Search in sources :

Example 1 with ScanOptions

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();
    }
}
Also used : RedisClusterConnection(org.springframework.data.redis.connection.RedisClusterConnection) UpdatedRegistration(org.eclipse.leshan.server.registration.UpdatedRegistration) Registration(org.eclipse.leshan.server.registration.Registration) ArrayList(java.util.ArrayList) ScanOptions(org.springframework.data.redis.core.ScanOptions) Cursor(org.springframework.data.redis.core.Cursor) LinkedList(java.util.LinkedList)

Example 2 with ScanOptions

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;
    }
}
Also used : RedisClusterConnection(org.springframework.data.redis.connection.RedisClusterConnection) ArrayList(java.util.ArrayList) ScanOptions(org.springframework.data.redis.core.ScanOptions) Cursor(org.springframework.data.redis.core.Cursor) LwM2mClient(org.thingsboard.server.transport.lwm2m.server.client.LwM2mClient) HashSet(java.util.HashSet)

Example 3 with ScanOptions

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();
}
Also used : lombok.val(lombok.val) IOUtils(org.apache.commons.io.IOUtils) Stream(java.util.stream.Stream) ScanOptions(org.springframework.data.redis.core.ScanOptions) Spliterators(java.util.Spliterators) RedisTemplate(org.springframework.data.redis.core.RedisTemplate) lombok.val(lombok.val) StreamSupport(java.util.stream.StreamSupport) Spliterator(java.util.Spliterator)

Example 4 with ScanOptions

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;
    }
}
Also used : RedisClusterConnection(org.springframework.data.redis.connection.RedisClusterConnection) ArrayList(java.util.ArrayList) ScanOptions(org.springframework.data.redis.core.ScanOptions) Cursor(org.springframework.data.redis.core.Cursor) LwM2MModelConfig(org.thingsboard.server.transport.lwm2m.server.model.LwM2MModelConfig)

Aggregations

ScanOptions (org.springframework.data.redis.core.ScanOptions)4 ArrayList (java.util.ArrayList)3 RedisClusterConnection (org.springframework.data.redis.connection.RedisClusterConnection)3 Cursor (org.springframework.data.redis.core.Cursor)3 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 Spliterator (java.util.Spliterator)1 Spliterators (java.util.Spliterators)1 Stream (java.util.stream.Stream)1 StreamSupport (java.util.stream.StreamSupport)1 lombok.val (lombok.val)1 IOUtils (org.apache.commons.io.IOUtils)1 Registration (org.eclipse.leshan.server.registration.Registration)1 UpdatedRegistration (org.eclipse.leshan.server.registration.UpdatedRegistration)1 RedisTemplate (org.springframework.data.redis.core.RedisTemplate)1 LwM2mClient (org.thingsboard.server.transport.lwm2m.server.client.LwM2mClient)1 LwM2MModelConfig (org.thingsboard.server.transport.lwm2m.server.model.LwM2MModelConfig)1