Refine search
@Override public RedisSetCommands setCommands() { return new LettuceSetCommands(this); }
@Override public Set<byte[]> sMembers(byte[] key) { Assert.notNull(key, "Key must not be null!"); try { if (isPipelined()) { pipeline(connection.newLettuceResult(getAsyncConnection().smembers(key))); return null; } if (isQueueing()) { transaction(connection.newLettuceResult(getAsyncConnection().smembers(key))); return null; } return getConnection().smembers(key); } catch (Exception ex) { throw convertLettuceAccessException(ex); } }
@Override public Long sDiffStore(byte[] destKey, byte[]... keys) { Assert.notNull(destKey, "Destination key must not be null!"); Assert.notNull(keys, "Source keys must not be null!"); Assert.noNullElements(keys, "Source keys must not contain null elements!"); byte[][] allKeys = ByteUtils.mergeArrays(destKey, keys); if (ClusterSlotHashUtil.isSameSlotForAllKeys(allKeys)) { return super.sDiffStore(destKey, keys); } Set<byte[]> diff = sDiff(keys); if (diff.isEmpty()) { return 0L; } return sAdd(destKey, diff.toArray(new byte[diff.size()][])); } }
@Override public Set<byte[]> sDiff(byte[]... keys) { Assert.notNull(keys, "Keys must not be null!"); Assert.noNullElements(keys, "Keys must not contain null elements!"); if (ClusterSlotHashUtil.isSameSlotForAllKeys(keys)) { return super.sDiff(keys); } byte[] source = keys[0]; byte[][] others = Arrays.copyOfRange(keys, 1, keys.length); ByteArraySet values = new ByteArraySet(sMembers(source)); Collection<Set<byte[]>> nodeResult = connection.getClusterCommandExecutor() .executeMultiKeyCommand((LettuceMultiKeyClusterCommandCallback<Set<byte[]>>) RedisSetCommands::smembers, Arrays.asList(others)) .resultsAsList(); if (values.isEmpty()) { return Collections.emptySet(); } for (Set<byte[]> toSubstract : nodeResult) { values.removeAll(toSubstract); } return values.asRawSet(); }
@Override public Set<byte[]> sInter(byte[]... keys) { Assert.notNull(keys, "Keys must not be null!"); Assert.noNullElements(keys, "Keys must not contain null elements!"); if (ClusterSlotHashUtil.isSameSlotForAllKeys(keys)) { return super.sInter(keys); } Collection<Set<byte[]>> nodeResult = connection.getClusterCommandExecutor() .executeMultiKeyCommand((LettuceMultiKeyClusterCommandCallback<Set<byte[]>>) RedisSetCommands::smembers, Arrays.asList(keys)) .resultsAsList(); ByteArraySet result = null; for (Set<byte[]> entry : nodeResult) { ByteArraySet tmp = new ByteArraySet(entry); if (result == null) { result = tmp; } else { result.retainAll(tmp); if (result.isEmpty()) { break; } } } if (result == null || result.isEmpty()) { return Collections.emptySet(); } return result.asRawSet(); }
@Override protected ScanIteration<byte[]> doScan(byte[] key, long cursorId, ScanOptions options) { if (isQueueing() || isPipelined()) { throw new UnsupportedOperationException("'SSCAN' cannot be called in pipeline / transaction mode."); } io.lettuce.core.ScanCursor scanCursor = connection.getScanCursor(cursorId); ScanArgs scanArgs = LettuceConverters.toScanArgs(options); ValueScanCursor<byte[]> valueScanCursor = getConnection().sscan(key, scanCursor, scanArgs); String nextCursorId = valueScanCursor.getCursor(); List<byte[]> values = connection.failsafeReadScanValues(valueScanCursor.getValues(), null); return new ScanIteration<>(Long.valueOf(nextCursorId), values); }
@Override public Set<byte[]> sDiff(byte[]... keys) { Assert.notNull(keys, "Keys must not be null!"); Assert.noNullElements(keys, "Keys must not contain null elements!"); if (ClusterSlotHashUtil.isSameSlotForAllKeys(keys)) { return super.sDiff(keys); } byte[] source = keys[0]; byte[][] others = Arrays.copyOfRange(keys, 1, keys.length); ByteArraySet values = new ByteArraySet(sMembers(source)); Collection<Set<byte[]>> nodeResult = connection.getClusterCommandExecutor() .executeMultiKeyCommand((LettuceMultiKeyClusterCommandCallback<Set<byte[]>>) RedisSetCommands::smembers, Arrays.asList(others)) .resultsAsList(); if (values.isEmpty()) { return Collections.emptySet(); } for (Set<byte[]> toSubstract : nodeResult) { values.removeAll(toSubstract); } return values.asRawSet(); }
@Override public Set<byte[]> sInter(byte[]... keys) { Assert.notNull(keys, "Keys must not be null!"); Assert.noNullElements(keys, "Keys must not contain null elements!"); if (ClusterSlotHashUtil.isSameSlotForAllKeys(keys)) { return super.sInter(keys); } Collection<Set<byte[]>> nodeResult = connection.getClusterCommandExecutor() .executeMultiKeyCommand((LettuceMultiKeyClusterCommandCallback<Set<byte[]>>) RedisSetCommands::smembers, Arrays.asList(keys)) .resultsAsList(); ByteArraySet result = null; for (Set<byte[]> entry : nodeResult) { ByteArraySet tmp = new ByteArraySet(entry); if (result == null) { result = tmp; } else { result.retainAll(tmp); if (result.isEmpty()) { break; } } } if (result == null || result.isEmpty()) { return Collections.emptySet(); } return result.asRawSet(); }
@Override protected ScanIteration<byte[]> doScan(byte[] key, long cursorId, ScanOptions options) { if (isQueueing() || isPipelined()) { throw new UnsupportedOperationException("'SSCAN' cannot be called in pipeline / transaction mode."); } io.lettuce.core.ScanCursor scanCursor = connection.getScanCursor(cursorId); ScanArgs scanArgs = LettuceConverters.toScanArgs(options); ValueScanCursor<byte[]> valueScanCursor = getConnection().sscan(key, scanCursor, scanArgs); String nextCursorId = valueScanCursor.getCursor(); List<byte[]> values = connection.failsafeReadScanValues(valueScanCursor.getValues(), null); return new ScanIteration<>(Long.valueOf(nextCursorId), values); }
@Override public Long sCard(byte[] key) { Assert.notNull(key, "Key must not be null!"); try { if (isPipelined()) { pipeline(connection.newLettuceResult(getAsyncConnection().scard(key))); return null; } if (isQueueing()) { transaction(connection.newLettuceResult(getAsyncConnection().scard(key))); return null; } return getConnection().scard(key); } catch (Exception ex) { throw convertLettuceAccessException(ex); } }
@Override public Long sDiffStore(byte[] destKey, byte[]... keys) { Assert.notNull(destKey, "Destination key must not be null!"); Assert.notNull(keys, "Source keys must not be null!"); Assert.noNullElements(keys, "Source keys must not contain null elements!"); byte[][] allKeys = ByteUtils.mergeArrays(destKey, keys); if (ClusterSlotHashUtil.isSameSlotForAllKeys(allKeys)) { return super.sDiffStore(destKey, keys); } Set<byte[]> diff = sDiff(keys); if (diff.isEmpty()) { return 0L; } return sAdd(destKey, diff.toArray(new byte[diff.size()][])); } }
@Override public Set<byte[]> sDiff(byte[]... keys) { Assert.notNull(keys, "Keys must not be null!"); Assert.noNullElements(keys, "Keys must not contain null elements!"); if (ClusterSlotHashUtil.isSameSlotForAllKeys(keys)) { return super.sDiff(keys); } byte[] source = keys[0]; byte[][] others = Arrays.copyOfRange(keys, 1, keys.length); ByteArraySet values = new ByteArraySet(sMembers(source)); Collection<Set<byte[]>> nodeResult = connection.getClusterCommandExecutor() .executeMultiKeyCommand((LettuceMultiKeyClusterCommandCallback<Set<byte[]>>) RedisSetCommands::smembers, Arrays.asList(others)) .resultsAsList(); if (values.isEmpty()) { return Collections.emptySet(); } for (Set<byte[]> toSubstract : nodeResult) { values.removeAll(toSubstract); } return values.asRawSet(); }
@Override public Set<byte[]> sInter(byte[]... keys) { Assert.notNull(keys, "Keys must not be null!"); Assert.noNullElements(keys, "Keys must not contain null elements!"); if (ClusterSlotHashUtil.isSameSlotForAllKeys(keys)) { return super.sInter(keys); } Collection<Set<byte[]>> nodeResult = connection.getClusterCommandExecutor() .executeMultiKeyCommand((LettuceMultiKeyClusterCommandCallback<Set<byte[]>>) RedisSetCommands::smembers, Arrays.asList(keys)) .resultsAsList(); ByteArraySet result = null; for (Set<byte[]> entry : nodeResult) { ByteArraySet tmp = new ByteArraySet(entry); if (result == null) { result = tmp; } else { result.retainAll(tmp); if (result.isEmpty()) { break; } } } if (result == null || result.isEmpty()) { return Collections.emptySet(); } return result.asRawSet(); }
@Override protected ScanIteration<byte[]> doScan(byte[] key, long cursorId, ScanOptions options) { if (isQueueing() || isPipelined()) { throw new UnsupportedOperationException("'SSCAN' cannot be called in pipeline / transaction mode."); } io.lettuce.core.ScanCursor scanCursor = connection.getScanCursor(cursorId); ScanArgs scanArgs = LettuceConverters.toScanArgs(options); ValueScanCursor<byte[]> valueScanCursor = getConnection().sscan(key, scanCursor, scanArgs); String nextCursorId = valueScanCursor.getCursor(); List<byte[]> values = connection.failsafeReadScanValues(valueScanCursor.getValues(), null); return new ScanIteration<>(Long.valueOf(nextCursorId), values); }
@Override public RedisSetCommands setCommands() { return new LettuceSetCommands(this); }
@Override public byte[] sPop(byte[] key) { Assert.notNull(key, "Key must not be null!"); try { if (isPipelined()) { pipeline(connection.newLettuceResult(getAsyncConnection().spop(key))); return null; } if (isQueueing()) { transaction(connection.newLettuceResult(getAsyncConnection().spop(key))); return null; } return getConnection().spop(key); } catch (Exception ex) { throw convertLettuceAccessException(ex); } }
@Override public Long sDiffStore(byte[] destKey, byte[]... keys) { Assert.notNull(destKey, "Destination key must not be null!"); Assert.notNull(keys, "Source keys must not be null!"); Assert.noNullElements(keys, "Source keys must not contain null elements!"); byte[][] allKeys = ByteUtils.mergeArrays(destKey, keys); if (ClusterSlotHashUtil.isSameSlotForAllKeys(allKeys)) { return super.sDiffStore(destKey, keys); } Set<byte[]> diff = sDiff(keys); if (diff.isEmpty()) { return 0L; } return sAdd(destKey, diff.toArray(new byte[diff.size()][])); } }
@Override public RedisSetCommands setCommands() { return new LettuceSetCommands(this); }
@Override public byte[] sRandMember(byte[] key) { Assert.notNull(key, "Key must not be null!"); try { if (isPipelined()) { pipeline(connection.newLettuceResult(getAsyncConnection().srandmember(key))); return null; } if (isQueueing()) { transaction(connection.newLettuceResult(getAsyncConnection().srandmember(key))); return null; } return getConnection().srandmember(key); } catch (Exception ex) { throw convertLettuceAccessException(ex); } }
@Override public Set<byte[]> sUnion(byte[]... keys) { Assert.notNull(keys, "Keys must not be null!"); Assert.noNullElements(keys, "Keys must not contain null elements!"); try { if (isPipelined()) { pipeline(connection.newLettuceResult(getAsyncConnection().sunion(keys))); return null; } if (isQueueing()) { transaction(connection.newLettuceResult(getAsyncConnection().sunion(keys))); return null; } return getConnection().sunion(keys); } catch (Exception ex) { throw convertLettuceAccessException(ex); } }