From 19533a17aa55fafc70d0a385928e785cb50e1ebc Mon Sep 17 00:00:00 2001 From: admin <2780501319@qq.com> Date: 星期五, 30 七月 2021 02:05:14 +0800 Subject: [PATCH] 爱奇艺视频更新 --- src/main/java/com/yeshi/buwan/util/RedisManager.java | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 55 insertions(+), 1 deletions(-) diff --git a/src/main/java/com/yeshi/buwan/util/RedisManager.java b/src/main/java/com/yeshi/buwan/util/RedisManager.java index 0de7a41..b0c4805 100644 --- a/src/main/java/com/yeshi/buwan/util/RedisManager.java +++ b/src/main/java/com/yeshi/buwan/util/RedisManager.java @@ -9,6 +9,7 @@ import com.google.gson.Gson; import com.yeshi.buwan.vo.video.VideoListResultVO; +import org.yeshi.utils.SerializeUtil; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; import redis.clients.jedis.params.SetParams; @@ -94,7 +95,7 @@ } - public void increase(String key,int s) { + public void increase(String key, int s) { Jedis jedis = getJedis(); try { jedis.incr(key); @@ -126,6 +127,10 @@ } public void removeCommonString(String key) { + removeKey(key); + } + + public void remove(String key) { removeKey(key); } @@ -208,4 +213,53 @@ return true; } + + /** + * 浠巖edis缂撳瓨涓煡璇紝鍙嶅簭鍒楀寲 + * + * @param redisKey + * @return + */ + public Object getDataFromRedis(String redisKey) { + //鏌ヨ + Jedis jedis = jedisPool.getResource(); + try { + byte[] result = jedis.get(redisKey.getBytes()); + + //濡傛灉鏌ヨ娌℃湁涓虹┖ + if (null == result) { + return null; + } + + //鏌ヨ鍒颁簡锛屽弽搴忓垪鍖� + return SerializeUtil.unSerialize(result); + } finally { + jedis.close(); + } + } + + /** + * 灏嗘暟鎹簱涓煡璇㈠埌鐨勬暟鎹斁鍏edis + * + * @param redisKey + * @param obj + */ + public void setDataToRedis(String redisKey, Object obj, Integer seconds) { + + //搴忓垪鍖� + byte[] bytes = SerializeUtil.serialize(obj); + + SetParams params = null; + if (seconds != null) { + params = new SetParams().nx().ex(seconds); + } + //瀛樺叆redis + Jedis jedis = jedisPool.getResource(); + try { + jedis.set(redisKey.getBytes(), bytes, params); + } finally { + jedis.close(); + } + } + } -- Gitblit v1.8.0