Class SlotHash


  • public class SlotHash
    extends Object
    Utility to calculate the slot from a key.
    Since:
    3.0
    Author:
    Mark Paluch
    • Field Detail

      • SUBKEY_START

        public static final byte SUBKEY_START
        Constant for a subkey start.
        See Also:
        Constant Field Values
      • SUBKEY_END

        public static final byte SUBKEY_END
        Constant for a subkey end.
        See Also:
        Constant Field Values
      • SLOT_COUNT

        public static final int SLOT_COUNT
        Number of redis cluster slot hashes.
        See Also:
        Constant Field Values
    • Method Detail

      • getSlot

        public static int getSlot​(String key)
        Calculate the slot from the given key.
        Parameters:
        key - the key
        Returns:
        slot
      • getSlot

        public static int getSlot​(byte[] key)
        Calculate the slot from the given key.
        Parameters:
        key - the key
        Returns:
        slot
      • getSlot

        public static int getSlot​(ByteBuffer key)
        Calculate the slot from the given key.
        Parameters:
        key - the key
        Returns:
        slot
      • partition

        public static <K,​V> Map<Integer,​List<K>> partition​(RedisCodec<K,​V> codec,
                                                                       Iterable<K> keys)
        Partition keys by slot-hash. The resulting map honors order of the keys.
        Type Parameters:
        K - Key type.
        V - Value type.
        Parameters:
        codec - codec to encode the key.
        keys - iterable of keys.
        Returns:
        map between slot-hash and an ordered list of keys.
      • getSlots

        public static <S extends Number,​K> Map<K,​S> getSlots​(Map<S,​? extends Iterable<K>> partitioned)
        Create mapping between the Key and hash slot.
        Type Parameters:
        K - key type
        S - slot-hash number type.
        Parameters:
        partitioned - map partitioned by slot-hash and keys.
        Returns:
        map of keys to their slot-hash.