private LettuceClusterKeyCommands doGetClusterKeyCommands() { return new LettuceClusterKeyCommands(this); }
@Override public Boolean renameNX(byte[] sourceKey, byte[] targetKey) { Assert.notNull(sourceKey, "Source key must not be null!"); Assert.notNull(targetKey, "Target key must not be null!"); if (ClusterSlotHashUtil.isSameSlotForAllKeys(sourceKey, targetKey)) { return super.renameNX(sourceKey, targetKey); } byte[] value = dump(sourceKey); if (value != null && value.length > 0 && !exists(targetKey)) { restore(targetKey, 0, value); del(sourceKey); return Boolean.TRUE; } return Boolean.FALSE; }
@Override public Set<byte[]> keys(RedisClusterNode node, byte[] pattern) { return doGetClusterKeyCommands().keys(node, pattern); }
@Override public void rename(byte[] sourceKey, byte[] targetKey) { Assert.notNull(sourceKey, "Source key must not be null!"); Assert.notNull(targetKey, "Target key must not be null!"); if (ClusterSlotHashUtil.isSameSlotForAllKeys(sourceKey, targetKey)) { super.rename(sourceKey, targetKey); return; } byte[] value = dump(sourceKey); if (value != null && value.length > 0) { restore(targetKey, 0, value); del(sourceKey); } }
@Override public Long sort(byte[] key, SortParameters params, byte[] storeKey) { Assert.notNull(key, "Key must not be null!"); if (ClusterSlotHashUtil.isSameSlotForAllKeys(key, storeKey)) { return super.sort(key, params, storeKey); } List<byte[]> sorted = sort(key, params); if (!CollectionUtils.isEmpty(sorted)) { byte[][] arr = new byte[sorted.size()][]; switch (type(key)) { case SET: connection.setCommands().sAdd(storeKey, sorted.toArray(arr)); return 1L; case LIST: connection.listCommands().lPush(storeKey, sorted.toArray(arr)); return 1L; default: throw new IllegalArgumentException("sort and store is only supported for SET and LIST"); } } return 0L; } }
public byte[] randomKey(RedisClusterNode node) { return doGetClusterKeyCommands().randomKey(node); }
@Override public Cursor<byte[]> scan(RedisClusterNode node, ScanOptions options) { return doGetClusterKeyCommands().scan(node, options); }
@Override public void rename(byte[] sourceKey, byte[] targetKey) { Assert.notNull(sourceKey, "Source key must not be null!"); Assert.notNull(targetKey, "Target key must not be null!"); if (ClusterSlotHashUtil.isSameSlotForAllKeys(sourceKey, targetKey)) { super.rename(sourceKey, targetKey); return; } byte[] value = dump(sourceKey); if (value != null && value.length > 0) { restore(targetKey, 0, value); del(sourceKey); } }
@Override public Long sort(byte[] key, SortParameters params, byte[] storeKey) { Assert.notNull(key, "Key must not be null!"); if (ClusterSlotHashUtil.isSameSlotForAllKeys(key, storeKey)) { return super.sort(key, params, storeKey); } List<byte[]> sorted = sort(key, params); if (!CollectionUtils.isEmpty(sorted)) { byte[][] arr = new byte[sorted.size()][]; switch (type(key)) { case SET: connection.setCommands().sAdd(storeKey, sorted.toArray(arr)); return 1L; case LIST: connection.listCommands().lPush(storeKey, sorted.toArray(arr)); return 1L; default: throw new IllegalArgumentException("sort and store is only supported for SET and LIST"); } } return 0L; } }
@Override public byte[] randomKey() { List<RedisClusterNode> nodes = connection.clusterGetNodes(); Set<RedisClusterNode> inspectedNodes = new HashSet<>(nodes.size()); do { RedisClusterNode node = nodes.get(ThreadLocalRandom.current().nextInt(nodes.size())); while (inspectedNodes.contains(node)) { node = nodes.get(ThreadLocalRandom.current().nextInt(nodes.size())); } inspectedNodes.add(node); byte[] key = randomKey(node); if (key != null && key.length > 0) { return key; } } while (nodes.size() != inspectedNodes.size()); return null; }
@Override public Cursor<byte[]> scan(RedisClusterNode node, ScanOptions options) { return doGetClusterKeyCommands().scan(node, options); }
@Override public Boolean renameNX(byte[] sourceKey, byte[] targetKey) { Assert.notNull(sourceKey, "Source key must not be null!"); Assert.notNull(targetKey, "Target key must not be null!"); if (ClusterSlotHashUtil.isSameSlotForAllKeys(sourceKey, targetKey)) { return super.renameNX(sourceKey, targetKey); } byte[] value = dump(sourceKey); if (value != null && value.length > 0 && !exists(targetKey)) { restore(targetKey, 0, value); del(sourceKey); return Boolean.TRUE; } return Boolean.FALSE; }
@Override public void rename(byte[] sourceKey, byte[] targetKey) { Assert.notNull(sourceKey, "Source key must not be null!"); Assert.notNull(targetKey, "Target key must not be null!"); if (ClusterSlotHashUtil.isSameSlotForAllKeys(sourceKey, targetKey)) { super.rename(sourceKey, targetKey); return; } byte[] value = dump(sourceKey); if (value != null && value.length > 0) { restore(targetKey, 0, value); del(sourceKey); } }
@Override public Long sort(byte[] key, SortParameters params, byte[] storeKey) { Assert.notNull(key, "Key must not be null!"); if (ClusterSlotHashUtil.isSameSlotForAllKeys(key, storeKey)) { return super.sort(key, params, storeKey); } List<byte[]> sorted = sort(key, params); if (!CollectionUtils.isEmpty(sorted)) { byte[][] arr = new byte[sorted.size()][]; switch (type(key)) { case SET: connection.setCommands().sAdd(storeKey, sorted.toArray(arr)); return 1L; case LIST: connection.listCommands().lPush(storeKey, sorted.toArray(arr)); return 1L; default: throw new IllegalArgumentException("sort and store is only supported for SET and LIST"); } } return 0L; } }
public byte[] randomKey(RedisClusterNode node) { return doGetClusterKeyCommands().randomKey(node); }
@Override public Cursor<byte[]> scan(RedisClusterNode node, ScanOptions options) { return doGetClusterKeyCommands().scan(node, options); }
private LettuceClusterKeyCommands doGetClusterKeyCommands() { return new LettuceClusterKeyCommands(this); }
@Override public Set<byte[]> keys(RedisClusterNode node, byte[] pattern) { return doGetClusterKeyCommands().keys(node, pattern); }
@Override public Boolean renameNX(byte[] sourceKey, byte[] targetKey) { Assert.notNull(sourceKey, "Source key must not be null!"); Assert.notNull(targetKey, "Target key must not be null!"); if (ClusterSlotHashUtil.isSameSlotForAllKeys(sourceKey, targetKey)) { return super.renameNX(sourceKey, targetKey); } byte[] value = dump(sourceKey); if (value != null && value.length > 0 && !exists(targetKey)) { restore(targetKey, 0, value); del(sourceKey); return Boolean.TRUE; } return Boolean.FALSE; }
public byte[] randomKey(RedisClusterNode node) { return doGetClusterKeyCommands().randomKey(node); }