import redis.clients.jedis.Jedis; public class Test { public static void main(String[] args) { Jedis jedis = new Jedis("10.110.20.152",6379); String cacheKey = "test"; //Return the length of the list stored at the specified key. //If the key does not exist zero is returned . //If the value stored at key is not a list an error is returned. long length = jedis.llen(cacheKey); System.out.println(length);//输出0 //Add the string value to the head (LPUSH) or tail (RPUSH) //of the list stored at key. //If the key does not exist an empty list is created //just before the append operation. //If the key exists but is not a List an error is returned. jedis.rpush(cacheKey, "b");//从队尾插入 jedis.rpush(cacheKey, "c");//从队尾插入 jedis.lpush(cacheKey, "a");//从队首插入 System.out.println(jedis.llen(cacheKey));//输出3 //Atomically return and remove //the first (LPOP) or last (RPOP) element of the list. //For example if the list contains the elements "a","b","c" //LPOP will return "a" and the list will become "b","c". String value1 = jedis.lpop(cacheKey);//从队首弹出 System.out.println(jedis.llen(cacheKey));//输出2 String value2 = jedis.lpop(cacheKey);//从队首弹出 System.out.println(jedis.llen(cacheKey));//输出1 String value3 = jedis.lpop(cacheKey);//从队首弹出 System.out.println(jedis.llen(cacheKey));//输出0 System.out.println(value1+value2+value3);//输出abc System.out.println(jedis.lpop(cacheKey));//输出null jedis.close(); } }
Jedis Redis List 简单操作
猜你喜欢
转载自huangqiqing123.iteye.com/blog/2390948
今日推荐
周排行