首页天道酬勤redis连接池配置,redis图形化界面

redis连接池配置,redis图形化界面

张世龙 05-05 19:32 70次浏览

Redis工具类RedisPoolUntil

redis.properties

#redis服务器ipredis.ip=127.0.0.1#redis服务器端口号redis.port=6379#redis密码redis.passWord=# 与服务器建立连接的超时时间如果连接对象没有返回redis.timeout=3000 jedis最大空闲连接数pool.maxIdle=3#jedis池,则等待可用连接的最长时间。 以毫秒为单位,默认值为-1,表示不超时。 #如果超过等待时间,则直接抛出jedisconnectionexceptionpool.maxwaitmillis=3000

RedisPoolUntil.class

import lombok.extern.slf4j.slf4j; import Java.io.input streamreader; importorg.Apache.log4j.helpers.thread local map; import redis.clients.jedis.jedis; import redis.clients.jedis.Jedi spool; import redis.clients.jedis.jedis poolconfig; import java.io.IOException; import java.util.Properties;/* * @ authorwangyutian * @ versionv 1.0 * @ classnameredispoolutil * @描述性就绪工具类* @ date 2021/6/21 */@ slfolll privateredispoolutil((}/***配置文件(*@returnJava.util.properties ) @authoryutian*@time2021/6/22 ) /权限try { properties.load (newinputstreamreader (object.class.getresourceasstream (redis config file ) ) } catch (ioexcexcer }返回属性; } /** *初始化连接池* * @ author Yutian * @ time 2021/6/22 */privatestaticvoidinitpool ({ try }属性属性=getch int maxidle=integer.parseint (properties.getproperty (' pool.maxidle ' ); stringredisip=properties.getproperty (redis.IP ); intre disport=integer.parseint (properties.getproperty (' redis.port ' ); int time out=integer.parseint (properties.getproperty (' redis.time out ' ); jedispoolconfigconfig=newjedispoolconfig (; config.setmaxtotal(maxtotal; config.setmaxidle(maxidle; //连接断开时,是否阻止,false抛出异常,并阻止true直到超时。 默认值为true。 config.setblockwhenexhausted (true; Jedi spool=newjedispool (配置,redisIp,redisPort,timeOut ); log.info (“连接池初始化成功”}catch(exceptione ) { log.error )“连接池初始化失败”,e ); e .打印堆栈跟踪(; } } /** *获取连接* * @ author Yutian * @ time 2021/6/22 */publicstaticjedisgetjedis ((jedis=local.get ); if(Jedis==null ) if ) Jedispool==null ) { initPool ); } try { jedis=Jedi spool.get resource (; }catch(exceptione ) { e.printStackTrace ); }local.set(Jedis; }返回jedis; } /** *退回连接* * @ author Yutian * @ time 2021/6/22 */publicstaticvoidclose ({ jedis jedis=local.get ) }; try{if(Jedis!=null(Jedis.close ); log.info (“连接池已关闭”}catch(exceptione ) { log.error ) )“连接池关闭失败”,e ); } local.set (空); } /** *连接池* * @ author Yutian * @ time 2021/6/22 */publicstaticvoidclosepool () if(Jedispool!=null(Jedispool.close ); }/***Jedis对象资源* * @ author Yutian * @ time 2021/6/22 */publicstaticvoidreturnresource { jedis jedis } { jedis!=空(Jedi spool.return resource ) Jedis; }/***Jedis对象发生异常时,Jedis对象资源* * @ author Yutian * @ time 2021/6/22 */publicstaticvoidreturnbrokenresource (jedis对象资源} }

redis做oracle缓存,java读取redis数据