use of org.springframework.data.redis.core.ScanOptions in project thingsboard by thingsboard.
the class TbLwM2mRedisRegistrationStore method getAllRegistrations.
@Override
public Iterator<Registration> getAllRegistrations() {
try (var connection = connectionFactory.getConnection()) {
Collection<Registration> list = new LinkedList<>();
ScanOptions scanOptions = ScanOptions.scanOptions().count(100).match(REG_EP + "*").build();
List<Cursor<byte[]>> scans = new ArrayList<>();
if (connection instanceof RedisClusterConnection) {
((RedisClusterConnection) connection).clusterGetNodes().forEach(node -> {
scans.add(((RedisClusterConnection) connection).scan(node, scanOptions));
});
} else {
scans.add(connection.scan(scanOptions));
}
scans.forEach(scan -> {
scan.forEachRemaining(key -> {
byte[] element = connection.get(key);
list.add(deserializeReg(element));
});
});
return list.iterator();
}
}
use of org.springframework.data.redis.core.ScanOptions in project thingsboard by thingsboard.
the class TbRedisLwM2MClientStore method getAll.
@Override
public Set<LwM2mClient> getAll() {
try (var connection = connectionFactory.getConnection()) {
Set<LwM2mClient> clients = new HashSet<>();
ScanOptions scanOptions = ScanOptions.scanOptions().count(100).match(CLIENT_EP + "*").build();
List<Cursor<byte[]>> scans = new ArrayList<>();
if (connection instanceof RedisClusterConnection) {
((RedisClusterConnection) connection).clusterGetNodes().forEach(node -> {
scans.add(((RedisClusterConnection) connection).scan(node, scanOptions));
});
} else {
scans.add(connection.scan(scanOptions));
}
scans.forEach(scan -> {
scan.forEachRemaining(key -> {
byte[] element = connection.get(key);
clients.add(deserialize(element));
});
});
return clients;
}
}
use of org.springframework.data.redis.core.ScanOptions in project cas by apereo.
the class DefaultCasRedisTemplate method keys.
@Override
public Stream<String> keys(final String pattern, final long count) {
var scanOptions = ScanOptions.scanOptions().match(pattern);
if (count > 0) {
scanOptions = scanOptions.count(count);
}
val cursor = getConnectionFactory().getConnection().scan(scanOptions.build());
return StreamSupport.stream(Spliterators.spliteratorUnknownSize(cursor, Spliterator.ORDERED), false).onClose(() -> IOUtils.closeQuietly(cursor)).map(key -> (String) getKeySerializer().deserialize(key)).distinct();
}
use of org.springframework.data.redis.core.ScanOptions in project thingsboard by thingsboard.
the class TbRedisLwM2MModelConfigStore method getAll.
@Override
public List<LwM2MModelConfig> getAll() {
try (var connection = connectionFactory.getConnection()) {
List<LwM2MModelConfig> configs = new ArrayList<>();
ScanOptions scanOptions = ScanOptions.scanOptions().count(100).match(MODEL_EP + "*").build();
List<Cursor<byte[]>> scans = new ArrayList<>();
if (connection instanceof RedisClusterConnection) {
((RedisClusterConnection) connection).clusterGetNodes().forEach(node -> {
scans.add(((RedisClusterConnection) connection).scan(node, scanOptions));
});
} else {
scans.add(connection.scan(scanOptions));
}
scans.forEach(scan -> {
scan.forEachRemaining(key -> {
byte[] element = connection.get(key);
configs.add(JacksonUtil.fromBytes(element, LwM2MModelConfig.class));
});
});
return configs;
}
}
Aggregations