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
FieldsModifier and TypeFieldDescriptionstatic final intprotected static final byteprotected static final byte -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intcalculateSlot(byte[] key) Calculate the slot from the given key.static intcalculateSlot(String key) Calculate the slot from the given key.static booleanisSameSlotForAllKeys(byte[]... keys) Determines whether all keys will hash to the same slot.static booleanisSameSlotForAllKeys(ByteBuffer... keys) Determines whether all keys will hash to the same slot.static booleanDetermines 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 ofByteBufferobjects 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-CollectionofByteBufferobjects 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 theCollectionof keys is null.- Since:
- 2.0
-
calculateSlot
Calculate the slot from the given key.- Parameters:
key-Stringcontaining the Redis key to evaluate; must not be null or empty.- Returns:
- the computed slot based on the given key.
- Throws:
IllegalArgumentException- if the givenkeyis 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.
-