Class ClusterSlotHashUtil
java.lang.Object
org.springframework.data.redis.connection.ClusterSlotHashUtil
Utility class encapsulating functionality commonly used for cluster slot hashing.
- Since:
- 1.7
- Author:
- Christoph Strobl, John Blum
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
protected static final byte
protected static final byte
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic int
calculateSlot
(byte[] key) Calculate the slot from the given key.static int
calculateSlot
(String key) Calculate the slot from the given key.static boolean
isSameSlotForAllKeys
(byte[]... keys) Determines whether all keys will hash to the same slot.static boolean
isSameSlotForAllKeys
(ByteBuffer... keys) Determines whether all keys will hash to the same slot.static boolean
Determines whether all keys will hash to the same slot.
-
Field Details
-
SLOT_COUNT
public static final int SLOT_COUNT- See Also:
-
SUBKEY_START
protected static final byte SUBKEY_START- See Also:
-
SUBKEY_END
protected static final byte SUBKEY_END- See Also:
-
-
Constructor Details
-
ClusterSlotHashUtil
public ClusterSlotHashUtil()
-
-
Method Details
-
isSameSlotForAllKeys
public static boolean isSameSlotForAllKeys(byte[]... keys) Determines whether all keys will hash to the same slot.- Parameters:
keys
- array of keys to evaluate3; must not be null.- Returns:
- a boolean value indicating whether all keys will hash to the same slot.
- Throws:
IllegalArgumentException
- if the byte array of keys is null.
-
isSameSlotForAllKeys
Determines whether all keys will hash to the same slot.- Parameters:
keys
- array ofByteBuffer
objects containing the keys to evaluate; must not be null.- Returns:
- a boolean value indicating whether all keys will hash to the same slot.
- Throws:
IllegalArgumentException
- if the array of keys is null.- Since:
- 2.0
- See Also:
-
isSameSlotForAllKeys
Determines whether all keys will hash to the same slot.- Parameters:
keys
-Collection
ofByteBuffer
objects containing the keys to evaluate; must not be null.- Returns:
- a boolean value indicating whether all keys will hash to the same slot.
- Throws:
IllegalArgumentException
- if theCollection
of keys is null.- Since:
- 2.0
-
calculateSlot
Calculate the slot from the given key.- Parameters:
key
-String
containing the Redis key to evaluate; must not be null or empty.- Returns:
- the computed slot based on the given key.
- Throws:
IllegalArgumentException
- if the givenkey
is null or empty.- See Also:
-
calculateSlot
public static int calculateSlot(byte[] key) Calculate the slot from the given key.- Parameters:
key
- array of bytes containing the Redis key to evaluate; must not be null.- Returns:
- the computed slot based on the given key.
-