Redis管道获取数据
来源:互联网 发布:桌面收纳 知乎 编辑:程序博客网 时间:2024/06/05 04:30
/**获取Jedis * @return */ public Jedis getJedis(){ Properties pros = getPprVue(); String isopen = pros.getProperty("redis.isopen");// String host = pros.getProperty("redis.host");//地址 String port = pros.getProperty("redis.port");//端口 String pass = pros.getProperty("redis.pass");//密码 if("yes".equals(isopen)){ Jedis jedis = new Jedis(host,Integer.parseInt(port));// jedis.auth(pass); return jedis; }else{ return null; } } /**读取redis.properties 配置文件 * @return * @throws IOException */ public Properties getPprVue(){ InputStream inputStream = DbFH.class.getClassLoader().getResourceAsStream("redis.properties"); Properties p = new Properties(); try { p.load(inputStream); inputStream.close(); } catch (IOException e) { //读取配置文件出错 e.printStackTrace(); } return p; }
redis.properties# Redis 参数配置redis.isopen:yesredis.host:11.31.142.115redis.port:6379redis.pass:wredis.maxIdle:300redis.maxActive:600redis.maxWait:1000redis.testOnBorrow:true
/** * 获取reids里所有的数据 * @param prefix * @return */ public Map<String,Object> getRedisData(String prefix)throws Exception{// prefix="WxCmd"; Map<String,Object> map=new HashMap<String, Object>(); Jedis redis=redisDaoImpl.getJedis(); // 获取所有key String keyword="WxCmd:"; if(null!=prefix && prefix!=""){ keyword+="*"+prefix; } Set s = redis.keys(keyword+"*"); Iterator it = s.iterator(); while (it.hasNext()) { String key = (String) it.next(); //获取redis存储的类型 String type = redis.type(key); Object value=new Object(); if(type.equals("hash")){ value=redis.hvals(key); }else if(type.equals("string")){ value=redis.get(key); }else{ ... } map.put(key,value); } return map; } /** * 获取reids里所有的数据 * @param prefix * @return */ public Map<String,Map<String,String>> getRedisDataByKey(String prefix)throws Exception{ Map<String,Map<String,String>> result = new HashMap<String,Map<String,String>>(); Jedis redis=redisDaoImpl.getJedis(); Set<String> keys = redis.keys(prefix+"*"); if(null!=keys && keys.size()>0){ //获取管道 Pipeline pipeline = redis.pipelined(); Map<String,Response<Map<String,String>>> responses = new HashMap<String,Response<Map<String,String>>>(keys.size()); Long start = System.currentTimeMillis(); for(String key : keys) { responses.put(key, pipeline.hgetAll(key)); } pipeline.sync(); for(String k : responses.keySet()) { result.put(k, responses.get(k).get()); } Long end = System.currentTimeMillis(); System.err.println("result size:[" + result.size() + "] .."); System.err.println("hgetAll with pipeline used [" + (end - start) / 1000 + "] seconds .."); } return result; } /** * 根据key获取所有的数据 * @param * @return */ public Map<String,Map<String,String>> getRedisDataByListKey(List<String> keyList)throws Exception{ Map<String,Map<String,String>> result = new HashMap<String,Map<String,String>>(); List<String> keys=keyList; Jedis redis=redisDaoImpl.getJedis(); if(null!=keys && keys.size()>0){ //获取管道 Pipeline pipeline = redis.pipelined(); Map<String,Response<Map<String,String>>> responses = new HashMap<String,Response<Map<String,String>>>(keys.size()); for(String key : keys) { responses.put(key, pipeline.hgetAll(key)); } pipeline.sync(); for(String k : responses.keySet()) { result.put(k, responses.get(k).get()); } } return result; }
阅读全文
0 0
- Redis管道获取数据
- Redis做数据延期处理管道修改
- redis-管道
- Redis管道
- redis-管道
- Redis管道
- StackExchange.Redis 管道 批量 高性能插入数据
- 数据管道
- Redis基础之管道
- redis-cli pipe 管道
- Redis 管道pipeline
- Redis管道(Pipelining)操作
- redis翻译_redis管道
- Redis管道(Pipelining)操作
- 012redis管道(pipeline)
- Redis 管道技术
- Redis 管道技术
- Redis 管道技术
- AQS解析
- 财务系统拆分思路整理+计划-备份
- 动态属性标签
- 大数据统计租房市场现状(深圳篇)
- HLS(HTTP Live Streaming)
- Redis管道获取数据
- 理解io流产生和整体流程
- 裸机_GPIO实验_汇编
- 高级面向对象之 面向对象中常用的属性和方法
- 目标类选择器":traget"应用场景
- 深入pack
- 机器学习基于K-近邻算法(KNN)
- C语言 — 整形提升
- 九度oj-1031-xxx定律