DATAREDIS-479 - Upgrade to jedis to 2.8.1.
Update jedis driver to 2.8.1. Use binary method for SSCAN and implement ZSCAN and HSCAN methods. Move ScanOptions to ScanParams conversion to JedisConverters. Original Pull Request: #178
This commit is contained in:
committed by
Christoph Strobl
parent
069954ee7a
commit
77de777da8
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015 the original author or authors.
|
||||
* Copyright 2015-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -74,6 +74,7 @@ import redis.clients.jedis.BinaryJedisPubSub;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisCluster;
|
||||
import redis.clients.jedis.JedisPool;
|
||||
import redis.clients.jedis.ScanParams;
|
||||
import redis.clients.jedis.ZParams;
|
||||
|
||||
/**
|
||||
@@ -1532,10 +1533,9 @@ public class JedisClusterConnection implements RedisClusterConnection {
|
||||
@Override
|
||||
protected ScanIteration<byte[]> doScan(long cursorId, ScanOptions options) {
|
||||
|
||||
redis.clients.jedis.ScanResult<String> result = cluster.sscan(JedisConverters.toString(key),
|
||||
Long.toString(cursorId));
|
||||
return new ScanIteration<byte[]>(Long.valueOf(result.getCursor()),
|
||||
JedisConverters.stringListToByteList().convert(result.getResult()));
|
||||
ScanParams params = JedisConverters.toScanParams(options);
|
||||
redis.clients.jedis.ScanResult<byte[]> result = cluster.sscan(key, JedisConverters.toBytes(cursorId), params);
|
||||
return new ScanIteration<byte[]>(Long.valueOf(result.getStringCursor()), result.getResult());
|
||||
}
|
||||
}.open();
|
||||
}
|
||||
@@ -2158,8 +2158,19 @@ public class JedisClusterConnection implements RedisClusterConnection {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cursor<Tuple> zScan(byte[] key, ScanOptions options) {
|
||||
throw new UnsupportedOperationException("Jedis does currently not support binary zscan command.");
|
||||
public Cursor<Tuple> zScan(final byte[] key, final ScanOptions options) {
|
||||
return new ScanCursor<Tuple>(options) {
|
||||
|
||||
@Override
|
||||
protected ScanIteration<Tuple> doScan(long cursorId, ScanOptions options) {
|
||||
|
||||
ScanParams params = JedisConverters.toScanParams(options);
|
||||
|
||||
redis.clients.jedis.ScanResult<redis.clients.jedis.Tuple> result = cluster.zscan(key, JedisConverters.toBytes(cursorId), params);
|
||||
return new ScanIteration<Tuple>(Long.valueOf(result.getStringCursor()), JedisConverters
|
||||
.tuplesToTuples().convert(result.getResult()));
|
||||
}
|
||||
}.open();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2387,7 +2398,11 @@ public class JedisClusterConnection implements RedisClusterConnection {
|
||||
|
||||
@Override
|
||||
protected ScanIteration<Entry<byte[], byte[]>> doScan(long cursorId, ScanOptions options) {
|
||||
throw new UnsupportedOperationException("Jedis does currently not support binary hscan");
|
||||
|
||||
ScanParams params = JedisConverters.toScanParams(options);
|
||||
|
||||
redis.clients.jedis.ScanResult<Map.Entry<byte[], byte[]>> result = cluster.hscan(key, JedisConverters.toBytes(cursorId), params);
|
||||
return new ScanIteration<Map.Entry<byte[], byte[]>>(Long.valueOf(result.getStringCursor()), result.getResult());
|
||||
}
|
||||
}.open();
|
||||
}
|
||||
|
||||
@@ -60,7 +60,6 @@ import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import redis.clients.jedis.BinaryJedis;
|
||||
import redis.clients.jedis.BinaryJedisPubSub;
|
||||
@@ -92,6 +91,7 @@ import redis.clients.util.Pool;
|
||||
* @author Konstantin Shchepanovskyi
|
||||
* @author David Liu
|
||||
* @author Milan Agatonovic
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class JedisConnection extends AbstractRedisConnection {
|
||||
|
||||
@@ -3315,7 +3315,7 @@ public class JedisConnection extends AbstractRedisConnection {
|
||||
throw new UnsupportedOperationException("'SCAN' cannot be called in pipeline / transaction mode.");
|
||||
}
|
||||
|
||||
ScanParams params = prepareScanParams(options);
|
||||
ScanParams params = JedisConverters.toScanParams(options);
|
||||
redis.clients.jedis.ScanResult<String> result = jedis.scan(Long.toString(cursorId), params);
|
||||
return new ScanIteration<byte[]>(Long.valueOf(result.getStringCursor()), JedisConverters.stringListToByteList()
|
||||
.convert(result.getResult()));
|
||||
@@ -3352,7 +3352,7 @@ public class JedisConnection extends AbstractRedisConnection {
|
||||
throw new UnsupportedOperationException("'ZSCAN' cannot be called in pipeline / transaction mode.");
|
||||
}
|
||||
|
||||
ScanParams params = prepareScanParams(options);
|
||||
ScanParams params = JedisConverters.toScanParams(options);
|
||||
|
||||
ScanResult<redis.clients.jedis.Tuple> result = jedis.zscan(key, JedisConverters.toBytes(cursorId), params);
|
||||
return new ScanIteration<RedisZSetCommands.Tuple>(Long.valueOf(result.getStringCursor()), JedisConverters
|
||||
@@ -3389,7 +3389,7 @@ public class JedisConnection extends AbstractRedisConnection {
|
||||
throw new UnsupportedOperationException("'SSCAN' cannot be called in pipeline / transaction mode.");
|
||||
}
|
||||
|
||||
ScanParams params = prepareScanParams(options);
|
||||
ScanParams params = JedisConverters.toScanParams(options);
|
||||
|
||||
redis.clients.jedis.ScanResult<byte[]> result = jedis.sscan(key, JedisConverters.toBytes(cursorId), params);
|
||||
return new ScanIteration<byte[]>(Long.valueOf(result.getStringCursor()), result.getResult());
|
||||
@@ -3424,7 +3424,7 @@ public class JedisConnection extends AbstractRedisConnection {
|
||||
throw new UnsupportedOperationException("'HSCAN' cannot be called in pipeline / transaction mode.");
|
||||
}
|
||||
|
||||
ScanParams params = prepareScanParams(options);
|
||||
ScanParams params = JedisConverters.toScanParams(options);
|
||||
|
||||
ScanResult<Entry<byte[], byte[]>> result = jedis.hscan(key, JedisConverters.toBytes(cursorId), params);
|
||||
return new ScanIteration<Map.Entry<byte[], byte[]>>(Long.valueOf(result.getStringCursor()), result.getResult());
|
||||
@@ -3432,19 +3432,6 @@ public class JedisConnection extends AbstractRedisConnection {
|
||||
}.open();
|
||||
}
|
||||
|
||||
private ScanParams prepareScanParams(ScanOptions options) {
|
||||
ScanParams sp = new ScanParams();
|
||||
if (!options.equals(ScanOptions.NONE)) {
|
||||
if (options.getCount() != null) {
|
||||
sp.count(options.getCount().intValue());
|
||||
}
|
||||
if (StringUtils.hasText(options.getPattern())) {
|
||||
sp.match(options.getPattern());
|
||||
}
|
||||
}
|
||||
return sp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies if pipelined results should be converted to the expected data type. If false, results of
|
||||
* {@link #closePipeline()} and {@link #exec()} will be of the type returned by the Jedis driver
|
||||
|
||||
@@ -42,6 +42,7 @@ import org.springframework.data.redis.connection.convert.ListConverter;
|
||||
import org.springframework.data.redis.connection.convert.MapConverter;
|
||||
import org.springframework.data.redis.connection.convert.SetConverter;
|
||||
import org.springframework.data.redis.connection.convert.StringToRedisClientInfoConverter;
|
||||
import org.springframework.data.redis.core.ScanOptions;
|
||||
import org.springframework.data.redis.core.types.Expiration;
|
||||
import org.springframework.data.redis.core.types.RedisClientInfo;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -51,6 +52,7 @@ import org.springframework.util.StringUtils;
|
||||
|
||||
import redis.clients.jedis.BinaryClient.LIST_POSITION;
|
||||
import redis.clients.jedis.BitOP;
|
||||
import redis.clients.jedis.ScanParams;
|
||||
import redis.clients.jedis.SortingParams;
|
||||
import redis.clients.util.SafeEncoder;
|
||||
|
||||
@@ -432,4 +434,26 @@ abstract public class JedisConverters extends Converters {
|
||||
return buffer.array();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert {@link ScanOptions} to Jedis {@link ScanParams}.
|
||||
*
|
||||
* @param options
|
||||
* @return
|
||||
*/
|
||||
public static ScanParams toScanParams(ScanOptions options) {
|
||||
|
||||
ScanParams sp = new ScanParams();
|
||||
|
||||
if (!options.equals(ScanOptions.NONE)) {
|
||||
if (options.getCount() != null) {
|
||||
sp.count(options.getCount().intValue());
|
||||
}
|
||||
if (StringUtils.hasText(options.getPattern())) {
|
||||
sp.match(options.getPattern());
|
||||
}
|
||||
}
|
||||
return sp;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user