/** * @param keys must not be {@literal null}. * @return */ public static boolean isSameSlotForAllKeys(byte[]... keys) { Assert.notNull(keys, "Keys must not be null!"); if (keys.length <= 1) { return true; } int slot = calculateSlot(keys[0]); for (int i = 1; i < keys.length; i++) { if (slot != calculateSlot(keys[i])) { return false; } } return true; }
/** * Calculate the slot from the given key. * * @param key must not be {@literal null} or empty. * @return */ public static int calculateSlot(String key) { Assert.hasText(key, "Key must not be null or empty!"); return calculateSlot(key.getBytes()); }
/** * @param key must not be {@literal null}. * @return {@literal null}. */ public Set<RedisClusterNode> getKeyServingNodes(byte[] key) { Assert.notNull(key, "Key must not be null for Cluster Node lookup."); return getSlotServingNodes(ClusterSlotHashUtil.calculateSlot(key)); } }
/** * Get the {@link RedisClusterNode} that is the current master serving the given key. * * @param key must not be {@literal null}. * @return never {@literal null}. * @throws ClusterStateFailureException */ public RedisClusterNode getKeyServingMasterNode(byte[] key) { Assert.notNull(key, "Key for node lookup must not be null!"); int slot = ClusterSlotHashUtil.calculateSlot(key); for (RedisClusterNode node : nodes) { if (node.isMaster() && node.servesSlot(slot)) { return node; } } throw new ClusterStateFailureException( String.format("Could not find master node serving slot %s for key '%s',", slot, Arrays.toString(key))); }
/** * @param keys must not be {@literal null}. * @return */ public static boolean isSameSlotForAllKeys(byte[]... keys) { Assert.notNull(keys, "Keys must not be null!"); if (keys.length <= 1) { return true; } int slot = calculateSlot(keys[0]); for (int i = 1; i < keys.length; i++) { if (slot != calculateSlot(keys[i])) { return false; } } return true; }
/** * @param keys must not be {@literal null}. * @return */ public static boolean isSameSlotForAllKeys(byte[]... keys) { Assert.notNull(keys, "Keys must not be null!"); if (keys.length <= 1) { return true; } int slot = calculateSlot(keys[0]); for (int i = 1; i < keys.length; i++) { if (slot != calculateSlot(keys[i])) { return false; } } return true; }
/** * Calculate the slot from the given key. * * @param key must not be {@literal null} or empty. * @return */ public static int calculateSlot(String key) { Assert.hasText(key, "Key must not be null or empty!"); return calculateSlot(key.getBytes()); }
/** * Calculate the slot from the given key. * * @param key must not be {@literal null} or empty. * @return */ public static int calculateSlot(String key) { Assert.hasText(key, "Key must not be null or empty!"); return calculateSlot(key.getBytes()); }
/** * @param key must not be {@literal null}. * @return {@literal null}. */ public Set<RedisClusterNode> getKeyServingNodes(byte[] key) { Assert.notNull(key, "Key must not be null for Cluster Node lookup."); return getSlotServingNodes(ClusterSlotHashUtil.calculateSlot(key)); } }
/** * @param key must not be {@literal null}. * @return {@literal null}. */ public Set<RedisClusterNode> getKeyServingNodes(byte[] key) { Assert.notNull(key, "Key must not be null for Cluster Node lookup."); return getSlotServingNodes(ClusterSlotHashUtil.calculateSlot(key)); } }
/** * Get the {@link RedisClusterNode} that is the current master serving the given key. * * @param key must not be {@literal null}. * @return never {@literal null}. * @throws ClusterStateFailureException */ public RedisClusterNode getKeyServingMasterNode(byte[] key) { Assert.notNull(key, "Key for node lookup must not be null!"); int slot = ClusterSlotHashUtil.calculateSlot(key); for (RedisClusterNode node : nodes) { if (node.isMaster() && node.servesSlot(slot)) { return node; } } throw new ClusterStateFailureException( String.format("Could not find master node serving slot %s for key '%s',", slot, Arrays.toString(key))); }
/** * Get the {@link RedisClusterNode} that is the current master serving the given key. * * @param key must not be {@literal null}. * @return never {@literal null}. * @throws ClusterStateFailureException */ public RedisClusterNode getKeyServingMasterNode(byte[] key) { Assert.notNull(key, "Key for node lookup must not be null!"); int slot = ClusterSlotHashUtil.calculateSlot(key); for (RedisClusterNode node : nodes) { if (node.isMaster() && node.servesSlot(slot)) { return node; } } throw new ClusterStateFailureException( String.format("Could not find master node serving slot %s for key '%s',", slot, Arrays.toString(key))); }