Skip to content

Commit

Permalink
perf(redis): Use SMEMBERS for redis repository scanSet (#901)
Browse files Browse the repository at this point in the history
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
nessex and mergify[bot] committed Apr 1, 2022
1 parent 9050e3d commit 54fab39
Showing 1 changed file with 8 additions and 14 deletions.
Expand Up @@ -480,20 +480,14 @@ private Map<String, Set<Role>> getRolesOf(Set<String> userIds) {
}

private Set<String> scanSet(byte[] key) {
final Set<String> results = new HashSet<>();
final AtomicReference<byte[]> cursor =
new AtomicReference<>(ScanParams.SCAN_POINTER_START_BINARY);
do {
final ScanResult<byte[]> result =
redisClientDelegate.withBinaryClient(
jedis -> {
return jedis.sscan(key, cursor.get());
});
results.addAll(
result.getResult().stream().map(SafeEncoder::encode).collect(Collectors.toList()));
cursor.set(result.getCursorAsBytes());
} while (!Arrays.equals(cursor.get(), ScanParams.SCAN_POINTER_START_BINARY));
return results;
return redisClientDelegate
.withBinaryClient(
jedis -> {
return jedis.smembers(key);
})
.stream()
.map(SafeEncoder::encode)
.collect(Collectors.toSet());
}

private byte[] userKey(String userId, ResourceType r) {
Expand Down

0 comments on commit 54fab39

Please sign in to comment.