类 RedisUtil

java.lang.Object
cn.jrack.springboot.redis.core.util.RedisUtil

@Component public class RedisUtil extends Object
Redis工具类,使用之前请确保RedisTemplate成功注入
作者:
joy
  • 方法详细资料

    • init

      @PostConstruct public void init()
    • expire

      public static boolean expire(String key, long timeout)
      设置有效时间 单位默认秒
      参数:
      key - Redis键
      timeout - 超时时间
      返回:
      true=设置成功;false=设置失败
    • expire

      public static boolean expire(String key, long timeout, TimeUnit unit)
      设置有效时间
      参数:
      key - Redis键
      timeout - 超时时间
      unit - 时间单位
      返回:
      true=设置成功;false=设置失败
    • del

      public static boolean del(String key)
      删除单个key
      参数:
      key - 键
      返回:
      true=删除成功;false=删除失败
    • del

      public static long del(Collection<String> keys)
      删除多个key
      参数:
      keys - 键集合
      返回:
      成功删除的个数
    • set

      public static void set(String key, Object value)
      存入普通对象
      参数:
      key - Redis键
      value - 值
    • set

      public static void set(String key, Object value, long timeout)
      存入普通对象
      参数:
      key - 键
      value - 值
      timeout - 有效期,单位秒
    • get

      public static Object get(String key)
      获取普通对象
      参数:
      key - 键
      返回:
      对象
    • hPut

      public static void hPut(String key, String filed, Object value)
      往Hash中存入数据
      参数:
      key - Redis键
      filed - Hash filed键
      value - 值
    • hPutAll

      public static void hPutAll(String key, Map<String,Object> filedMap)
      往Hash中存入多个数据
      参数:
      key - Redis键
      filedMap - Hash键值对
    • hGet

      public static Object hGet(String key, String filed)
      获取Hash中的数据
      参数:
      key - Redis键
      filed - Hash filed键
      返回:
      Hash中的对象
    • hMultiGet

      public static List<Object> hMultiGet(String key, Collection<Object> fileds)
      获取多个Hash中的数据
      参数:
      key - Redis键
      fileds - Hash filed键集合
      返回:
      Hash对象集合
    • sSet

      public static long sSet(String key, Object... values)
      往Set中存入数据
      参数:
      key - Redis键
      values - 值
      返回:
      存入的个数
    • sDel

      public static long sDel(String key, Object... values)
      删除Set中的数据
      参数:
      key - Redis键
      values - 值
      返回:
      移除的个数
    • lPush

      public static long lPush(String key, Object value)
      往List左侧中存入数据
      参数:
      key - Redis键
      value - 数据
      返回:
      存入的个数
    • rPush

      public static long rPush(String key, Object value)
      往List右侧中存入数据
      参数:
      key - Redis键
      value - 数据
      返回:
      存入的个数
    • lPushAll

      public static long lPushAll(String key, Collection<Object> values)
      往List中左侧存入多个数据
      参数:
      key - Redis键
      values - 多个数据
      返回:
      存入的个数
    • lPushAll

      public static long lPushAll(String key, Object... values)
      往List中左侧存入多个数据
      参数:
      key - Redis键
      values - 多个数据
      返回:
      存入的个数
    • rPushAll

      public static long rPushAll(String key, Collection<Object> values)
      往List中右侧存入多个数据
      参数:
      key - Redis键
      values - 多个数据
      返回:
      存入的个数
    • rPushAll

      public static long rPushAll(String key, Object... values)
      往List中右侧存入多个数据
      参数:
      key - Redis键
      values - 多个数据
      返回:
      存入的个数
    • listGetRange

      public static List<Object> listGetRange(String key, int start, int end)
      从List中获取begin到end之间的元素
      参数:
      key - Redis键
      start - 开始位置
      end - 结束位置(start=0,end=-1表示获取全部元素)
      返回:
      List对象
    • listGetL

      public static Object listGetL(String key)
      从List左侧弹出数据
      参数:
      key - Redis键
      返回:
      对象
    • listGetR

      public static Object listGetR(String key)
      从List右侧弹出数据
      参数:
      key - Redis键
      返回:
      对象