redis maven 搭建
来源:互联网 发布:淘宝图片引是什么意思 编辑:程序博客网 时间:2024/06/07 08:12
redis.properties
#config for redisredis.pool.maxActive=512redis.pool.maxIdle=100redis.pool.maxWait=100000redis.pool.testOnBorrow=trueredis.pool.testOnReturn=trueredis.ip=127.0.0.1redis.port=6379redis.expire=1200
pom.xml 依赖包
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 --> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> <version>3.4</version> </dependency> <!-- redis.properties --> <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>2.1.0</version> </dependency>
RedisUtils
package com.saudio.common.redis;import redis.clients.jedis.Jedis;import redis.clients.jedis.JedisPool;import redis.clients.jedis.JedisPoolConfig;import redis.clients.jedis.exceptions.JedisConnectionException;import java.util.Locale;import java.util.ResourceBundle;/** * Created by hongwei on 2016/9/25. */public class RedisUtils { protected static JedisPool jedispool; protected static int EXPIRE = 130; static{ Locale locale1 = new Locale("zh", "CN"); ResourceBundle bundle = ResourceBundle.getBundle("redis",locale1); if (bundle == null) { throw new IllegalArgumentException( "[redis.properties] is not found!"); } EXPIRE = Integer.valueOf(bundle.getString("redis.expire")); JedisPoolConfig jedisconfig = new JedisPoolConfig(); jedisconfig.setMaxActive(Integer.valueOf(bundle .getString("redis.pool.maxActive"))); jedisconfig.setMaxIdle(Integer.valueOf(bundle .getString("redis.pool.maxIdle"))); jedisconfig.setMaxWait(Long.valueOf(bundle .getString("redis.pool.maxWait"))); jedisconfig.setTestOnBorrow(Boolean.valueOf(bundle .getString("redis.pool.testOnBorrow"))); jedisconfig.setTestOnReturn(Boolean.valueOf(bundle .getString("redis.pool.testOnReturn"))); jedispool = new JedisPool(jedisconfig, bundle.getString("redis.ip"), Integer.valueOf(bundle.getString("redis.port")), 100000); } public static Jedis getJedis() { Jedis jedis = null; try { jedis = jedispool.getResource(); } catch (JedisConnectionException jce) { jce.getStackTrace(); try { Thread.sleep(3000); } catch (InterruptedException e) { jce.getStackTrace(); } jedis = jedispool.getResource(); } return jedis; } public static void returnResource(JedisPool pool, Jedis jedis) { if (jedis != null) { pool.returnResource(jedis); } } public static void setKey(String key , String value , int seconds){ Jedis jedis = getJedis(); jedis.set(key,value); jedis.expire(key,seconds); } public String getKey(String key){ return getJedis().get(key); }}
0 0
- redis maven 搭建
- redis+spring+maven平台搭建
- Maven+springMVC+mybatis+redis 项目搭建
- springmvc+mybatis+redis的maven项目搭建
- jfinal+redis+maven搭建web项目
- IDEA使用maven搭建java项目连接redis(图文)
- 五、maven项目搭建 ssm框架之spring整合redis
- idea15搭建简单maven项目测试连接redis
- Redis搭建
- redis搭建
- redis搭建
- redis搭建
- redis搭建
- 搭建redis
- Maven 搭建
- maven搭建
- maven搭建
- maven搭建
- erlang fsm 学习及用例
- logback logback.xml常用配置详解
- 10个很棒的学习Android 开发的网站
- SpringMVC + security模块 框架整合详解
- 没有思想的文章
- redis maven 搭建
- java 创建文件-创建目录-创建临时文件
- 普通深度优先搜索(方法总数)模板简介
- Kafka源码阅读 —— KafkaController(2)
- Chapter 1 Object Oriented Programming (OOP)
- 标准体重测量器
- 安徽大学线性代数第二章习题册(详细解答)
- 【JAVA】上机实验三作业
- SmartUpload基础