Class Redis<K,V>

java.lang.Object
com.imyeyu.spring.util.Redis<K,V>
Type Parameters:
K - 键类型
V - 值类型

public class Redis<K,V> extends Object
RedisTemplate 功能封装,简化 Redis 操作

serializer 为该 RedisTemplate 的键的序列化操作,序列化解析器由 AbstractRedisConfig 提供

Version:
2021-11-21 09:58
Author:
夜雨
  • Constructor Details

    • Redis

      public Redis()
    • Redis

      public Redis(org.springframework.data.redis.core.RedisTemplate<K,V> redis, org.springframework.data.redis.serializer.RedisSerializer<K> serializer)
  • Method Details

    • lock

      public boolean lock(K key, V value, long timeoutMS)
      加锁
      Parameters:
      key - 键
      value - 值
      timeoutMS - 超时时间毫秒
      Returns:
      true 为加锁成功
    • releaseLock

      public void releaseLock(K key)
      释放锁
      Parameters:
      key - 键
    • setExpire

      public void setExpire(K key, long ms)
      设置存活时间
      Parameters:
      key - 键
      ms - 毫秒 TTL
    • getExpire

      public long getExpire(K key)
      获取该数据 TTL
      Parameters:
      key - 键
      Returns:
      毫秒 TTL
    • setAndKeepTTL

      public void setAndKeepTTL(K key, V value)
      设置数据并保持 TTL
      Parameters:
      key - 键
      value - 值
    • set

      public void set(K key, V value, long ms)
      设置数据
      Parameters:
      key - 键
      value - 值
      ms - 毫秒 TTL
    • get

      public V get(K key)
      获取值
      Parameters:
      key - 键
      Returns:
    • getString

      public String getString(K key)
      获取值,强转为 String
      Parameters:
      key - 键
      Returns:
    • is

      public Boolean is(K key)
      获取值,强转为 Boolean
      Parameters:
      key - 键
      Returns:
    • not

      public Boolean not(K key)
      获取值,强转为 Boolean 并取反
      Parameters:
      key - 键
      Returns:
    • has

      public boolean has(K key)
      是否存在
      Parameters:
      key - 键
      Returns:
      true 为存在
    • add

      public void add(K key, V value)
      对列表添加值
      Parameters:
      key - 键
      value - 值
    • addAll

      @SafeVarargs public final void addAll(K key, V... values)
      对列表批量添加值
      Parameters:
      key - 键
      values - 值
    • getList

      public List<V> getList(K key)
      获取为列表
      Parameters:
      key - 键
      Returns:
      列表
    • getAllList

      public Map<K,List<V>> getAllList()
      获取所有数据列表
      Returns:
      所有数据列表
    • contains

      public boolean contains(K key, V value)
      值为列表时查找是否存在某值
      Parameters:
      key - 键
      value - 值
      Returns:
      true 为存在
    • values

      public List<V> values()
      获取所有值
      Returns:
      所有值
      Throws:
      com.imyeyu.java.bean.timi.TimiException - 异常
    • map

      public Map<K,V> map()
      获取所有数据(包括键)
      Returns:
      所有数据(包括键)
    • keys

      public List<K> keys(String pattern)
      获取符合条件的 key
      Parameters:
      pattern - 表达式
      Returns:
      keys
    • destroy

      public boolean destroy(K key)
      销毁对象
      Parameters:
      key - 键
      Returns:
      true 为成功
    • flushAll

      public void flushAll()
      删库
    • getRedis

      public org.springframework.data.redis.core.RedisTemplate<K,V> getRedis()
    • getSerializer

      public org.springframework.data.redis.serializer.RedisSerializer<K> getSerializer()
    • setRedis

      public void setRedis(org.springframework.data.redis.core.RedisTemplate<K,V> redis)
    • setSerializer

      public void setSerializer(org.springframework.data.redis.serializer.RedisSerializer<K> serializer)
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • canEqual

      protected boolean canEqual(Object other)
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object