...
|
...
|
@@ -11,56 +11,86 @@ import org.slf4j.LoggerFactory; |
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.BitSet;
|
|
|
import java.util.Collection;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
@Service("searchRedis")
|
|
|
public class SearchRedis implements CacheInterface {
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(SearchRedis.class);
|
|
|
private static final Logger logger = LoggerFactory.getLogger(SearchRedis.class);
|
|
|
|
|
|
@Autowired
|
|
|
private YohoSearchRedisComponent yohoSearchRedisComponent;
|
|
|
|
|
|
@Override
|
|
|
public boolean exist(RedisKeyBuilder redisKeyBuilder) {
|
|
|
try {
|
|
|
YHRedisTemplate redisTemplate = yohoSearchRedisComponent.getRedisTemplate();
|
|
|
return RedisCacheUtils.exist(redisTemplate, redisKeyBuilder);
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage(), e);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Autowired
|
|
|
private YohoSearchRedisComponent yohoSearchRedisComponent;
|
|
|
@Override
|
|
|
public CacheObject get(RedisKeyBuilder redisKeyBuilder) {
|
|
|
try {
|
|
|
YHValueOperations valueOperations = yohoSearchRedisComponent.getValueOperations();
|
|
|
return RedisCacheUtils.get(valueOperations, redisKeyBuilder, CacheObject.class);
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage(), e);
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public CacheObject get(RedisKeyBuilder redisKeyBuilder) {
|
|
|
try {
|
|
|
YHValueOperations valueOperations = yohoSearchRedisComponent.getValueOperations();
|
|
|
return RedisCacheUtils.get(valueOperations, redisKeyBuilder, CacheObject.class);
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage(), e);
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
@Override
|
|
|
public void addOrUpdate(RedisKeyBuilder redisKeyBuilder, CacheObject value, int expiredTimeInMinute) {
|
|
|
try {
|
|
|
YHValueOperations valueOperations = yohoSearchRedisComponent.getValueOperations();
|
|
|
RedisCacheUtils.add(valueOperations, redisKeyBuilder, value, expiredTimeInMinute);
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage(), e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void addOrUpdate(RedisKeyBuilder redisKeyBuilder, CacheObject value, int expiredTimeInMinute) {
|
|
|
try {
|
|
|
YHValueOperations valueOperations = yohoSearchRedisComponent.getValueOperations();
|
|
|
RedisCacheUtils.add(valueOperations, redisKeyBuilder, value, expiredTimeInMinute);
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage(), e);
|
|
|
}
|
|
|
@Override
|
|
|
public void mutiSet(Map<RedisKeyBuilder, String> map, int expiredTimeInMinute) {
|
|
|
YHRedisTemplate redisTemplate = yohoSearchRedisComponent.getRedisTemplate();
|
|
|
RedisCacheUtils.mutiSet(redisTemplate, map, expiredTimeInMinute);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
@Override
|
|
|
public List<String> mutiGet(Collection<RedisKeyBuilder> redisKeyBuilders) {
|
|
|
YHValueOperations valueOperations = yohoSearchRedisComponent.getValueOperations();
|
|
|
return RedisCacheUtils.mutiGet(valueOperations, redisKeyBuilders);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void delete(RedisKeyBuilder redisKeyBuilder) {
|
|
|
try {
|
|
|
YHRedisTemplate redisTemplate = yohoSearchRedisComponent.getRedisTemplate();
|
|
|
RedisCacheUtils.delete(redisTemplate, redisKeyBuilder);
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage(), e);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
@Override
|
|
|
public boolean setBitSet(RedisKeyBuilder redisKeyBuilder, BitSet bitSet, int expiredTimeInMinute) {
|
|
|
try {
|
|
|
return RedisCacheUtils.setBitSet(yohoSearchRedisComponent.getRedisTemplate(), redisKeyBuilder, bitSet, expiredTimeInMinute);
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage(), e);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public boolean exist(RedisKeyBuilder redisKeyBuilder) {
|
|
|
try {
|
|
|
YHRedisTemplate redisTemplate = yohoSearchRedisComponent.getRedisTemplate();
|
|
|
return RedisCacheUtils.exist(redisTemplate, redisKeyBuilder);
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage(), e);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
@Override
|
|
|
public Map<Integer, Boolean> getFromBitSet(RedisKeyBuilder key, List<Integer> offsets) {
|
|
|
try {
|
|
|
YHRedisTemplate redisTemplate = yohoSearchRedisComponent.getRedisTemplate();
|
|
|
if (!redisTemplate.hasKey(key)) {
|
|
|
return null;
|
|
|
}
|
|
|
return RedisCacheUtils.getBits(redisTemplate, key, offsets);
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage(), e);
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|