1,关于春天配置文件中对于复述的配置
& lt; !——复述,配置——比; & lt; bean id=癹edisPoolConfig”类=皉edis.clients.jedis.JedisPoolConfig”比; & lt; !——& lt;属性名=" maxActive " value=" https://www.yisu.com/zixun/90 "/比;——比; & lt;属性名=" maxIdle " value=" https://www.yisu.com/zixun/5 "/比; & lt; !——& lt;属性名=" maxWait " value=" https://www.yisu.com/zixun/1000 "/比;——比; & lt;属性名=" testOnBorrow " value=" https://www.yisu.com/zixun/true "/比; & lt;/bean> & lt; !——配置复述,数据源——比; & lt; bean id=癹edisPool”类=" redis.clients.jedis。JedisPool摧毁“销毁方法=比; & lt; constructor-arg ref=" jedisPoolConfig "/比; & lt; constructor-arg值=" https://www.yisu.com/zixun/192.168.21.195 "/比; & lt; constructor-arg值=" https://www.yisu.com/zixun/6379 "/比; & lt;/bean> & lt; !——配置自定义的RedisAPI工具类——比; & lt; bean id=皉edisAPI”类=皁rg.slsale.common.RedisAPI”比; & lt;属性名=" jedisPool " ref=" jedisPool "/比; & lt;/bean>
2,配置自定义的RedisAPI,对复述,数据库的管理
包org.slsale.common; 进口redis.clients.jedis.Jedis; 进口redis.clients.jedis.JedisPool;/* * * jedisAPI * @author luzhewu * */公开课RedisAPI { 公共JedisPool JedisPool;//复述,连接池对象 公共JedisPool getJedisPool () { 返回jedisPool; } 公共空间setJedisPool (JedisPool JedisPool) { 这一点。jedisPool=jedisPool; }/* * *设置键和值tp复述 * @param关键 * @param价值 * @return */公共布尔组(字符串,字符串值){ 能能=零; 尝试{ 能=jedisPool.getResource();//获取能对象 能。集(关键字,值); 返回true; }捕捉(异常e) { e.printStackTrace (); 最后}{//返还到连接池 returnResource (jedisPool能); } 返回错误; }/* * *判断某个关键是否存在 * @param关键 * @return */公共逻辑存在(String键){ 能能=零; 尝试{ 能=jedisPool.getResource (); 返回jedis.exists(关键); }捕捉(异常e) { e.printStackTrace (); 最后}{//返还到连接池 returnResource (jedisPool能); } 返回错误; }/* * *通过关键获取价值 * @param关键 * @return */公共字符串(字符串键){ 字符串值=https://www.yisu.com/zixun/null; 能能=零; 尝试{ 能=jedisPool.getResource (); 值=jedis.get(关键); }捕捉(异常e) { e.printStackTrace (); 最后}{//返还到连接池 returnResource (jedisPool能); } 返回值; }/* * *返还到连接池 * @param jedisPool * @param能 */公共静态孔隙returnResource (JedisPool JedisPool,能能){ 如果(能!=null) { jedisPool.returnResource(能); } } }
3,复述,相关依赖
& lt; !——复述,相关依赖能——比; & lt; dependency> & lt; groupId> redis.clients & lt; artifactId> jedis & lt; version> 2.6.1 >之前,以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
舰导弹开发使用复述,作为缓存的使用步骤