Jedis對redis的五大類型操作代碼詳解
本篇主要闡述Jedis對redis的五大類型的操作:字符串、列表、散列、集合、有序集合。
JedisUtil
這里的測試用例采用junit4進(jìn)行運(yùn)行,準(zhǔn)備代碼如下:
private static final String ipAddr = "10.10.195.112";
private static final int port = 6379;
private static Jedis jedis= null;
@BeforeClass
public static void init()
{
jedis = JedisUtil.getInstance().getJedis(ipAddr, port);
}
@AfterClass
public static void close()
{
JedisUtil.getInstance().closeJedis(jedis,ipAddr, port);
}
其中JedisUtil是對jedis做的簡單封裝,代碼如下:
import org.apache.log4j.Logger;
import java.util.HashMap;
import java.util.Map;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
public class JedisUtil
{
private Logger logger = Logger.getLogger(this.getClass().getName());
private JedisUtil(){
}
private static class RedisUtilHolder{
private static final JedisUtil instance = new JedisUtil();
}
public static JedisUtil getInstance(){
return RedisUtilHolder.instance;
}
private static Map<String,JedisPool> maps = new HashMap<String,JedisPool>();
private static JedisPool getPool(String ip, int port){
String key = ip+":"+port;
JedisPool pool = null;
if(!maps.containsKey(key))
{
JedisPoolConfig config = new JedisPoolConfig();
config.setMaxActive(RedisConfig.MAX_ACTIVE);
config.setMaxIdle(RedisConfig.MAX_IDLE);
config.setMaxWait(RedisConfig.MAX_WAIT);
config.setTestOnBorrow(true);
config.setTestOnReturn(true);
pool = new JedisPool(config,ip,port,RedisConfig.TIMEOUT);
maps.put(key, pool);
} else
{
pool = maps.get(key);
}
return pool;
}
public Jedis getJedis(String ip, int port)
{
Jedis jedis = null;
int count = 0;
do
{
try
{
jedis = getPool(ip,port).getResource();
}
catch (Exception e)
{
logger.error("get redis master1 failed!",e);
getPool(ip,port).returnBrokenResource(jedis);
}
}
while(jedis == null && count<RedisConfig.RETRY_NUM);
return jedis;
}
public void closeJedis(Jedis jedis, String ip, int port){
if(jedis != null)
{
getPool(ip,port).returnResource(jedis);
}
}
}
public class RedisConfig
{
//可用連接實(shí)例的最大數(shù)目,默認(rèn)值為8;
//如果賦值為-1,則表示不限制;如果pool已經(jīng)分配了maxActive個jedis實(shí)例,則此時pool的狀態(tài)為exhausted(耗盡)。
public static int MAX_ACTIVE = 1024;
//控制一個pool最多有多少個狀態(tài)為idle(空閑的)的jedis實(shí)例,默認(rèn)值也是8。
public static int MAX_IDLE = 200;
//等待可用連接的最大時間,單位毫秒,默認(rèn)值為-1,表示永不超時。如果超過等待時間,則直接拋出JedisConnectionException;
public static int MAX_WAIT = 10000;
public static int TIMEOUT = 10000;
public static int RETRY_NUM = 5;
}
鍵操作
@Test public void testKey() throws InterruptedException
{
System.out.println("清空數(shù)據(jù):"+jedis.flushDB());
System.out.println("判斷某個鍵是否存在:"+jedis.exists("username"));
System.out.println("新增<'username','zzh'>的鍵值對:"+jedis.set("username", "zzh"));
System.out.println(jedis.exists("name"));
System.out.println("新增<'password','password'>的鍵值對:"+jedis.set("password", "password"));
System.out.print("系統(tǒng)中所有的鍵如下:");
Set<String> keys = jedis.keys("*");
System.out.println(keys);
System.out.println("刪除鍵password:"+jedis.del("password"));
System.out.println("判斷鍵password是否存在:"+jedis.exists("password"));
System.out.println("設(shè)置鍵username的過期時間為5s:"+jedis.expire("username", 5));
TimeUnit.SECONDS.sleep(2);
System.out.println("查看鍵username的剩余生存時間:"+jedis.ttl("username"));
System.out.println("移除鍵username的生存時間:"+jedis.persist("username"));
System.out.println("查看鍵username的剩余生存時間:"+jedis.ttl("username"));
System.out.println("查看鍵username所存儲的值的類型:"+jedis.type("username"));
}
輸出結(jié)果:
清空數(shù)據(jù):OK 判斷某個鍵是否存在:false 新增<'username','zzh'>的鍵值對:OK false 新增<'password','password'>的鍵值對:OK 系統(tǒng)中所有的鍵如下:[username, password] 刪除鍵password:1 判斷鍵password是否存在:false 設(shè)置鍵username的過期時間為5s:1 查看鍵username的剩余生存時間:3 移除鍵username的生存時間:1 查看鍵username的剩余生存時間:-1 查看鍵username所存儲的值的類型:string
字符串操作
在Redis里面,字符串可以存儲三種類型的值:
字節(jié)串(byte string)
整數(shù)
浮點(diǎn)數(shù)
字節(jié)串
@Test public void testString() throws InterruptedException
{
jedis.flushDB();
System.out.println("===========增加數(shù)據(jù)===========");
System.out.println(jedis.set("key1","value1"));
System.out.println(jedis.set("key2","value2"));
System.out.println(jedis.set("key3", "value3"));
System.out.println("刪除鍵key2:"+jedis.del("key2"));
System.out.println("獲取鍵key2:"+jedis.get("key2"));
System.out.println("修改key1:"+jedis.set("key1", "value1Changed"));
System.out.println("獲取key1的值:"+jedis.get("key1"));
System.out.println("在key3后面加入值:"+jedis.append("key3", "End"));
System.out.println("key3的值:"+jedis.get("key3"));
System.out.println("增加多個鍵值對:"+jedis.mset("key01","value01","key02","value02","key03","value03"));
System.out.println("獲取多個鍵值對:"+jedis.mget("key01","key02","key03"));
System.out.println("獲取多個鍵值對:"+jedis.mget("key01","key02","key03","key04"));
System.out.println("刪除多個鍵值對:"+jedis.del(new String[]{
"key01","key02"
}
));
System.out.println("獲取多個鍵值對:"+jedis.mget("key01","key02","key03"));
jedis.flushDB();
System.out.println("===========新增鍵值對防止覆蓋原先值==============");
System.out.println(jedis.setnx("key1", "value1"));
System.out.println(jedis.setnx("key2", "value2"));
System.out.println(jedis.setnx("key2", "value2-new"));
System.out.println(jedis.get("key1"));
System.out.println(jedis.get("key2"));
System.out.println("===========新增鍵值對并設(shè)置有效時間=============");
System.out.println(jedis.setex("key3", 2, "value3"));
System.out.println(jedis.get("key3"));
TimeUnit.SECONDS.sleep(3);
System.out.println(jedis.get("key3"));
System.out.println("===========獲取原值,更新為新值==========");
//GETSET is an atomic set this value and return the old value command.
System.out.println(jedis.getSet("key2", "key2GetSet"));
System.out.println(jedis.get("key2"));
System.out.println("獲得key2的值的字串:"+jedis.getrange("key2", 2, 4));
}
輸出結(jié)果:
===========增加數(shù)據(jù)=========== OK OK OK 刪除鍵key2:1 獲取鍵key2:null 修改key1:OK 獲取key1的值:value1Changed 在key3后面加入值:9 key3的值:value3End 增加多個鍵值對:OK 獲取多個鍵值對:[value01, value02, value03] 獲取多個鍵值對:[value01, value02, value03, null] 刪除多個鍵值對:2 獲取多個鍵值對:[null, null, value03] ===========新增鍵值對防止覆蓋原先值============== 1 1 0 value1 value2 ===========新增鍵值對并設(shè)置有效時間============= OK value3 null ===========獲取原值,更新為新值========== value2 key2GetSet 獲得key2的值的字串:y2G
memcached和redis同樣有append的操作,但是memcached有prepend的操作,redis中并沒有。
整數(shù)和浮點(diǎn)數(shù)
@Test public void testNumber()
{
jedis.flushDB();
jedis.set("key1", "1");
jedis.set("key2", "2");
jedis.set("key3", "2.3");
System.out.println("key1的值:"+jedis.get("key1"));
System.out.println("key2的值:"+jedis.get("key2"));
System.out.println("key1的值加1:"+jedis.incr("key1"));
System.out.println("獲取key1的值:"+jedis.get("key1"));
System.out.println("key2的值減1:"+jedis.decr("key2"));
System.out.println("獲取key2的值:"+jedis.get("key2"));
System.out.println("將key1的值加上整數(shù)5:"+jedis.incrBy("key1", 5));
System.out.println("獲取key1的值:"+jedis.get("key1"));
System.out.println("將key2的值減去整數(shù)5:"+jedis.decrBy("key2", 5));
System.out.println("獲取key2的值:"+jedis.get("key2"));
}
輸出結(jié)果:
key1的值:1 key2的值:2 key1的值加1:2 獲取key1的值:2 key2的值減1:1 獲取key2的值:1 將key1的值加上整數(shù)5:7 獲取key1的值:7 將key2的值減去整數(shù)5:-4 獲取key2的值:-4
在redis2.6或以上版本中有這個命令:incrbyfloat,即將鍵存儲的值加上浮點(diǎn)數(shù)amount,jedis-2.1.0中不支持這一操作。
列表
@Test public void testList()
{
jedis.flushDB();
System.out.println("===========添加一個list===========");
jedis.lpush("collections", "ArrayList", "Vector", "Stack", "HashMap", "WeakHashMap", "LinkedHashMap");
jedis.lpush("collections", "HashSet");
jedis.lpush("collections", "TreeSet");
jedis.lpush("collections", "TreeMap");
System.out.println("collections的內(nèi)容:"+jedis.lrange("collections", 0, -1));//-1代表倒數(shù)第一個元素,-2代表倒數(shù)第二個元素
System.out.println("collections區(qū)間0-3的元素:"+jedis.lrange("collections",0,3));
System.out.println("===============================");
// 刪除列表指定的值 ,第二個參數(shù)為刪除的個數(shù)(有重復(fù)時),后add進(jìn)去的值先被刪,類似于出棧
System.out.println("刪除指定元素個數(shù):"+jedis.lrem("collections", 2, "HashMap"));
System.out.println("collections的內(nèi)容:"+jedis.lrange("collections", 0, -1));
System.out.println("刪除下表0-3區(qū)間之外的元素:"+jedis.ltrim("collections", 0, 3));
System.out.println("collections的內(nèi)容:"+jedis.lrange("collections", 0, -1));
System.out.println("collections列表出棧(左端):"+jedis.lpop("collections"));
System.out.println("collections的內(nèi)容:"+jedis.lrange("collections", 0, -1));
System.out.println("collections添加元素,從列表右端,與lpush相對應(yīng):"+jedis.rpush("collections", "EnumMap"));
System.out.println("collections的內(nèi)容:"+jedis.lrange("collections", 0, -1));
System.out.println("collections列表出棧(右端):"+jedis.rpop("collections"));
System.out.println("collections的內(nèi)容:"+jedis.lrange("collections", 0, -1));
System.out.println("修改collections指定下標(biāo)1的內(nèi)容:"+jedis.lset("collections", 1, "LinkedArrayList"));
System.out.println("collections的內(nèi)容:"+jedis.lrange("collections", 0, -1));
System.out.println("===============================");
System.out.println("collections的長度:"+jedis.llen("collections"));
System.out.println("獲取collections下標(biāo)為2的元素:"+jedis.lindex("collections", 2));
System.out.println("===============================");
jedis.lpush("sortedList", "3","6","2","0","7","4");
System.out.println("sortedList排序前:"+jedis.lrange("sortedList", 0, -1));
System.out.println(jedis.sort("sortedList"));
System.out.println("sortedList排序后:"+jedis.lrange("sortedList", 0, -1));
}
輸出結(jié)果:
===========添加一個list=========== collections的內(nèi)容:[TreeMap, TreeSet, HashSet, LinkedHashMap, WeakHashMap, HashMap, Stack, Vector, ArrayList] collections區(qū)間0-3的元素:[TreeMap, TreeSet, HashSet, LinkedHashMap] =============================== 刪除指定元素個數(shù):1 collections的內(nèi)容:[TreeMap, TreeSet, HashSet, LinkedHashMap, WeakHashMap, Stack, Vector, ArrayList] 刪除下表0-3區(qū)間之外的元素:OK collections的內(nèi)容:[TreeMap, TreeSet, HashSet, LinkedHashMap] collections列表出棧(左端):TreeMap collections的內(nèi)容:[TreeSet, HashSet, LinkedHashMap] collections添加元素,從列表右端,與lpush相對應(yīng):4 collections的內(nèi)容:[TreeSet, HashSet, LinkedHashMap, EnumMap] collections列表出棧(右端):EnumMap collections的內(nèi)容:[TreeSet, HashSet, LinkedHashMap] 修改collections指定下標(biāo)1的內(nèi)容:OK collections的內(nèi)容:[TreeSet, LinkedArrayList, LinkedHashMap] =============================== collections的長度:3 獲取collections下標(biāo)為2的元素:LinkedHashMap =============================== sortedList排序前:[4, 7, 0, 2, 6, 3] [0, 2, 3, 4, 6, 7] sortedList排序后:[4, 7, 0, 2, 6, 3]
Redis中還有阻塞式的列表彈出命令以及在列表之間移動元素的命令:blpop, brpop, rpoplpush, brpoplpush等。
集合(Set)
@Test public void testSet()
{
jedis.flushDB();
System.out.println("============向集合中添加元素============");
System.out.println(jedis.sadd("eleSet", "e1","e2","e4","e3","e0","e8","e7","e5"));
System.out.println(jedis.sadd("eleSet", "e6"));
System.out.println(jedis.sadd("eleSet", "e6"));
System.out.println("eleSet的所有元素為:"+jedis.smembers("eleSet"));
System.out.println("刪除一個元素e0:"+jedis.srem("eleSet", "e0"));
System.out.println("eleSet的所有元素為:"+jedis.smembers("eleSet"));
System.out.println("刪除兩個元素e7和e6:"+jedis.srem("eleSet", "e7","e6"));
System.out.println("eleSet的所有元素為:"+jedis.smembers("eleSet"));
System.out.println("隨機(jī)的移除集合中的一個元素:"+jedis.spop("eleSet"));
System.out.println("隨機(jī)的移除集合中的一個元素:"+jedis.spop("eleSet"));
System.out.println("eleSet的所有元素為:"+jedis.smembers("eleSet"));
System.out.println("eleSet中包含元素的個數(shù):"+jedis.scard("eleSet"));
System.out.println("e3是否在eleSet中:"+jedis.sismember("eleSet", "e3"));
System.out.println("e1是否在eleSet中:"+jedis.sismember("eleSet", "e1"));
System.out.println("e1是否在eleSet中:"+jedis.sismember("eleSet", "e5"));
System.out.println("=================================");
System.out.println(jedis.sadd("eleSet1", "e1","e2","e4","e3","e0","e8","e7","e5"));
System.out.println(jedis.sadd("eleSet2", "e1","e2","e4","e3","e0","e8"));
System.out.println("將eleSet1中刪除e1并存入eleSet3中:"+jedis.smove("eleSet1", "eleSet3", "e1"));
System.out.println("將eleSet1中刪除e2并存入eleSet3中:"+jedis.smove("eleSet1", "eleSet3", "e2"));
System.out.println("eleSet1中的元素:"+jedis.smembers("eleSet1"));
System.out.println("eleSet3中的元素:"+jedis.smembers("eleSet3"));
System.out.println("============集合運(yùn)算=================");
System.out.println("eleSet1中的元素:"+jedis.smembers("eleSet1"));
System.out.println("eleSet2中的元素:"+jedis.smembers("eleSet2"));
System.out.println("eleSet1和eleSet2的交集:"+jedis.sinter("eleSet1","eleSet2"));
System.out.println("eleSet1和eleSet2的并集:"+jedis.sunion("eleSet1","eleSet2"));
System.out.println("eleSet1和eleSet2的差集:"+jedis.sdiff("eleSet1","eleSet2"));//eleSet1中有,eleSet2中沒有
}
輸出結(jié)果:
============向集合中添加元素============ 8 1 0 eleSet的所有元素為:[e3, e4, e1, e2, e0, e8, e7, e6, e5] 刪除一個元素e0:1 eleSet的所有元素為:[e3, e4, e1, e2, e8, e7, e6, e5] 刪除兩個元素e7和e6:2 eleSet的所有元素為:[e3, e4, e1, e2, e8, e5] 隨機(jī)的移除集合中的一個元素:e5 隨機(jī)的移除集合中的一個元素:e2 eleSet的所有元素為:[e3, e4, e1, e8] eleSet中包含元素的個數(shù):4 e3是否在eleSet中:true e1是否在eleSet中:true e1是否在eleSet中:false ================================= 8 6 將eleSet1中刪除e1并存入eleSet3中:1 將eleSet1中刪除e2并存入eleSet3中:1 eleSet1中的元素:[e3, e4, e0, e8, e7, e5] eleSet3中的元素:[e1, e2] ============集合運(yùn)算================= eleSet1中的元素:[e3, e4, e0, e8, e7, e5] eleSet2中的元素:[e3, e4, e1, e2, e0, e8] eleSet1和eleSet2的交集:[e3, e4, e0, e8] eleSet1和eleSet2的并集:[e3, e4, e1, e2, e0, e8, e7, e5] eleSet1和eleSet2的差集:[e7, e5]
關(guān)于Set還有一些其他命令:srandmember, sdiffstore, sinterstore, sunionstore等。
散列
@Test public void testHash()
{
jedis.flushDB();
Map<String,String> map = new HashMap<>();
map.put("key1","value1");
map.put("key2","value2");
map.put("key3","value3");
map.put("key4","value4");
jedis.hmset("hash",map);
jedis.hset("hash", "key5", "value5");
System.out.println("散列hash的所有鍵值對為:"+jedis.hgetAll("hash"));//return Map<String,String>
System.out.println("散列hash的所有鍵為:"+jedis.hkeys("hash"));//return Set<String>
System.out.println("散列hash的所有值為:"+jedis.hvals("hash"));//return List<String>
System.out.println("將key6保存的值加上一個整數(shù),如果key6不存在則添加key6:"+jedis.hincrBy("hash", "key6", 6));
System.out.println("散列hash的所有鍵值對為:"+jedis.hgetAll("hash"));
System.out.println("將key6保存的值加上一個整數(shù),如果key6不存在則添加key6:"+jedis.hincrBy("hash", "key6", 3));
System.out.println("散列hash的所有鍵值對為:"+jedis.hgetAll("hash"));
System.out.println("刪除一個或者多個鍵值對:"+jedis.hdel("hash", "key2"));
System.out.println("散列hash的所有鍵值對為:"+jedis.hgetAll("hash"));
System.out.println("散列hash中鍵值對的個數(shù):"+jedis.hlen("hash"));
System.out.println("判斷hash中是否存在key2:"+jedis.hexists("hash","key2"));
System.out.println("判斷hash中是否存在key3:"+jedis.hexists("hash","key3"));
System.out.println("獲取hash中的值:"+jedis.hmget("hash","key3"));
System.out.println("獲取hash中的值:"+jedis.hmget("hash","key3","key4"));
}
輸出結(jié)果:
散列hash的所有鍵值對為:{key4=value4, key3=value3, key5=value5, key2=value2, key1=value1}
散列hash的所有鍵為:[key4, key3, key5, key2, key1]
散列hash的所有值為:[value4, value3, value1, value2, value5]
將key6保存的值加上一個整數(shù),如果key6不存在則添加key6:6
散列hash的所有鍵值對為:{key4=value4, key3=value3, key6=6, key5=value5, key2=value2, key1=value1}
將key6保存的值加上一個整數(shù),如果key6不存在則添加key6:9
散列hash的所有鍵值對為:{key4=value4, key3=value3, key6=9, key5=value5, key2=value2, key1=value1}
刪除一個或者多個鍵值對:1
散列hash的所有鍵值對為:{key4=value4, key3=value3, key6=9, key5=value5, key1=value1}
散列hash中鍵值對的個數(shù):5
判斷hash中是否存在key2:false
判斷hash中是否存在key3:true
獲取hash中的值:[value3]
獲取hash中的值:[value3, value4]
有序集合
@Test public void testSortedSet()
{
jedis.flushDB();
Map<Double,String> map = new HashMap<>();
map.put(1.2,"key2");
map.put(4.0, "key3");
map.put(5.0,"key4");
map.put(0.2,"key5");
System.out.println(jedis.zadd("zset", 3,"key1"));
System.out.println(jedis.zadd("zset",map));
System.out.println("zset中的所有元素:"+jedis.zrange("zset", 0, -1));
System.out.println("zset中的所有元素:"+jedis.zrangeWithScores("zset", 0, -1));
System.out.println("zset中的所有元素:"+jedis.zrangeByScore("zset", 0,100));
System.out.println("zset中的所有元素:"+jedis.zrangeByScoreWithScores("zset", 0,100));
System.out.println("zset中key2的分值:"+jedis.zscore("zset", "key2"));
System.out.println("zset中key2的排名:"+jedis.zrank("zset", "key2"));
System.out.println("刪除zset中的元素key3:"+jedis.zrem("zset", "key3"));
System.out.println("zset中的所有元素:"+jedis.zrange("zset", 0, -1));
System.out.println("zset中元素的個數(shù):"+jedis.zcard("zset"));
System.out.println("zset中分值在1-4之間的元素的個數(shù):"+jedis.zcount("zset", 1, 4));
System.out.println("key2的分值加上5:"+jedis.zincrby("zset", 5, "key2"));
System.out.println("key3的分值加上4:"+jedis.zincrby("zset", 4, "key3"));
System.out.println("zset中的所有元素:"+jedis.zrange("zset", 0, -1));
}
輸出結(jié)果:
1 4 zset中的所有元素:[key5, key2, key1, key3, key4] zset中的所有元素:[[[107, 101, 121, 53],0.2], [[107, 101, 121, 50],1.2], [[107, 101, 121, 49],3.0], [[107, 101, 121, 51],4.0], [[107, 101, 121, 52],5.0]] zset中的所有元素:[key5, key2, key1, key3, key4] zset中的所有元素:[[[107, 101, 121, 53],0.2], [[107, 101, 121, 50],1.2], [[107, 101, 121, 49],3.0], [[107, 101, 121, 51],4.0], [[107, 101, 121, 52],5.0]] zset中key2的分值:1.2 zset中key2的排名:1 刪除zset中的元素key3:1 zset中的所有元素:[key5, key2, key1, key4] zset中元素的個數(shù):4 zset中分值在1-4之間的元素的個數(shù):2 key2的分值加上5:6.2 key3的分值加上4:4.0 zset中的所有元素:[key5, key1, key3, key4, key2]
有序集合還有諸如zinterstore, zunionstore, zremrangebyscore, zremrangebyrank, zrevrank, zrevrange, zrangebyscore等命令。
排序sort
@Test public void testSort()
{
jedis.flushDB();
jedis.lpush("collections", "ArrayList", "Vector", "Stack", "HashMap", "WeakHashMap", "LinkedHashMap");
System.out.println("collections的內(nèi)容:"+jedis.lrange("collections", 0, -1));
SortingParams sortingParameters = new SortingParams();
System.out.println(jedis.sort("collections",sortingParameters.alpha()));
System.out.println("===============================");
jedis.lpush("sortedList", "3","6","2","0","7","4");
System.out.println("sortedList排序前:"+jedis.lrange("sortedList", 0, -1));
System.out.println("升序:"+jedis.sort("sortedList", sortingParameters.asc()));
System.out.println("升序:"+jedis.sort("sortedList", sortingParameters.desc()));
System.out.println("===============================");
jedis.lpush("userlist", "33");
jedis.lpush("userlist", "22");
jedis.lpush("userlist", "55");
jedis.lpush("userlist", "11");
jedis.hset("user:66", "name", "66");
jedis.hset("user:55", "name", "55");
jedis.hset("user:33", "name", "33");
jedis.hset("user:22", "name", "79");
jedis.hset("user:11", "name", "24");
jedis.hset("user:11", "add", "beijing");
jedis.hset("user:22", "add", "shanghai");
jedis.hset("user:33", "add", "guangzhou");
jedis.hset("user:55", "add", "chongqing");
jedis.hset("user:66", "add", "xi'an");
sortingParameters = new SortingParams();
sortingParameters.get("user:*->name");
sortingParameters.get("user:*->add");
System.out.println(jedis.sort("userlist",sortingParameters));
}
輸出結(jié)果:
collections的內(nèi)容:[LinkedHashMap, WeakHashMap, HashMap, Stack, Vector, ArrayList] [ArrayList, HashMap, LinkedHashMap, Stack, Vector, WeakHashMap] =============================== sortedList排序前:[4, 7, 0, 2, 6, 3] 升序:[0, 2, 3, 4, 6, 7] 升序:[7, 6, 4, 3, 2, 0] =============================== [24, beijing, 79, shanghai, 33, guangzhou, 55, chongqing]
總結(jié)
以上就是本文關(guān)于Jedis對redis的五大操作代碼詳解的全部內(nèi)容,希望對大家有所幫助。感興趣的朋友可以繼續(xù)參閱本站:
redis實(shí)現(xiàn)計(jì)數(shù)器-防止刷單方法介紹
Java編程redisson實(shí)現(xiàn)分布式鎖代碼示例
如有不足之處,歡迎留言指出。
相關(guān)文章
Java實(shí)現(xiàn)合并word文檔的示例代碼
在做項(xiàng)目中,經(jīng)常會遇到一種情況,需要將一個小word文檔的內(nèi)容插入到一個大word(主文檔)中。本文就為大家準(zhǔn)備了Java實(shí)現(xiàn)合并word文檔的方法,需要的可以參考一下2022-08-08
Java中Stringbuild,Date和Calendar類的用法詳解
這篇文章主要為大家詳細(xì)介紹了Java中Stringbuild、Date和Calendar類的用法,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起了解一下2023-04-04
java實(shí)現(xiàn)/創(chuàng)建線程的幾種方式小結(jié)
在JAVA中,用Thread類代表線程,所有線程對象都必須是Thread類或者Thread類子類的實(shí)例,下面這篇文章主要介紹了java實(shí)現(xiàn)/創(chuàng)建線程的幾種方式,需要的朋友可以參考下2021-08-08
Junit單元測試關(guān)于@Transactional注解引起的事務(wù)回滾問題
這篇文章主要介紹了Junit單元測試關(guān)于@Transactional注解引起的事務(wù)回滾問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-08-08
Spring事件監(jiān)聽器@EventListener與publishEvent的使用
Spring可以通過事件監(jiān)聽器機(jī)制來處理應(yīng)用程序中的事件,本文主要介紹了Spring事件監(jiān)聽器@EventListener與publishEvent的使用,具有一定的參考價值,感興趣的可以了解一下2024-06-06
swagger文檔增強(qiáng)工具knife4j使用圖文詳解
這篇文章主要介紹了swagger文檔增強(qiáng)工具knife4j使用詳解,想要使用knife4j非常簡單,只要在Springboot項(xiàng)目中引入knife4j的依賴即可,本文通過圖文并茂的形式給大家介紹的非常詳細(xì),需要的朋友可以參考下2022-08-08
Java代理模式(Proxy)實(shí)現(xiàn)方法詳解
這篇文章主要介紹了Java代理模式(Proxy)實(shí)現(xiàn)的相關(guān)資料,代理模式是一種結(jié)構(gòu)型設(shè)計(jì)模式,通過引入代理對象來控制對目標(biāo)對象的訪問,代理模式的優(yōu)點(diǎn)包括職責(zé)清晰、擴(kuò)展性好、保護(hù)目標(biāo)對象和增強(qiáng)功能,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下2025-04-04

