From d57fc1094625792b20d5ec713bcf9dfb1901ed68 Mon Sep 17 00:00:00 2001 From: fwq <582742538@qq.com> Date: 星期五, 01 九月 2023 10:17:15 +0800 Subject: [PATCH] 增加Excel解析不为空的校验 --- src/main/java/com/hx/redis/RedisUtil.java | 33 +++++++++++++++++++++++++++++++++ 1 files changed, 33 insertions(+), 0 deletions(-) diff --git a/src/main/java/com/hx/redis/RedisUtil.java b/src/main/java/com/hx/redis/RedisUtil.java index 8067593..d9b582b 100644 --- a/src/main/java/com/hx/redis/RedisUtil.java +++ b/src/main/java/com/hx/redis/RedisUtil.java @@ -1,5 +1,6 @@ package com.hx.redis; +import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Component; @@ -23,6 +24,18 @@ @Resource private RedisTemplate<String, Object> redisTemplate; + /** + * 鍒囨崲鏁版嵁搴� + * @param dataNumber 鏁版嵁搴撶紪鍙� + */ + public void setDataBase(int dataNumber) { + LettuceConnectionFactory connectionFactory = (LettuceConnectionFactory) redisTemplate.getConnectionFactory(); + if (connectionFactory != null && dataNumber != connectionFactory.getDatabase()) { + connectionFactory.setDatabase(dataNumber); + this.redisTemplate.setConnectionFactory(connectionFactory); + connectionFactory.resetConnection(); + } + } /** * [鍒ゆ柇key鏄惁瀛樺湪] @@ -128,6 +141,26 @@ } + /** + * 璁剧疆鍒版湡鏃堕棿 + * @param key 瀵瑰簲閿� + * @param time 鏃堕暱 + * @param timeUnit 鏃堕棿鍗曚綅 + * @return + */ + public boolean expire(String key, long time, TimeUnit timeUnit) { + try { + if (time > 0) { + return redisTemplate.expire(key, time, timeUnit); + } + } catch (Exception e) { + e.printStackTrace(); + return false; + + } + return false; + } + /** * hash 鍒犻櫎鎿嶄綔 -- Gitblit v1.8.0