jedis 简单使用
编程技术  /  houtizong 发布于 3年前   117
jedis.RedisOperationCollection.java
package jedis;import org.apache.log4j.Logger;import redis.clients.jedis.Jedis;import java.util.List;import java.util.Map;import java.util.Set;public class RedisOperationCollection { private static Logger logger = Logger.getLogger(RedisOperationCollection.class); private static Jedis jedis = new Jedis("127.0.0.1"); private static void showCommonOperations(){ Set<String> keys = jedis.keys("*");// select all the keys logger.info("all keys in this db are : "+keys); boolean keyExisted = jedis.exists("key");// check whether the specified key is existed logger.info("key existed : "+keyExisted); String keyType = jedis.type("list");// check key type logger.info("key type : "+keyType); } private static void showListOperations(){ jedis.del("list"); jedis.lpush("list","abc"); jedis.rpush("list", "hij"); List<String> list = jedis.lrange("list",0,-1); logger.info("list information is : "+list); } private static void showHashOperations(){ jedis.hset("hash","name","姓名"); Map<String, String> hash = jedis.hgetAll("hash"); logger.info("the hash information is "+hash); } private static void showSetOperations(){ jedis.sadd("set","a","b","c"); jedis.spop("set"); jedis.srem("set","b"); Set<String> set = jedis.smembers("set"); logger.info("the set information is "+set); } private static void showSortedSetOperations(){ jedis.zadd("zset",0,"java"); jedis.zadd("zset",1,"C"); jedis.zadd("zset",2,"C++"); jedis.zadd("zset",3,"C#"); Set<String> zset = jedis.zrange("zset", 0, -1); logger.info("the zset information is "+zset); } public static void main(String[] args) { showCommonOperations(); showListOperations(); showHashOperations(); showSetOperations(); showSortedSetOperations(); }}
pom.xml
<dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>2.4.2</version> </dependency>
请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!
技术博客集 - 网站简介:
前后端技术:
后端基于Hyperf2.1框架开发,前端使用Bootstrap可视化布局系统生成
网站主要作用:
1.编程技术分享及讨论交流,内置聊天系统;
2.测试交流框架问题,比如:Hyperf、Laravel、TP、beego;
3.本站数据是基于大数据采集等爬虫技术为基础助力分享知识,如有侵权请发邮件到站长邮箱,站长会尽快处理;
4.站长邮箱:[email protected];
文章归档
文章标签
友情链接