Java 类org.springframework.data.redis.core.ScanOptions 实例源码

项目:flex-poker    文件:RedisSignUpRepository.java   
@Override
public UUID findSignUpCodeByUsername(String username) {
    String foundSignUpCodeKey = redisTemplate.execute(new RedisCallback<String>() {
        @Override
        public String doInRedis(RedisConnection connection) throws DataAccessException {
            try (Cursor<byte[]> cursor = connection.scan(
                    ScanOptions.scanOptions().match("signup:signupcode*").build())) {
                while (cursor.hasNext()) {
                    String key = new String(cursor.next(), "UTF-8");
                    String usernameFromRedis = (String) redisTemplate.opsForHash().get(key, "username");
                    if (username.equals(usernameFromRedis)) {
                        return key;
                    }
                }
            } catch (IOException e) {
                throw new FlexPokerException("error in Redis");
            }
            throw new FlexPokerException("could not find username in Redis");
        }
    });

    return UUID.fromString(foundSignUpCodeKey.split(":")[2]);
}
项目:redis-admin    文件:DefaultSetOperations.java   
@Override
public Cursor<V> scan(K key, final ScanOptions options) {

    final byte[] rawKey = rawKey(key);
    return execute(new RedisCallback<Cursor<V>>() {

        @Override
        public Cursor<V> doInRedis(RedisConnection connection) throws DataAccessException {
            return new ConvertingCursor<byte[], V>(connection.sScan(rawKey, options), new Converter<byte[], V>() {

                @Override
                public V convert(byte[] source) {
                    return deserializeValue(source);
                }
            });
        }
    }, true);

}
项目:redis-admin    文件:DefaultZSetOperations.java   
@Override
public Cursor<TypedTuple<V>> scan(K key, final ScanOptions options) {

    final byte[] rawKey = rawKey(key);
    Cursor<Tuple> cursor = execute(new RedisCallback<Cursor<Tuple>>() {

        @Override
        public Cursor<Tuple> doInRedis(RedisConnection connection) throws DataAccessException {
            connection.select(dbIndex);
            return connection.zScan(rawKey, options);
        }
    }, true);

    return new ConvertingCursor<Tuple, TypedTuple<V>>(cursor, new Converter<Tuple, TypedTuple<V>>() {

        @Override
        public TypedTuple<V> convert(Tuple source) {
            return deserializeTuple(source);
        }
    });
}
项目:Camel    文件:RedisStringIdempotentRepository.java   
@ManagedOperation(description = "Clear the store")
@Override
public void clear() {
    valueOperations.getOperations().execute(new RedisCallback<List<byte[]>>() {
        @Override
        public List<byte[]> doInRedis(RedisConnection connection) throws DataAccessException {
            List<byte[]> binaryKeys = new ArrayList<>();
            Cursor<byte[]> cursor = connection.scan(ScanOptions.scanOptions().match("*" + createRedisKey("*")).build());

            while (cursor.hasNext()) {
                byte[] key = cursor.next();
                binaryKeys.add(key);
            }
            if (binaryKeys.size() > 0) {
                connection.del(binaryKeys.toArray(new byte[][]{}));
            }
            return binaryKeys;
        }
    });
}
项目:spring-data-examples    文件:KeyOperationsTests.java   
/**
 * Uses {@code SCAN} command for loading all matching keys. <br />
 * {@code SCAN} uses a cursor on server side returning only a subset of the available data with the possibility to
 * ripple load further elements using the cursors position. <br />
 * All keys will be loaded using <strong>multiple</strong> operations.
 */
@Test
public void iterateOverKeysMatchingPrefixUsingScanCommand() {

    generateRandomKeys(1000);

    Cursor<byte[]> cursor = this.connection.scan(ScanOptions.scanOptions().match(KEY_PATTERN).build());
    printKeys(cursor);
}
项目:redis-admin    文件:DefaultHashOperations.java   
@Override
public Cursor<Entry<HK, HV>> scan(K key, final ScanOptions options) {

    final byte[] rawKey = rawKey(key);
    return execute(new RedisCallback<Cursor<Map.Entry<HK, HV>>>() {

        @Override
        public Cursor<Entry<HK, HV>> doInRedis(RedisConnection connection) throws DataAccessException {

            return new ConvertingCursor<Map.Entry<byte[], byte[]>, Map.Entry<HK, HV>>(connection.hScan(rawKey, options),
                    new Converter<Map.Entry<byte[], byte[]>, Map.Entry<HK, HV>>() {

                        @Override
                        public Entry<HK, HV> convert(final Entry<byte[], byte[]> source) {

                            return new Map.Entry<HK, HV>() {

                                @Override
                                public HK getKey() {
                                    return deserializeHashKey(source.getKey());
                                }

                                @Override
                                public HV getValue() {
                                    return deserializeHashValue(source.getValue());
                                }

                                @Override
                                public HV setValue(HV value) {
                                    throw new UnsupportedOperationException("Values cannot be set when scanning through entries.");
                                }
                            };

                        }
                    });
        }

    }, true);

}
项目:parrot-rest    文件:HashOperationsMock.java   
@Override
public Cursor<Entry<Object, Object>> scan(String key, ScanOptions options) {
    throw new UnsupportedOperationException("Unsupported method");
}
项目:tx-lcn    文件:AbstractRedisConnection.java   
@Override
public Cursor<byte[]> scan(ScanOptions options) {
    return redisConnection.scan(options);
}
项目:tx-lcn    文件:AbstractRedisConnection.java   
@Override
public Cursor<byte[]> sScan(byte[] key, ScanOptions options) {
    return redisConnection.sScan(key, options);
}
项目:tx-lcn    文件:AbstractRedisConnection.java   
@Override
public Cursor<Tuple> zScan(byte[] key, ScanOptions options) {
    return redisConnection.zScan(key, options);
}
项目:tx-lcn    文件:AbstractRedisConnection.java   
@Override
public Cursor<Map.Entry<byte[], byte[]>> hScan(byte[] key, ScanOptions options) {
    return redisConnection.hScan(key, options);
}
项目:redis-admin    文件:DefaultBoundSetOperations.java   
@Override
public Cursor<V> scan(ScanOptions options) {
    return ops.scan(getKey(), options);
}
项目:redis-admin    文件:DefaultBoundHashOperations.java   
@Override
public Cursor<Entry<HK, HV>> scan(ScanOptions options) {
    return ops.scan(getKey(), options);
}
项目:redis-admin    文件:DefaultBoundZSetOperations.java   
@Override
public Cursor<TypedTuple<V>> scan(ScanOptions options) {
    return ops.scan(getKey(), options);
}
项目:sctalk    文件:RedisKeys.java   
/**
 * 前缀
 * @param prefix
 * @return
 * @since  1.0
 */
public static ScanOptions getStartOptions(String prefix) {
    return ScanOptions.scanOptions().match("^" + prefix + ".*").build();
}
项目:sctalk    文件:RedisKeys.java   
/**
 * 后缀
 * @param suffix
 * @return
 * @since  1.0
 */
public static ScanOptions getEndOptions(String suffix) {
    return ScanOptions.scanOptions().match(".*" + suffix + "$").build();
}