Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
beauty_ssm
提交
7f488679
B
beauty_ssm
项目概览
爱吃血肠
/
beauty_ssm
通知
9
Star
1
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
B
beauty_ssm
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
7f488679
编写于
3月 03, 2018
作者:
爱吃血肠
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修改后台redis缓存报错问题
上级
95313b58
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
352 addition
and
352 deletion
+352
-352
src/main/java/com/yingjun/ssm/cache/RedisCache.java
src/main/java/com/yingjun/ssm/cache/RedisCache.java
+106
-106
src/main/java/com/yingjun/ssm/cache/RedisClusterCache.java
src/main/java/com/yingjun/ssm/cache/RedisClusterCache.java
+97
-97
src/main/java/com/yingjun/ssm/quartz/BizQuartz.java
src/main/java/com/yingjun/ssm/quartz/BizQuartz.java
+23
-23
src/main/java/com/yingjun/ssm/service/impl/GoodsServiceImpl.java
...n/java/com/yingjun/ssm/service/impl/GoodsServiceImpl.java
+14
-14
src/main/java/com/yingjun/ssm/service/impl/UserServiceImpl.java
...in/java/com/yingjun/ssm/service/impl/UserServiceImpl.java
+12
-12
src/main/resources/redis.properties
src/main/resources/redis.properties
+7
-7
src/main/resources/spring/spring-quartz.xml
src/main/resources/spring/spring-quartz.xml
+1
-1
src/main/resources/spring/spring-redis.xml
src/main/resources/spring/spring-redis.xml
+92
-92
未找到文件。
src/main/java/com/yingjun/ssm/cache/RedisCache.java
浏览文件 @
7f488679
...
...
@@ -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+"|*");
//
}
}
src/main/java/com/yingjun/ssm/cache/RedisClusterCache.java
浏览文件 @
7f488679
...
...
@@ -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;
//
}
}
src/main/java/com/yingjun/ssm/quartz/BizQuartz.java
浏览文件 @
7f488679
...
...
@@ -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();
//
}
}
src/main/java/com/yingjun/ssm/service/impl/GoodsServiceImpl.java
浏览文件 @
7f488679
...
...
@@ -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
;
}
...
...
src/main/java/com/yingjun/ssm/service/impl/UserServiceImpl.java
浏览文件 @
7f488679
...
...
@@ -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
;
}
...
...
src/main/resources/redis.properties
浏览文件 @
7f488679
#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
...
...
src/main/resources/spring/spring-quartz.xml
浏览文件 @
7f488679
...
...
@@ -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>
src/main/resources/spring/spring-redis.xml
浏览文件 @
7f488679
...
...
@@ -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>
<!--<!– 缓存的层级–>-->
<!--<context:component-scan base-package="com.yingjun.ssm.cache" />-->
<!--<!– 引入redis配置 –>-->
<!--<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>-->
<!--<!– 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>-->
<!--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> -->
<!--<!– 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>–>-->
<!-- 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>
<!--<!–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> –>-->
<!-- redisTemplate配置,redisTemplate是对Jedis的对redis操作的扩展,有更多的操作,封装使操作更便捷 -->
<bean
id=
"redisTemplate"
class=
"org.springframework.data.redis.core.StringRedisTemplate"
>
<property
name=
"connectionFactory"
ref=
"jedisConnectionFactory"
/>
</bean>
</beans>
<!--<!– 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> -->
<!--<!– redisTemplate配置,redisTemplate是对Jedis的对redis操作的扩展,有更多的操作,封装使操作更便捷 –>-->
<!--<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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录