DownGradeCacheService.java
1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package com.yoho.search.common.downgrade;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yoho.search.common.cache.impls.SearchRedis;
import com.yoho.search.common.utils.RedisCacheUtils;
@Service
public class DownGradeCacheService {
private static final Logger logger = LoggerFactory.getLogger(DownGradeCacheService.class);
@Autowired
private SearchRedis searchRedisCache;
public boolean exist(String key) {
try {
return RedisCacheUtils.exist(searchRedisCache.searchRedisTemplate, key);
} catch (Exception e) {
logger.error(e.getMessage(), e);
return false;
}
}
public <T> T safeGet(String key, Class<T> clazz) {
try {
return RedisCacheUtils.get(searchRedisCache.searchValueOperations, key, clazz);
} catch (Exception e) {
logger.error(e.getMessage(), e);
return null;
}
}
public <T> void safeAdd(String key, T t, int expiredTimeInMinute) {
try {
RedisCacheUtils.add(searchRedisCache.searchValueOperations, key, t, expiredTimeInMinute);
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
}