博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Redis Java API
阅读量:4329 次
发布时间:2019-06-06

本文共 2592 字,大约阅读时间需要 8 分钟。

package cn.ac.iscas.pebble.dc.redispool;import java.io.File;import java.io.FileOutputStream;import java.util.Date;import java.util.HashMap;import java.util.List;import java.util.Set;import redis.clients.jedis.Jedis;import redis.clients.jedis.JedisPool;import redis.clients.jedis.JedisPoolConfig;import redis.clients.jedis.Pipeline;import redis.clients.jedis.Response;import cn.ac.iscas.pebble.dc.hdfs.AppendToFile;import cn.ac.iscas.pebble.dc.test.P;public class RedisPoolProxy {        private HashMap
poolList = new HashMap
(); public static Date yes = null; private static RedisPoolProxy _proxy = null; public static RedisPoolProxy getInstance(){ if(null == _proxy){ _proxy = new RedisPoolProxy(); } return _proxy; } public JedisPool getPool(String ip,int port){ JedisPool pool = poolList.get(ip + ":" + port); if(null == pool){ JedisPoolConfig config = new JedisPoolConfig(); config.setMaxTotal(P.maxTotal);//最大连接数 config.setMaxIdle(P.maxIdle);//最大空闲连接数 config.setMaxWaitMillis(P.maxWaitMillis);//获取连接时的最大等待毫秒数 config.setTestOnBorrow(true);//在获取连接的时候检查有效性, 默认false pool = new JedisPool(config, ip, port,60*1000); poolList.put(ip + ":" + port, pool); } return pool; } public static Integer getDataFromRedis(String ip, int port, int db, String localfilepath,boolean delete){ JedisPool pool = RedisPoolProxy.getInstance().getPool(ip,port); int count = 0; boolean flag = true; if(null != pool){ Jedis redis = null; try { redis = pool.getResource(); Pipeline pipeline = redis.pipelined(); pipeline.select(db); Response
> response = pipeline.keys("*"); pipeline.sync(); Set
keys = response.get(); if(null != keys){ pipeline.get(key); pipeline.del(key); } List
result = pipeline.syncAndReturnAll(); for(Object value:result){ if(value instanceof String){ System.out.println((String)value+"\n"); count++; } } }catch (Exception e) { pool.returnBrokenResource(redis); e.printStackTrace(); flag=false; } finally { if (null != redis && null != pool ) { pool.returnResource(redis); } } } return count; }}

转载于:https://www.cnblogs.com/dorothychai/p/4568846.html

你可能感兴趣的文章
hdu1874畅通工程再续
查看>>
无线网络不受到攻击与窃听的几个小诀窍
查看>>
JDK中的Timer和TimerTask详解
查看>>
OC2-xml文件解析
查看>>
改变Eclipse 中代码字体大小
查看>>
第五章例题
查看>>
小议 HashMap
查看>>
Docker配置镜像源(windows)
查看>>
MyEclipse安装JS代码提示(Spket插件)
查看>>
QT_8_Qt中的事件处理_定时器事件_定时器类_事件分发器_事件过滤器_绘图事件_高级绘图事件_绘图设备_QFile 文件读写_QFileInfo文件信息...
查看>>
laravel 视图流程控制,if switch for loop
查看>>
Java自学资料——线程
查看>>
Microsoft Visual C++ Runtime Library Runtime Error解决的方式
查看>>
四、Linux/UNIX操作命令积累【chmod、chown、tail】
查看>>
盘点几种喜好“嘲讽”老罗的人
查看>>
Yii PHP Framework有用新手教程
查看>>
八皇后
查看>>
shell 命令总结
查看>>
【教程】EditPlus+MinGW搭建简易的C/C++开发环境
查看>>
数据库定时任务
查看>>