From 3b2c5fb47caca6ab286e0c8ed8c0575024c528d0 Mon Sep 17 00:00:00 2001
From: zxl <763096477@qq.com>
Date: 星期六, 11 十月 2025 09:18:39 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/user_action' into user_action
---
framework/src/main/java/cn/lili/cache/impl/RedisCache.java | 40 +++++++++++++++++++++++++++++++++-------
1 files changed, 33 insertions(+), 7 deletions(-)
diff --git a/framework/src/main/java/cn/lili/cache/impl/RedisCache.java b/framework/src/main/java/cn/lili/cache/impl/RedisCache.java
index ac56702..471ac00 100644
--- a/framework/src/main/java/cn/lili/cache/impl/RedisCache.java
+++ b/framework/src/main/java/cn/lili/cache/impl/RedisCache.java
@@ -1,8 +1,8 @@
package cn.lili.cache.impl;
import cn.lili.cache.Cache;
+import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.core.*;
import org.springframework.data.redis.support.atomic.RedisAtomicLong;
@@ -21,14 +21,10 @@
*/
@Slf4j
@Component
+@RequiredArgsConstructor
public class RedisCache implements Cache {
- @Autowired
- private RedisTemplate<Object, Object> redisTemplate;
-
- public RedisCache() {
-
- }
+ private final RedisTemplate<Object, Object> redisTemplate;
@Override
public Object get(Object key) {
@@ -226,6 +222,13 @@
return entityIdCounter.getAndIncrement();
}
+ @Override
+ public Long decr(String key) {
+ RedisAtomicLong entityIdCounter = new RedisAtomicLong(key, redisTemplate.getConnectionFactory());
+ return entityIdCounter.getAndDecrement();
+ }
+
+
/**
* 浣跨敤Sorted Set璁板綍keyword
* zincrby鍛戒护锛屽浜庝竴涓猄orted Set锛屽瓨鍦ㄧ殑灏辨妸鍒嗘暟鍔爔(x鍙嚜琛岃瀹�)锛屼笉瀛樺湪灏卞垱寤轰竴涓垎鏁颁负1鐨勬垚鍛�
@@ -314,4 +317,27 @@
public Long zRemove(String key, String... value) {
return redisTemplate.opsForZSet().remove(key, value);
}
+
+ /**
+ * 璁剧疆杩囨湡鏃堕棿
+ *
+ * @param key
+ * @param timeout 杩囨湡鏃堕暱
+ * @param timeUnit 鏃堕暱鍗曚綅
+ */
+ @Override
+ public void setExpire(String key, long timeout, TimeUnit timeUnit) {
+ redisTemplate.expire(key, timeout, timeUnit);
+ }
+
+ /**
+ * 鍒ゆ柇鏌愪釜key鏄惁瀛樺湪
+ *
+ * @param key
+ * @return
+ */
+ @Override
+ public boolean exist(String key) {
+ return redisTemplate.hasKey(key);
+ }
}
--
Gitblit v1.8.0