org.springframework.data.redis.core.ConvertingCursor Java Examples
The following examples show how to use
org.springframework.data.redis.core.ConvertingCursor.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RedisUtils.java From ad with Apache License 2.0 | 8 votes |
public static Set<String> scan(RedisTemplate<String, ?> redisTemplate, String pattern, int count) { ScanOptions scanOptions; if (count > -1) { scanOptions = ScanOptions.scanOptions().match(pattern).count(count).build(); } else { scanOptions = ScanOptions.scanOptions().match(pattern).build(); } ConvertingCursor<byte[], String> cursor = redisTemplate.executeWithStickyConnection((redisConnection) -> new ConvertingCursor<>(redisConnection.scan(scanOptions), new StringRedisSerializer()::deserialize) ); if (cursor != null) { Set<String> set = Sets.newHashSet(); cursor.forEachRemaining(set::add); return set; } return Collections.emptySet(); }
Example #2
Source File: DefaultSetOperations.java From redis-admin with Apache License 2.0 | 6 votes |
@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); }
Example #3
Source File: DefaultZSetOperations.java From redis-admin with Apache License 2.0 | 6 votes |
@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); } }); }
Example #4
Source File: DefaultHashOperations.java From redis-admin with Apache License 2.0 | 5 votes |
@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); }