提交 7f488679 编写于 作者: 爱吃血肠's avatar 爱吃血肠

修改后台redis缓存报错问题

上级 95313b58
......@@ -21,110 +21,110 @@ import java.util.Set;
public class RedisCache {
public final static String CAHCENAME="cache";//缓存名
public final static int CAHCETIME=60;//默认缓存时间
@Autowired
private RedisTemplate<String, String> redisTemplate;
public <T> boolean putCache(String key, T obj) {
final byte[] bkey = key.getBytes();
final byte[] bvalue = ProtoStuffSerializerUtil.serialize(obj);
boolean result = redisTemplate.execute(new RedisCallback<Boolean>() {
@Override
public Boolean doInRedis(RedisConnection connection) throws DataAccessException {
return connection.setNX(bkey, bvalue);
}
});
return result;
}
public <T> void putCacheWithExpireTime(String key, T obj, final long expireTime) {
final byte[] bkey = key.getBytes();
final byte[] bvalue = ProtoStuffSerializerUtil.serialize(obj);
redisTemplate.execute(new RedisCallback<Boolean>() {
@Override
public Boolean doInRedis(RedisConnection connection) throws DataAccessException {
connection.setEx(bkey, expireTime, bvalue);
return true;
}
});
}
public <T> boolean putListCache(String key, List<T> objList) {
final byte[] bkey = key.getBytes();
final byte[] bvalue = ProtoStuffSerializerUtil.serializeList(objList);
boolean result = redisTemplate.execute(new RedisCallback<Boolean>() {
@Override
public Boolean doInRedis(RedisConnection connection) throws DataAccessException {
return connection.setNX(bkey, bvalue);
}
});
return result;
}
public <T> boolean putListCacheWithExpireTime(String key, List<T> objList, final long expireTime) {
final byte[] bkey = key.getBytes();
final byte[] bvalue = ProtoStuffSerializerUtil.serializeList(objList);
boolean result = redisTemplate.execute(new RedisCallback<Boolean>() {
@Override
public Boolean doInRedis(RedisConnection connection) throws DataAccessException {
connection.setEx(bkey, expireTime, bvalue);
return true;
}
});
return result;
}
public <T> T getCache(final String key, Class<T> targetClass) {
byte[] result = redisTemplate.execute(new RedisCallback<byte[]>() {
@Override
public byte[] doInRedis(RedisConnection connection) throws DataAccessException {
return connection.get(key.getBytes());
}
});
if (result == null) {
return null;
}
return ProtoStuffSerializerUtil.deserialize(result, targetClass);
}
public <T> List<T> getListCache(final String key, Class<T> targetClass) {
byte[] result = redisTemplate.execute(new RedisCallback<byte[]>() {
@Override
public byte[] doInRedis(RedisConnection connection) throws DataAccessException {
return connection.get(key.getBytes());
}
});
if (result == null) {
return null;
}
return ProtoStuffSerializerUtil.deserializeList(result, targetClass);
}
/**
* 精确删除key
*
* @param key
*/
public void deleteCache(String key) {
redisTemplate.delete(key);
}
/**
* 模糊删除key
*
* @param pattern
*/
public void deleteCacheWithPattern(String pattern) {
Set<String> keys = redisTemplate.keys(pattern);
redisTemplate.delete(keys);
}
/**
* 清空所有缓存
*/
public void clearCache() {
deleteCacheWithPattern(RedisCache.CAHCENAME+"|*");
}
// public final static String CAHCENAME="cache";//缓存名
// public final static int CAHCETIME=60;//默认缓存时间
//
// @Autowired
// private RedisTemplate<String, String> redisTemplate;
//
// public <T> boolean putCache(String key, T obj) {
// final byte[] bkey = key.getBytes();
// final byte[] bvalue = ProtoStuffSerializerUtil.serialize(obj);
// boolean result = redisTemplate.execute(new RedisCallback<Boolean>() {
// @Override
// public Boolean doInRedis(RedisConnection connection) throws DataAccessException {
// return connection.setNX(bkey, bvalue);
// }
// });
// return result;
// }
//
// public <T> void putCacheWithExpireTime(String key, T obj, final long expireTime) {
// final byte[] bkey = key.getBytes();
// final byte[] bvalue = ProtoStuffSerializerUtil.serialize(obj);
// redisTemplate.execute(new RedisCallback<Boolean>() {
// @Override
// public Boolean doInRedis(RedisConnection connection) throws DataAccessException {
// connection.setEx(bkey, expireTime, bvalue);
// return true;
// }
// });
// }
//
// public <T> boolean putListCache(String key, List<T> objList) {
// final byte[] bkey = key.getBytes();
// final byte[] bvalue = ProtoStuffSerializerUtil.serializeList(objList);
// boolean result = redisTemplate.execute(new RedisCallback<Boolean>() {
// @Override
// public Boolean doInRedis(RedisConnection connection) throws DataAccessException {
// return connection.setNX(bkey, bvalue);
// }
// });
// return result;
// }
//
// public <T> boolean putListCacheWithExpireTime(String key, List<T> objList, final long expireTime) {
// final byte[] bkey = key.getBytes();
// final byte[] bvalue = ProtoStuffSerializerUtil.serializeList(objList);
// boolean result = redisTemplate.execute(new RedisCallback<Boolean>() {
// @Override
// public Boolean doInRedis(RedisConnection connection) throws DataAccessException {
// connection.setEx(bkey, expireTime, bvalue);
// return true;
// }
// });
// return result;
// }
//
// public <T> T getCache(final String key, Class<T> targetClass) {
// byte[] result = redisTemplate.execute(new RedisCallback<byte[]>() {
// @Override
// public byte[] doInRedis(RedisConnection connection) throws DataAccessException {
// return connection.get(key.getBytes());
// }
// });
// if (result == null) {
// return null;
// }
// return ProtoStuffSerializerUtil.deserialize(result, targetClass);
// }
//
// public <T> List<T> getListCache(final String key, Class<T> targetClass) {
// byte[] result = redisTemplate.execute(new RedisCallback<byte[]>() {
// @Override
// public byte[] doInRedis(RedisConnection connection) throws DataAccessException {
// return connection.get(key.getBytes());
// }
// });
// if (result == null) {
// return null;
// }
// return ProtoStuffSerializerUtil.deserializeList(result, targetClass);
// }
//
// /**
// * 精确删除key
// *
// * @param key
// */
// public void deleteCache(String key) {
// redisTemplate.delete(key);
// }
//
// /**
// * 模糊删除key
// *
// * @param pattern
// */
// public void deleteCacheWithPattern(String pattern) {
// Set<String> keys = redisTemplate.keys(pattern);
// redisTemplate.delete(keys);
// }
//
// /**
// * 清空所有缓存
// */
// public void clearCache() {
// deleteCacheWithPattern(RedisCache.CAHCENAME+"|*");
// }
}
......@@ -24,101 +24,101 @@ import java.util.Set;
public class RedisClusterCache {
public final static String CAHCENAME="cache";//缓存名
public final static int CAHCETIME=60;//默认缓存时间
//@Autowired
private JedisCluster jedisCluster;
public <T> void putCache(String key, T obj) {
final byte[] bkey = key.getBytes();
final byte[] bvalue = ProtoStuffSerializerUtil.serialize(obj);
jedisCluster.set(bkey,bvalue);
}
public <T> void putCacheWithExpireTime(String key, T obj, int expireTime) {
final byte[] bkey = key.getBytes();
final byte[] bvalue = ProtoStuffSerializerUtil.serialize(obj);
jedisCluster.setex(bkey, expireTime, bvalue);
}
public <T> void putListCache(String key, List<T> objList) {
final byte[] bkey = key.getBytes();
final byte[] bvalue = ProtoStuffSerializerUtil.serializeList(objList);
jedisCluster.set(bkey,bvalue);
}
public <T> void putListCacheWithExpireTime(String key, List<T> objList, int expireTime) {
final byte[] bkey = key.getBytes();
final byte[] bvalue = ProtoStuffSerializerUtil.serializeList(objList);
jedisCluster.setex(bkey, expireTime, bvalue);
}
public <T> T getCache(final String key, Class<T> targetClass) {
byte[] result =jedisCluster.get(key.getBytes());
if (result == null) {
return null;
}
return ProtoStuffSerializerUtil.deserialize(result, targetClass);
}
public <T> List<T> getListCache(String key, Class<T> targetClass) {
byte[] result =jedisCluster.get(key.getBytes());
if (result == null) {
return null;
}
return ProtoStuffSerializerUtil.deserializeList(result, targetClass);
}
/**
* 精确删除key
*
* @param key
*/
public void deleteCache(String key) {
jedisCluster.del(key);
}
/**
* 模糊删除key
*
* @param pattern
*/
public void deleteCacheWithPattern(String pattern) {
Set<String> keys =this.keys(pattern);
for(String key:keys){
jedisCluster.del(key);
}
}
/**
* 清空所有缓存
*/
public void clearCache() {
deleteCacheWithPattern(RedisClusterCache.CAHCENAME+"|*");
}
/**
* 由于JedisCluster没有提供对keys命令的封装,只能自己实现
* @param pattern
* @return
*/
public Set<String> keys(String pattern){
Set<String> keys = new HashSet<>();
Map<String, JedisPool> clusterNodes = jedisCluster.getClusterNodes();
for(String k : clusterNodes.keySet()){
JedisPool jp = clusterNodes.get(k);
Jedis connection = jp.getResource();
try {
keys.addAll(connection.keys(pattern));
} catch(Exception e){
e.printStackTrace();
} finally{
//用完一定要close这个链接!!!
connection.close();
}
}
return keys;
}
// public final static String CAHCENAME="cache";//缓存名
// public final static int CAHCETIME=60;//默认缓存时间
//
// //@Autowired
// private JedisCluster jedisCluster;
//
//
// public <T> void putCache(String key, T obj) {
// final byte[] bkey = key.getBytes();
// final byte[] bvalue = ProtoStuffSerializerUtil.serialize(obj);
// jedisCluster.set(bkey,bvalue);
// }
//
// public <T> void putCacheWithExpireTime(String key, T obj, int expireTime) {
// final byte[] bkey = key.getBytes();
// final byte[] bvalue = ProtoStuffSerializerUtil.serialize(obj);
// jedisCluster.setex(bkey, expireTime, bvalue);
// }
//
// public <T> void putListCache(String key, List<T> objList) {
// final byte[] bkey = key.getBytes();
// final byte[] bvalue = ProtoStuffSerializerUtil.serializeList(objList);
// jedisCluster.set(bkey,bvalue);
// }
//
// public <T> void putListCacheWithExpireTime(String key, List<T> objList, int expireTime) {
// final byte[] bkey = key.getBytes();
// final byte[] bvalue = ProtoStuffSerializerUtil.serializeList(objList);
// jedisCluster.setex(bkey, expireTime, bvalue);
// }
//
// public <T> T getCache(final String key, Class<T> targetClass) {
// byte[] result =jedisCluster.get(key.getBytes());
// if (result == null) {
// return null;
// }
// return ProtoStuffSerializerUtil.deserialize(result, targetClass);
// }
//
// public <T> List<T> getListCache(String key, Class<T> targetClass) {
// byte[] result =jedisCluster.get(key.getBytes());
// if (result == null) {
// return null;
// }
// return ProtoStuffSerializerUtil.deserializeList(result, targetClass);
// }
//
// /**
// * 精确删除key
// *
// * @param key
// */
// public void deleteCache(String key) {
// jedisCluster.del(key);
// }
//
// /**
// * 模糊删除key
// *
// * @param pattern
// */
// public void deleteCacheWithPattern(String pattern) {
// Set<String> keys =this.keys(pattern);
// for(String key:keys){
// jedisCluster.del(key);
// }
// }
//
// /**
// * 清空所有缓存
// */
// public void clearCache() {
// deleteCacheWithPattern(RedisClusterCache.CAHCENAME+"|*");
// }
//
// /**
// * 由于JedisCluster没有提供对keys命令的封装,只能自己实现
// * @param pattern
// * @return
// */
// public Set<String> keys(String pattern){
// Set<String> keys = new HashSet<>();
// Map<String, JedisPool> clusterNodes = jedisCluster.getClusterNodes();
// for(String k : clusterNodes.keySet()){
// JedisPool jp = clusterNodes.get(k);
// Jedis connection = jp.getResource();
// try {
// keys.addAll(connection.keys(pattern));
// } catch(Exception e){
// e.printStackTrace();
// } finally{
// //用完一定要close这个链接!!!
// connection.close();
// }
// }
// return keys;
// }
}
......@@ -33,28 +33,28 @@ import com.yingjun.ssm.dao.UserDao;
@Component
public class BizQuartz {
private final Logger LOG = LoggerFactory.getLogger(this.getClass());
@Autowired
private UserDao userDao;
@Autowired
private RedisCache cache;
/**
* 用户自动加积分
* 每天9点到17点每过1分钟所有用户加一次积分
*/
@Scheduled(cron = "0 0/1 9-17 * * ? ")
public void addUserScore() {
LOG.info("@Scheduled--------addUserScore()");
userDao.addScore(10);
}
/**
* 每隔5分钟定时清理缓存
*/
@Scheduled(cron = "0 0/5 * * * ? ")
public void cacheClear() {
LOG.info("@Scheduled-------cacheClear()");
cache.clearCache();
}
// private final Logger LOG = LoggerFactory.getLogger(this.getClass());
// @Autowired
// private UserDao userDao;
// @Autowired
// private RedisCache cache;
//
// /**
// * 用户自动加积分
// * 每天9点到17点每过1分钟所有用户加一次积分
// */
// @Scheduled(cron = "0 0/1 9-17 * * ? ")
// public void addUserScore() {
// LOG.info("@Scheduled--------addUserScore()");
// userDao.addScore(10);
// }
// /**
// * 每隔5分钟定时清理缓存
// */
// @Scheduled(cron = "0 0/5 * * * ? ")
// public void cacheClear() {
// LOG.info("@Scheduled-------cacheClear()");
// cache.clearCache();
// }
}
......@@ -35,18 +35,18 @@ public class GoodsServiceImpl implements GoodsService {
@Override
public List<Goods> getGoodsList(int offset, int limit) {
String cache_key = RedisCache.CAHCENAME + "|getGoodsList|" + offset + "|" + limit;
List<Goods> result_cache = cache.getListCache(cache_key, Goods.class);
if (result_cache != null) {
LOG.info("get cache with key:" + cache_key);
} else {
// 缓存中没有再去数据库取,并插入缓存(缓存时间为60秒)
result_cache = goodsDao.queryAll(offset, limit);
cache.putListCacheWithExpireTime(cache_key, result_cache, RedisCache.CAHCETIME);
LOG.info("put cache with key:" + cache_key);
return result_cache;
}
return result_cache;
// String cache_key = RedisCache.CAHCENAME + "|getGoodsList|" + offset + "|" + limit;
// List<Goods> result_cache = cache.getListCache(cache_key, Goods.class);
// if (result_cache != null) {
// LOG.info("get cache with key:" + cache_key);
// } else {
// // 缓存中没有再去数据库取,并插入缓存(缓存时间为60秒)
// result_cache = goodsDao.queryAll(offset, limit);
// cache.putListCacheWithExpireTime(cache_key, result_cache, RedisCache.CAHCETIME);
// LOG.info("put cache with key:" + cache_key);
// return result_cache;
// }
return null;
}
@Transactional
......@@ -72,7 +72,7 @@ public class GoodsServiceImpl implements GoodsService {
} else {
// 买卖成功
// 此时缓存中的数据不是最新的,需要对缓存进行清理(具体的缓存策略还是要根据具体需求制定)
cache.deleteCacheWithPattern("getGoodsList*");
//cache.deleteCacheWithPattern("getGoodsList*");
LOG.info("delete cache with key: getGoodsList*");
return;
}
......@@ -91,7 +91,7 @@ public class GoodsServiceImpl implements GoodsService {
} else {
// 买卖成功
// 此时缓存中的数据不再是最新的,需要对缓存进行清理(具体的缓存策略还是要根据具体需求制定)
cache.deleteCacheWithPattern("getGoodsList*");
//cache.deleteCacheWithPattern("getGoodsList*");
LOG.info("delete cache with key: getGoodsList*");
return;
}
......
......@@ -23,18 +23,18 @@ public class UserServiceImpl implements UserService {
@Override
public List<User> getUserList(int offset, int limit) {
String cache_key=RedisCache.CAHCENAME+"|getUserList|"+offset+"|"+limit;
//先去缓存中取
List<User> result_cache=cache.getListCache(cache_key, User.class);
if(result_cache==null){
//缓存中没有再去数据库取,并插入缓存(缓存时间为60秒)
result_cache=userDao.queryAll(offset, limit);
cache.putListCacheWithExpireTime(cache_key, result_cache, RedisCache.CAHCETIME);
LOG.info("put cache with key:"+cache_key);
}else{
LOG.info("get cache with key:"+cache_key);
}
return result_cache;
// String cache_key=RedisCache.CAHCENAME+"|getUserList|"+offset+"|"+limit;
// //先去缓存中取
// List<User> result_cache=cache.getListCache(cache_key, User.class);
// if(result_cache==null){
// //缓存中没有再去数据库取,并插入缓存(缓存时间为60秒)
// result_cache=userDao.queryAll(offset, limit);
// cache.putListCacheWithExpireTime(cache_key, result_cache, RedisCache.CAHCETIME);
// LOG.info("put cache with key:"+cache_key);
// }else{
// LOG.info("get cache with key:"+cache_key);
// }
return null;
}
......
#redis config
redis.pass=yingjun
redis.pool.maxTotal=105
redis.pool.maxIdle=10
redis.pool.maxWaitMillis=5000
redis.pool.testOnBorrow=true
#redis.pass=yingjun
#redis.pool.maxTotal=105
#redis.pool.maxIdle=10
#redis.pool.maxWaitMillis=5000
#redis.pool.testOnBorrow=true
#redis \u5355\u8282\u70B9\u914D\u7F6E
redis.ip=192.168.xx.xxx
redis.port=6379
#redis.ip=192.168.xx.xxx
#redis.port=6379
#redis \u9AD8\u53EF\u7528\u914D\u7F6E(\u57FA\u4E8Eredis sentinel)
#sentinel1.ip=192.168.11.100
......
......@@ -12,6 +12,6 @@
<task:annotation-driven />
<context:annotation-config />
<context:component-scan base-package="com.yingjun.ssm.quartz"/>
<!--<context:component-scan base-package="com.yingjun.ssm.quartz"/> -->
</beans>
......@@ -3,101 +3,101 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<!-- 缓存的层级-->
<context:component-scan base-package="com.yingjun.ssm.cache" />
<!-- 引入redis配置 -->
<context:property-placeholder location="classpath:redis.properties" ignore-unresolvable="true"/>
<!-- Redis 配置 -->
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
<property name="maxTotal" value="${redis.pool.maxTotal}" />
<property name="maxIdle" value="${redis.pool.maxIdle}" />
<property name="maxWaitMillis" value="${redis.pool.maxWaitMillis}" />
<property name="testOnBorrow" value="${redis.pool.testOnBorrow}" />
</bean>
<!--&lt;!&ndash; 缓存的层级&ndash;&gt;-->
<!--<context:component-scan base-package="com.yingjun.ssm.cache" />-->
<!--&lt;!&ndash; 引入redis配置 &ndash;&gt;-->
<!--<context:property-placeholder location="classpath:redis.properties" ignore-unresolvable="true"/>-->
<!-- JedisCluster 集群高可用配置 -->
<!--<bean id="jedisCluster" class="redis.clients.jedis.JedisCluster">
<constructor-arg index="0">
<set>
<bean class="redis.clients.jedis.HostAndPort">
<constructor-arg index="0" value="${redis.ip1}" />
<constructor-arg index="1" value="${redis.port1}" type="int" />
</bean>
<bean class="redis.clients.jedis.HostAndPort">
<constructor-arg index="0" value="${redis.ip2}" />
<constructor-arg index="1" value="${redis.port2}" type="int" />
</bean>
<bean class="redis.clients.jedis.HostAndPort">
<constructor-arg index="0" value="${redis.ip3}" />
<constructor-arg index="1" value="${redis.port3}" type="int" />
</bean>
<bean class="redis.clients.jedis.HostAndPort">
<constructor-arg index="0" value="${redis.ip4}" />
<constructor-arg index="1" value="${redis.port4}" type="int" />
</bean>
<bean class="redis.clients.jedis.HostAndPort">
<constructor-arg index="0" value="${redis.ip5}" />
<constructor-arg index="1" value="${redis.port5}" type="int" />
</bean>
<bean class="redis.clients.jedis.HostAndPort">
<constructor-arg index="0" value="${redis.ip6}" />
<constructor-arg index="1" value="${redis.port6}" type="int" />
</bean>
</set>
</constructor-arg>
<constructor-arg index="1" value="2000" type="int"></constructor-arg>
<constructor-arg index="2" value="100" type="int"></constructor-arg>
<constructor-arg index="3" ref="jedisPoolConfig"></constructor-arg>
</bean>-->
<!--&lt;!&ndash; Redis 配置 &ndash;&gt;-->
<!--<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">-->
<!--<property name="maxTotal" value="${redis.pool.maxTotal}" />-->
<!--<property name="maxIdle" value="${redis.pool.maxIdle}" />-->
<!--<property name="maxWaitMillis" value="${redis.pool.maxWaitMillis}" />-->
<!--<property name="testOnBorrow" value="${redis.pool.testOnBorrow}" />-->
<!--</bean>-->
<!--redis Sentinel主从高可用方案配置 -->
<!-- <bean id="sentinelConfiguration" class="org.springframework.data.redis.connection.RedisSentinelConfiguration">
<property name="master">
<bean class="org.springframework.data.redis.connection.RedisNode">
<property name="name" value="master-1"></property>
</bean>
</property>
<property name="sentinels">
<set>
<bean class="org.springframework.data.redis.connection.RedisNode">
<constructor-arg name="host" value="${sentinel1.ip}"></constructor-arg>
<constructor-arg name="port" value="${sentinel1.port}"></constructor-arg>
</bean>
<bean class="org.springframework.data.redis.connection.RedisNode">
<constructor-arg name="host" value="${sentinel2.ip}"></constructor-arg>
<constructor-arg name="port" value="${sentinel2.port}"></constructor-arg>
</bean>
<bean class="org.springframework.data.redis.connection.RedisNode">
<constructor-arg name="host" value="${sentinel3.ip}"></constructor-arg>
<constructor-arg name="port" value="${sentinel3.port}"></constructor-arg>
</bean>
</set>
</property>
</bean>
<bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" p:use-pool="true">
<property name="password" value="${redis.pass}" />
<property name="poolConfig">
<ref bean="jedisPoolConfig" />
</property>
<constructor-arg name="sentinelConfig" ref="sentinelConfiguration" />
</bean> -->
<!--&lt;!&ndash; JedisCluster 集群高可用配置 &ndash;&gt;-->
<!--&lt;!&ndash;<bean id="jedisCluster" class="redis.clients.jedis.JedisCluster">-->
<!--<constructor-arg index="0">-->
<!--<set>-->
<!--<bean class="redis.clients.jedis.HostAndPort">-->
<!--<constructor-arg index="0" value="${redis.ip1}" />-->
<!--<constructor-arg index="1" value="${redis.port1}" type="int" />-->
<!--</bean>-->
<!--<bean class="redis.clients.jedis.HostAndPort">-->
<!--<constructor-arg index="0" value="${redis.ip2}" />-->
<!--<constructor-arg index="1" value="${redis.port2}" type="int" />-->
<!--</bean>-->
<!--<bean class="redis.clients.jedis.HostAndPort">-->
<!--<constructor-arg index="0" value="${redis.ip3}" />-->
<!--<constructor-arg index="1" value="${redis.port3}" type="int" />-->
<!--</bean>-->
<!--<bean class="redis.clients.jedis.HostAndPort">-->
<!--<constructor-arg index="0" value="${redis.ip4}" />-->
<!--<constructor-arg index="1" value="${redis.port4}" type="int" />-->
<!--</bean>-->
<!--<bean class="redis.clients.jedis.HostAndPort">-->
<!--<constructor-arg index="0" value="${redis.ip5}" />-->
<!--<constructor-arg index="1" value="${redis.port5}" type="int" />-->
<!--</bean>-->
<!--<bean class="redis.clients.jedis.HostAndPort">-->
<!--<constructor-arg index="0" value="${redis.ip6}" />-->
<!--<constructor-arg index="1" value="${redis.port6}" type="int" />-->
<!--</bean>-->
<!--</set>-->
<!--</constructor-arg>-->
<!--<constructor-arg index="1" value="2000" type="int"></constructor-arg>-->
<!--<constructor-arg index="2" value="100" type="int"></constructor-arg>-->
<!--<constructor-arg index="3" ref="jedisPoolConfig"></constructor-arg>-->
<!--</bean>&ndash;&gt;-->
<!-- redis单节点数据库连接配置 -->
<bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<property name="hostName" value="${redis.ip}" />
<property name="port" value="${redis.port}" />
<property name="password" value="${redis.pass}" />
<property name="poolConfig" ref="jedisPoolConfig" />
</bean>
<!--&lt;!&ndash;redis Sentinel主从高可用方案配置 &ndash;&gt;-->
<!--&lt;!&ndash; <bean id="sentinelConfiguration" class="org.springframework.data.redis.connection.RedisSentinelConfiguration">-->
<!--<property name="master">-->
<!--<bean class="org.springframework.data.redis.connection.RedisNode">-->
<!--<property name="name" value="master-1"></property>-->
<!--</bean>-->
<!--</property>-->
<!--<property name="sentinels">-->
<!--<set>-->
<!--<bean class="org.springframework.data.redis.connection.RedisNode">-->
<!--<constructor-arg name="host" value="${sentinel1.ip}"></constructor-arg>-->
<!--<constructor-arg name="port" value="${sentinel1.port}"></constructor-arg>-->
<!--</bean>-->
<!--<bean class="org.springframework.data.redis.connection.RedisNode">-->
<!--<constructor-arg name="host" value="${sentinel2.ip}"></constructor-arg>-->
<!--<constructor-arg name="port" value="${sentinel2.port}"></constructor-arg>-->
<!--</bean>-->
<!--<bean class="org.springframework.data.redis.connection.RedisNode">-->
<!--<constructor-arg name="host" value="${sentinel3.ip}"></constructor-arg>-->
<!--<constructor-arg name="port" value="${sentinel3.port}"></constructor-arg>-->
<!--</bean>-->
<!--</set>-->
<!--</property>-->
<!--</bean>-->
<!--<bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" p:use-pool="true">-->
<!--<property name="password" value="${redis.pass}" />-->
<!--<property name="poolConfig">-->
<!--<ref bean="jedisPoolConfig" />-->
<!--</property>-->
<!--<constructor-arg name="sentinelConfig" ref="sentinelConfiguration" />-->
<!--</bean> &ndash;&gt;-->
<!-- redisTemplate配置,redisTemplate是对Jedis的对redis操作的扩展,有更多的操作,封装使操作更便捷 -->
<bean id="redisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate">
<property name="connectionFactory" ref="jedisConnectionFactory" />
</bean>
</beans>
<!--&lt;!&ndash; redis单节点数据库连接配置 &ndash;&gt;-->
<!--<bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">-->
<!--<property name="hostName" value="${redis.ip}" />-->
<!--<property name="port" value="${redis.port}" />-->
<!--<property name="password" value="${redis.pass}" />-->
<!--<property name="poolConfig" ref="jedisPoolConfig" />-->
<!--</bean> -->
<!--&lt;!&ndash; redisTemplate配置,redisTemplate是对Jedis的对redis操作的扩展,有更多的操作,封装使操作更便捷 &ndash;&gt;-->
<!--<bean id="redisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate">-->
<!--<property name="connectionFactory" ref="jedisConnectionFactory" />-->
<!--</bean>-->
<!---->
</beans>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册