Class JedisUtils

java.lang.Object
org.deltava.util.JedisUtils

public class JedisUtils extends Object
A utility class for Redis operations.
Since:
6.1
Version:
11.3
Author:
Luke
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Key used for round-trip latency tests.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    delete(String... keys)
    Deletes keys from Redis.
    static byte[]
    Returns a key's encoding in UTF-8.
    static Object
    get(String key)
    Fetches an object from Redis.
    static redis.clients.jedis.Jedis
    Obtains a connection from the Jedis connection pool.
    static Map<String,Object>
    Returns the Redis server and connection pool status.
    static void
    init(org.gvagroup.pool.ConnectionPool<redis.clients.jedis.Jedis> pool)
    Injects the Jedis connection pool.
    keys(String pattern)
    Returns all keys matching a particular pattern.
    static void
    push(String key, String value, int maxLength)
    Pushes a value to a list.
    static Object
    read(byte[] data)
    Deserializes an object and swallows exceptions.
    static byte[]
    Helper method to serialiaze an object and swallow checked exceptions.
    static void
    write(String key, long expiry, Object value)
    Writes an object to Redis.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Method Details

    • init

      public static void init(org.gvagroup.pool.ConnectionPool<redis.clients.jedis.Jedis> pool)
      Injects the Jedis connection pool.
      Parameters:
      pool - the pool
    • getConnection

      public static redis.clients.jedis.Jedis getConnection() throws Exception
      Obtains a connection from the Jedis connection pool. This exists for JedisCache, and is ugly
      Returns:
      a Jedis connection
      Throws:
      Exception - if the connection pool is full or not yet loaded
    • encodeKey

      public static byte[] encodeKey(String key)
      Returns a key's encoding in UTF-8.
      Parameters:
      key - the key
      Returns:
      the key using the standard encoding
    • read

      public static Object read(byte[] data)
      Deserializes an object and swallows exceptions.
      Parameters:
      data - the raw data
      Returns:
      the deserialized data
    • write

      public static byte[] write(Object o)
      Helper method to serialiaze an object and swallow checked exceptions.
      Parameters:
      o - the Object to serialize
      Returns:
      the serialized data
    • get

      public static Object get(String key)
      Fetches an object from Redis.
      Parameters:
      key - the key
      Returns:
      the value
    • write

      public static void write(String key, long expiry, Object value)
      Writes an object to Redis.
      Parameters:
      key - the key
      expiry - the expiry time in seconds from the present or an absolute timestamp
      value - the value
    • push

      public static void push(String key, String value, int maxLength)
      Pushes a value to a list. The list will be trimmed if it exceeds a maximum size.
      Parameters:
      key - the key
      value - the list element
      maxLength - the maximum size of the list or zero for unlimited
    • delete

      public static void delete(String... keys)
      Deletes keys from Redis.
      Parameters:
      keys - the keys
    • keys

      public static Collection<String> keys(String pattern)
      Returns all keys matching a particular pattern.
      Parameters:
      pattern - the key pattern
      Returns:
      a Collection of keys
    • getStatus

      public static Map<String,Object> getStatus()
      Returns the Redis server and connection pool status.
      Returns:
      a Map of status attributes