|
|
@ -8,6 +8,9 @@ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
package co.yixiang.utils; |
|
|
|
package co.yixiang.utils; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
|
|
|
|
import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; |
|
|
|
|
|
|
|
import com.mchange.v2.net.LocalHostManager; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.data.redis.connection.RedisConnection; |
|
|
|
import org.springframework.data.redis.connection.RedisConnection; |
|
|
|
import org.springframework.data.redis.connection.RedisConnectionFactory; |
|
|
|
import org.springframework.data.redis.connection.RedisConnectionFactory; |
|
|
@ -17,26 +20,24 @@ import org.springframework.util.CollectionUtils; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.*; |
|
|
|
import java.util.*; |
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @author / |
|
|
|
* @author / |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Component |
|
|
|
@Component |
|
|
|
@SuppressWarnings({"unchecked","all"}) |
|
|
|
|
|
|
|
public class RedisUtils { |
|
|
|
public class RedisUtils { |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
private RedisTemplate stringRedisTemplate; |
|
|
|
private RedisTemplate stringRedisTemplate; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// =============================commonold============================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 指定缓存失效时间 |
|
|
|
* 指定缓存失效时间 |
|
|
|
* @param key 键 |
|
|
|
* @param key 键 |
|
|
|
* @param time 时间(秒) |
|
|
|
* @param time 时间(秒) |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public boolean expire(String key, long time) { |
|
|
|
public boolean expire(String key, long time) { |
|
|
|
|
|
|
|
key = StrUtil.format("{}_{}",TenantContextHolder.getTenantId(),key); |
|
|
|
try { |
|
|
|
try { |
|
|
|
if (time > 0) { |
|
|
|
if (time > 0) { |
|
|
|
stringRedisTemplate.expire(key, time, TimeUnit.SECONDS); |
|
|
|
stringRedisTemplate.expire(key, time, TimeUnit.SECONDS); |
|
|
@ -54,6 +55,7 @@ public class RedisUtils { |
|
|
|
* @return 时间(秒) 返回0代表为永久有效 |
|
|
|
* @return 时间(秒) 返回0代表为永久有效 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public long getExpire(String key) { |
|
|
|
public long getExpire(String key) { |
|
|
|
|
|
|
|
key = StrUtil.format("{}_{}",TenantContextHolder.getTenantId(),key); |
|
|
|
return stringRedisTemplate.getExpire(key, TimeUnit.SECONDS); |
|
|
|
return stringRedisTemplate.getExpire(key, TimeUnit.SECONDS); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -63,6 +65,7 @@ public class RedisUtils { |
|
|
|
* @return / |
|
|
|
* @return / |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public List<String> scan(String pattern) { |
|
|
|
public List<String> scan(String pattern) { |
|
|
|
|
|
|
|
pattern = StrUtil.format("{}_{}",TenantContextHolder.getTenantId(),pattern); |
|
|
|
ScanOptions options = ScanOptions.scanOptions().match(pattern).build(); |
|
|
|
ScanOptions options = ScanOptions.scanOptions().match(pattern).build(); |
|
|
|
RedisConnectionFactory factory = stringRedisTemplate.getConnectionFactory(); |
|
|
|
RedisConnectionFactory factory = stringRedisTemplate.getConnectionFactory(); |
|
|
|
RedisConnection rc = Objects.requireNonNull(factory).getConnection(); |
|
|
|
RedisConnection rc = Objects.requireNonNull(factory).getConnection(); |
|
|
@ -87,6 +90,7 @@ public class RedisUtils { |
|
|
|
* @return / |
|
|
|
* @return / |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public List<String> findKeysForPage(String patternKey, int page, int size) { |
|
|
|
public List<String> findKeysForPage(String patternKey, int page, int size) { |
|
|
|
|
|
|
|
patternKey = StrUtil.format("{}_{}",TenantContextHolder.getTenantId(),patternKey); |
|
|
|
ScanOptions options = ScanOptions.scanOptions().match(patternKey).build(); |
|
|
|
ScanOptions options = ScanOptions.scanOptions().match(patternKey).build(); |
|
|
|
RedisConnectionFactory factory = stringRedisTemplate.getConnectionFactory(); |
|
|
|
RedisConnectionFactory factory = stringRedisTemplate.getConnectionFactory(); |
|
|
|
RedisConnection rc = Objects.requireNonNull(factory).getConnection(); |
|
|
|
RedisConnection rc = Objects.requireNonNull(factory).getConnection(); |
|
|
@ -123,6 +127,7 @@ public class RedisUtils { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public boolean hasKey(String key) { |
|
|
|
public boolean hasKey(String key) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
|
|
|
|
key = StrUtil.format("{}_{}",TenantContextHolder.getTenantId(),key); |
|
|
|
return stringRedisTemplate.hasKey(key); |
|
|
|
return stringRedisTemplate.hasKey(key); |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
e.printStackTrace(); |
|
|
@ -137,9 +142,14 @@ public class RedisUtils { |
|
|
|
public void del(String... key) { |
|
|
|
public void del(String... key) { |
|
|
|
if (key != null && key.length > 0) { |
|
|
|
if (key != null && key.length > 0) { |
|
|
|
if (key.length == 1) { |
|
|
|
if (key.length == 1) { |
|
|
|
stringRedisTemplate.delete(key[0]); |
|
|
|
stringRedisTemplate.delete(StrUtil.format("{}_{}",TenantContextHolder.getTenantId(),key[0])); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
stringRedisTemplate.delete((Collection<String>) CollectionUtils.arrayToList(key)); |
|
|
|
stringRedisTemplate.delete( |
|
|
|
|
|
|
|
CollectionUtils |
|
|
|
|
|
|
|
.arrayToList(key) |
|
|
|
|
|
|
|
.stream() |
|
|
|
|
|
|
|
.map(s-> StrUtil.format("{}_{}",TenantContextHolder.getTenantId(),s)) |
|
|
|
|
|
|
|
.collect(Collectors.toList())); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -152,11 +162,13 @@ public class RedisUtils { |
|
|
|
* @return 值 |
|
|
|
* @return 值 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Object get(String key) { |
|
|
|
public Object get(String key) { |
|
|
|
return key == null ? null : stringRedisTemplate.opsForValue().get(key); |
|
|
|
return key == null ? null : stringRedisTemplate.opsForValue().get(StrUtil.format("{}_{}",TenantContextHolder.getTenantId(),key)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public String getY(String key){ |
|
|
|
public String getY(String key){ |
|
|
|
return key == null || !stringRedisTemplate.hasKey(key) ? "" : stringRedisTemplate.opsForValue().get(key).toString(); |
|
|
|
return key == null || !stringRedisTemplate.hasKey(StrUtil.format("{}_{}",TenantContextHolder.getTenantId(),key)) |
|
|
|
|
|
|
|
? "" |
|
|
|
|
|
|
|
: stringRedisTemplate.opsForValue().get(StrUtil.format("{}_{}",TenantContextHolder.getTenantId(),key)).toString(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -165,8 +177,8 @@ public class RedisUtils { |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public List<Object> multiGet(List<String> keys) { |
|
|
|
public List<Object> multiGet(List<String> keys) { |
|
|
|
Object obj = stringRedisTemplate.opsForValue().multiGet(keys); |
|
|
|
keys = keys.stream().map(s-> StrUtil.format("{}_{}",TenantContextHolder.getTenantId(),s)).collect(Collectors.toList()); |
|
|
|
return null; |
|
|
|
return stringRedisTemplate.opsForValue().multiGet(keys); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -176,6 +188,7 @@ public class RedisUtils { |
|
|
|
* @return true成功 false失败 |
|
|
|
* @return true成功 false失败 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public boolean set(String key, Object value) { |
|
|
|
public boolean set(String key, Object value) { |
|
|
|
|
|
|
|
key = StrUtil.format("{}_{}",TenantContextHolder.getTenantId(),key); |
|
|
|
try { |
|
|
|
try { |
|
|
|
stringRedisTemplate.opsForValue().set(key, value); |
|
|
|
stringRedisTemplate.opsForValue().set(key, value); |
|
|
|
return true; |
|
|
|
return true; |
|
|
@ -193,6 +206,7 @@ public class RedisUtils { |
|
|
|
* @return true成功 false 失败 |
|
|
|
* @return true成功 false 失败 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public boolean set(String key, Object value, long time) { |
|
|
|
public boolean set(String key, Object value, long time) { |
|
|
|
|
|
|
|
key = StrUtil.format("{}_{}",TenantContextHolder.getTenantId(),key); |
|
|
|
try { |
|
|
|
try { |
|
|
|
if (time > 0) { |
|
|
|
if (time > 0) { |
|
|
|
stringRedisTemplate.opsForValue().set(key, value, time, TimeUnit.SECONDS); |
|
|
|
stringRedisTemplate.opsForValue().set(key, value, time, TimeUnit.SECONDS); |
|
|
@ -215,6 +229,7 @@ public class RedisUtils { |
|
|
|
* @return true成功 false 失败 |
|
|
|
* @return true成功 false 失败 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public boolean set(String key, String value, long time, TimeUnit timeUnit) { |
|
|
|
public boolean set(String key, String value, long time, TimeUnit timeUnit) { |
|
|
|
|
|
|
|
key = StrUtil.format("{}_{}",TenantContextHolder.getTenantId(),key); |
|
|
|
try { |
|
|
|
try { |
|
|
|
if (time > 0) { |
|
|
|
if (time > 0) { |
|
|
|
stringRedisTemplate.opsForValue().set(key, value, time, timeUnit); |
|
|
|
stringRedisTemplate.opsForValue().set(key, value, time, timeUnit); |
|
|
@ -237,6 +252,7 @@ public class RedisUtils { |
|
|
|
* @return 值 |
|
|
|
* @return 值 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Object hget(String key, String item) { |
|
|
|
public Object hget(String key, String item) { |
|
|
|
|
|
|
|
key = StrUtil.format("{}_{}",TenantContextHolder.getTenantId(),key); |
|
|
|
return stringRedisTemplate.opsForHash().get(key, item); |
|
|
|
return stringRedisTemplate.opsForHash().get(key, item); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -246,6 +262,7 @@ public class RedisUtils { |
|
|
|
* @return 对应的多个键值 |
|
|
|
* @return 对应的多个键值 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Map<Object, Object> hmget(String key) { |
|
|
|
public Map<Object, Object> hmget(String key) { |
|
|
|
|
|
|
|
key = StrUtil.format("{}_{}",TenantContextHolder.getTenantId(),key); |
|
|
|
return stringRedisTemplate.opsForHash().entries(key); |
|
|
|
return stringRedisTemplate.opsForHash().entries(key); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
@ -257,6 +274,7 @@ public class RedisUtils { |
|
|
|
* @return true 成功 false 失败 |
|
|
|
* @return true 成功 false 失败 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public boolean hmset(String key, Map<String, Object> map) { |
|
|
|
public boolean hmset(String key, Map<String, Object> map) { |
|
|
|
|
|
|
|
key = StrUtil.format("{}_{}",TenantContextHolder.getTenantId(),key); |
|
|
|
try { |
|
|
|
try { |
|
|
|
stringRedisTemplate.opsForHash().putAll(key, map); |
|
|
|
stringRedisTemplate.opsForHash().putAll(key, map); |
|
|
|
return true; |
|
|
|
return true; |
|
|
@ -274,6 +292,7 @@ public class RedisUtils { |
|
|
|
* @return true成功 false失败 |
|
|
|
* @return true成功 false失败 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public boolean hmset(String key, Map<String, Object> map, long time) { |
|
|
|
public boolean hmset(String key, Map<String, Object> map, long time) { |
|
|
|
|
|
|
|
key = StrUtil.format("{}_{}",TenantContextHolder.getTenantId(),key); |
|
|
|
try { |
|
|
|
try { |
|
|
|
stringRedisTemplate.opsForHash().putAll(key, map); |
|
|
|
stringRedisTemplate.opsForHash().putAll(key, map); |
|
|
|
if (time > 0) { |
|
|
|
if (time > 0) { |
|
|
@ -295,6 +314,7 @@ public class RedisUtils { |
|
|
|
* @return true 成功 false失败 |
|
|
|
* @return true 成功 false失败 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public boolean hset(String key, String item, Object value) { |
|
|
|
public boolean hset(String key, String item, Object value) { |
|
|
|
|
|
|
|
key = StrUtil.format("{}_{}",TenantContextHolder.getTenantId(),key); |
|
|
|
try { |
|
|
|
try { |
|
|
|
stringRedisTemplate.opsForHash().put(key, item, value); |
|
|
|
stringRedisTemplate.opsForHash().put(key, item, value); |
|
|
|
return true; |
|
|
|
return true; |
|
|
@ -314,6 +334,7 @@ public class RedisUtils { |
|
|
|
* @return true 成功 false失败 |
|
|
|
* @return true 成功 false失败 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public boolean hset(String key, String item, Object value, long time) { |
|
|
|
public boolean hset(String key, String item, Object value, long time) { |
|
|
|
|
|
|
|
key = StrUtil.format("{}_{}",TenantContextHolder.getTenantId(),key); |
|
|
|
try { |
|
|
|
try { |
|
|
|
stringRedisTemplate.opsForHash().put(key, item, value); |
|
|
|
stringRedisTemplate.opsForHash().put(key, item, value); |
|
|
|
if (time > 0) { |
|
|
|
if (time > 0) { |
|
|
@ -333,6 +354,7 @@ public class RedisUtils { |
|
|
|
* @param item 项 可以使多个 不能为null |
|
|
|
* @param item 项 可以使多个 不能为null |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void hdel(String key, Object... item) { |
|
|
|
public void hdel(String key, Object... item) { |
|
|
|
|
|
|
|
key = StrUtil.format("{}_{}",TenantContextHolder.getTenantId(),key); |
|
|
|
stringRedisTemplate.opsForHash().delete(key, item); |
|
|
|
stringRedisTemplate.opsForHash().delete(key, item); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -344,6 +366,7 @@ public class RedisUtils { |
|
|
|
* @return true 存在 false不存在 |
|
|
|
* @return true 存在 false不存在 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public boolean hHasKey(String key, String item) { |
|
|
|
public boolean hHasKey(String key, String item) { |
|
|
|
|
|
|
|
key = StrUtil.format("{}_{}",TenantContextHolder.getTenantId(),key); |
|
|
|
return stringRedisTemplate.opsForHash().hasKey(key, item); |
|
|
|
return stringRedisTemplate.opsForHash().hasKey(key, item); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -356,6 +379,7 @@ public class RedisUtils { |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public double hincr(String key, String item, double by) { |
|
|
|
public double hincr(String key, String item, double by) { |
|
|
|
|
|
|
|
key = StrUtil.format("{}_{}",TenantContextHolder.getTenantId(),key); |
|
|
|
return stringRedisTemplate.opsForHash().increment(key, item, by); |
|
|
|
return stringRedisTemplate.opsForHash().increment(key, item, by); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -368,6 +392,7 @@ public class RedisUtils { |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public double hdecr(String key, String item, double by) { |
|
|
|
public double hdecr(String key, String item, double by) { |
|
|
|
|
|
|
|
key = StrUtil.format("{}_{}",TenantContextHolder.getTenantId(),key); |
|
|
|
return stringRedisTemplate.opsForHash().increment(key, item, -by); |
|
|
|
return stringRedisTemplate.opsForHash().increment(key, item, -by); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -380,6 +405,7 @@ public class RedisUtils { |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Set<Object> sGet(String key) { |
|
|
|
public Set<Object> sGet(String key) { |
|
|
|
|
|
|
|
key = StrUtil.format("{}_{}",TenantContextHolder.getTenantId(),key); |
|
|
|
try { |
|
|
|
try { |
|
|
|
return stringRedisTemplate.opsForSet().members(key); |
|
|
|
return stringRedisTemplate.opsForSet().members(key); |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
@ -396,6 +422,7 @@ public class RedisUtils { |
|
|
|
* @return true 存在 false不存在 |
|
|
|
* @return true 存在 false不存在 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public boolean sHasKey(String key, Object value) { |
|
|
|
public boolean sHasKey(String key, Object value) { |
|
|
|
|
|
|
|
key = StrUtil.format("{}_{}",TenantContextHolder.getTenantId(),key); |
|
|
|
try { |
|
|
|
try { |
|
|
|
return stringRedisTemplate.opsForSet().isMember(key, value); |
|
|
|
return stringRedisTemplate.opsForSet().isMember(key, value); |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
@ -412,6 +439,7 @@ public class RedisUtils { |
|
|
|
* @return 成功个数 |
|
|
|
* @return 成功个数 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public long sSet(String key, Object... values) { |
|
|
|
public long sSet(String key, Object... values) { |
|
|
|
|
|
|
|
key = StrUtil.format("{}_{}",TenantContextHolder.getTenantId(),key); |
|
|
|
try { |
|
|
|
try { |
|
|
|
return stringRedisTemplate.opsForSet().add(key, values); |
|
|
|
return stringRedisTemplate.opsForSet().add(key, values); |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
@ -428,6 +456,7 @@ public class RedisUtils { |
|
|
|
* @return 成功个数 |
|
|
|
* @return 成功个数 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public long sSetAndTime(String key, long time, Object... values) { |
|
|
|
public long sSetAndTime(String key, long time, Object... values) { |
|
|
|
|
|
|
|
key = StrUtil.format("{}_{}",TenantContextHolder.getTenantId(),key); |
|
|
|
try { |
|
|
|
try { |
|
|
|
Long count = stringRedisTemplate.opsForSet().add(key, values); |
|
|
|
Long count = stringRedisTemplate.opsForSet().add(key, values); |
|
|
|
if (time > 0) { |
|
|
|
if (time > 0) { |
|
|
@ -446,6 +475,7 @@ public class RedisUtils { |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public long sGetSetSize(String key) { |
|
|
|
public long sGetSetSize(String key) { |
|
|
|
|
|
|
|
key = StrUtil.format("{}_{}",TenantContextHolder.getTenantId(),key); |
|
|
|
try { |
|
|
|
try { |
|
|
|
return stringRedisTemplate.opsForSet().size(key); |
|
|
|
return stringRedisTemplate.opsForSet().size(key); |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
@ -461,6 +491,7 @@ public class RedisUtils { |
|
|
|
* @return 移除的个数 |
|
|
|
* @return 移除的个数 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public long setRemove(String key, Object... values) { |
|
|
|
public long setRemove(String key, Object... values) { |
|
|
|
|
|
|
|
key = StrUtil.format("{}_{}",TenantContextHolder.getTenantId(),key); |
|
|
|
try { |
|
|
|
try { |
|
|
|
Long count = stringRedisTemplate.opsForSet().remove(key, values); |
|
|
|
Long count = stringRedisTemplate.opsForSet().remove(key, values); |
|
|
|
return count; |
|
|
|
return count; |
|
|
@ -480,6 +511,7 @@ public class RedisUtils { |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public List<Object> lGet(String key, long start, long end) { |
|
|
|
public List<Object> lGet(String key, long start, long end) { |
|
|
|
|
|
|
|
key = StrUtil.format("{}_{}",TenantContextHolder.getTenantId(),key); |
|
|
|
try { |
|
|
|
try { |
|
|
|
return stringRedisTemplate.opsForList().range(key, start, end); |
|
|
|
return stringRedisTemplate.opsForList().range(key, start, end); |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
@ -494,6 +526,7 @@ public class RedisUtils { |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public long lGetListSize(String key) { |
|
|
|
public long lGetListSize(String key) { |
|
|
|
|
|
|
|
key = StrUtil.format("{}_{}",TenantContextHolder.getTenantId(),key); |
|
|
|
try { |
|
|
|
try { |
|
|
|
return stringRedisTemplate.opsForList().size(key); |
|
|
|
return stringRedisTemplate.opsForList().size(key); |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
@ -509,6 +542,7 @@ public class RedisUtils { |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Object lGetIndex(String key, long index) { |
|
|
|
public Object lGetIndex(String key, long index) { |
|
|
|
|
|
|
|
key = StrUtil.format("{}_{}",TenantContextHolder.getTenantId(),key); |
|
|
|
try { |
|
|
|
try { |
|
|
|
return stringRedisTemplate.opsForList().index(key, index); |
|
|
|
return stringRedisTemplate.opsForList().index(key, index); |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
@ -524,6 +558,7 @@ public class RedisUtils { |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public boolean lSet(String key, Object value) { |
|
|
|
public boolean lSet(String key, Object value) { |
|
|
|
|
|
|
|
key = StrUtil.format("{}_{}",TenantContextHolder.getTenantId(),key); |
|
|
|
try { |
|
|
|
try { |
|
|
|
stringRedisTemplate.opsForList().rightPush(key, value); |
|
|
|
stringRedisTemplate.opsForList().rightPush(key, value); |
|
|
|
return true; |
|
|
|
return true; |
|
|
@ -541,6 +576,7 @@ public class RedisUtils { |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public boolean lSet(String key, Object value, long time) { |
|
|
|
public boolean lSet(String key, Object value, long time) { |
|
|
|
|
|
|
|
key = StrUtil.format("{}_{}",TenantContextHolder.getTenantId(),key); |
|
|
|
try { |
|
|
|
try { |
|
|
|
stringRedisTemplate.opsForList().rightPush(key, value); |
|
|
|
stringRedisTemplate.opsForList().rightPush(key, value); |
|
|
|
if (time > 0) { |
|
|
|
if (time > 0) { |
|
|
@ -560,6 +596,7 @@ public class RedisUtils { |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public boolean lSet(String key, List<Object> value) { |
|
|
|
public boolean lSet(String key, List<Object> value) { |
|
|
|
|
|
|
|
key = StrUtil.format("{}_{}",TenantContextHolder.getTenantId(),key); |
|
|
|
try { |
|
|
|
try { |
|
|
|
stringRedisTemplate.opsForList().rightPushAll(key, value); |
|
|
|
stringRedisTemplate.opsForList().rightPushAll(key, value); |
|
|
|
return true; |
|
|
|
return true; |
|
|
@ -577,6 +614,7 @@ public class RedisUtils { |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public boolean lSet(String key, List<Object> value, long time) { |
|
|
|
public boolean lSet(String key, List<Object> value, long time) { |
|
|
|
|
|
|
|
key = StrUtil.format("{}_{}",TenantContextHolder.getTenantId(),key); |
|
|
|
try { |
|
|
|
try { |
|
|
|
stringRedisTemplate.opsForList().rightPushAll(key, value); |
|
|
|
stringRedisTemplate.opsForList().rightPushAll(key, value); |
|
|
|
if (time > 0) { |
|
|
|
if (time > 0) { |
|
|
@ -597,6 +635,7 @@ public class RedisUtils { |
|
|
|
* @return / |
|
|
|
* @return / |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public boolean lUpdateIndex(String key, long index, Object value) { |
|
|
|
public boolean lUpdateIndex(String key, long index, Object value) { |
|
|
|
|
|
|
|
key = StrUtil.format("{}_{}",TenantContextHolder.getTenantId(),key); |
|
|
|
try { |
|
|
|
try { |
|
|
|
stringRedisTemplate.opsForList().set(key, index, value); |
|
|
|
stringRedisTemplate.opsForList().set(key, index, value); |
|
|
|
return true; |
|
|
|
return true; |
|
|
@ -614,6 +653,7 @@ public class RedisUtils { |
|
|
|
* @return 移除的个数 |
|
|
|
* @return 移除的个数 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public long lRemove(String key, long count, Object value) { |
|
|
|
public long lRemove(String key, long count, Object value) { |
|
|
|
|
|
|
|
key = StrUtil.format("{}_{}",TenantContextHolder.getTenantId(),key); |
|
|
|
try { |
|
|
|
try { |
|
|
|
return stringRedisTemplate.opsForList().remove(key, count, value); |
|
|
|
return stringRedisTemplate.opsForList().remove(key, count, value); |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|