mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-22 15:13:55 +08:00
优化清空redis的key方法。添加加1,减1方法
--RedisUtils.java 新的方法 --emptyAll.lua 清空redis的key的lua脚本
This commit is contained in:
@@ -45,6 +45,24 @@ public class RedisUtils {
|
||||
*/
|
||||
public final static long NOT_EXPIRE = -1L;
|
||||
|
||||
public Long increment(String key, long expire) {
|
||||
Long increment = redisTemplate.opsForValue().increment(key, 1L);
|
||||
if (expire != NOT_EXPIRE) {
|
||||
expire(key, expire);
|
||||
}
|
||||
return increment;
|
||||
}
|
||||
|
||||
public Long increment(String key) {
|
||||
return redisTemplate.opsForValue().increment(key, 1L);
|
||||
}
|
||||
|
||||
public Long decrement(String key) {
|
||||
return redisTemplate.opsForValue().decrement(key, 1L);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void set(String key, Object value, long expire) {
|
||||
redisTemplate.opsForValue().set(key, value);
|
||||
if (expire != NOT_EXPIRE) {
|
||||
@@ -139,7 +157,7 @@ public class RedisUtils {
|
||||
*/
|
||||
public void emptyAll() {
|
||||
// Lua 脚本 FLUSHALL是redis清空所有库的命令
|
||||
String luaScript ="redis.call('FLUSHALL')";
|
||||
String luaScript =resourceUtils.loadString("lua/emptyAll.lua");
|
||||
|
||||
// 创建 DefaultRedisScript 对象
|
||||
DefaultRedisScript<Void> redisScript = new DefaultRedisScript<>();
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
redis.call('FLUSHALL')
|
||||
Reference in New Issue
Block a user