过期key监听器

This commit is contained in:
lpphan
2022-03-17 23:10:35 +08:00
committed by han
parent f3aac79d52
commit e6562296b2
5 changed files with 174 additions and 3 deletions
@@ -1,6 +1,7 @@
package com.central.common.redis.template;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.connection.RedisClusterNode;
import org.springframework.data.redis.connection.RedisConnection;
@@ -178,6 +179,26 @@ public class RedisRepository {
public Object get(final String key) {
return redisTemplate.opsForValue().get(key);
}
/**
*获取原来key键对应的值并重新赋新值。
* @param key
* @param value
* @return
*/
public String getAndSet(final String key,Object value) {
String result = null;
if (StringUtils.isEmpty(key)){
log.error("key不能为空");
return null;
}
try {
result = (String) redisTemplate.opsForValue().getAndSet(key, value);
}catch (Exception e){
e.printStackTrace();
}
return result;
}
/**
* 根据key获取对象
*
@@ -190,6 +211,7 @@ public class RedisRepository {
return redisTemplate.execute(connection -> deserializeValue(connection.get(rawKey), valueSerializer), true);
}
/**
* Ops for hash hash operations.
*