Interface RedisCodec<K,​V>

  • Type Parameters:
    K - Key type.
    V - Value type.
    All Known Implementing Classes:
    ByteArrayCodec, StringCodec, Utf8StringCodec

    public interface RedisCodec<K,​V>
    A RedisCodec encodes keys and values sent to Redis, and decodes keys and values in the command output. The methods are called by multiple threads and must be thread-safe.
    Author:
    Will Glozer, Mark Paluch, Dimitris Mandalidis
    • Method Detail

      • of

        static <K,​V> RedisCodec<K,​V> of​(RedisCodec<K,​?> keyCodec,
                                                    RedisCodec<?,​V> valueCodec)
        Returns a composite RedisCodec that uses keyCodec for keys and valueCodec for values.
        Type Parameters:
        K - the type of the key
        V - the type of the value
        Parameters:
        keyCodec - the codec to encode/decode the keys.
        valueCodec - the codec to encode/decode the values.
        Returns:
        a composite RedisCodec.
        Since:
        5.2
      • decodeKey

        K decodeKey​(ByteBuffer bytes)
        Decode the key output by redis.
        Parameters:
        bytes - Raw bytes of the key, must not be null.
        Returns:
        The decoded key, may be null.
      • decodeValue

        V decodeValue​(ByteBuffer bytes)
        Decode the value output by redis.
        Parameters:
        bytes - Raw bytes of the value, must not be null.
        Returns:
        The decoded value, may be null.
      • encodeKey

        ByteBuffer encodeKey​(K key)
        Encode the key for output to redis.
        Parameters:
        key - the key, may be null.
        Returns:
        The encoded key, never null.
      • encodeValue

        ByteBuffer encodeValue​(V value)
        Encode the value for output to redis.
        Parameters:
        value - the value, may be null.
        Returns:
        The encoded value, never null.