Skip to content

DATAREDIS-479 - Upgrade to jedis to 2.8.1. #178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>1.7.0.BUILD-SNAPSHOT</version>
<version>1.7.0.DATAREDIS-479-SNAPSHOT</version>

<name>Spring Data Redis</name>

Expand All @@ -23,7 +23,7 @@
<xstream>1.4.8</xstream>
<pool>2.2</pool>
<lettuce>3.4.2.Final</lettuce>
<jedis>2.8.0</jedis>
<jedis>2.8.1</jedis>
<srp>0.7</srp>
<jredis>06052013</jredis>
<multithreadedtc>1.01</multithreadedtc>
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -74,6 +74,7 @@
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;

/**
Expand Down Expand Up @@ -1532,10 +1533,9 @@ public Cursor<byte[]> sScan(final byte[] key, ScanOptions options) {
@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();
}
Expand Down Expand Up @@ -2158,8 +2158,19 @@ public Long zInterStore(byte[] destKey, Aggregate aggregate, int[] weights, byte
}

@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();
}

/*
Expand Down Expand Up @@ -2387,7 +2398,11 @@ public Cursor<Entry<byte[], byte[]>> hScan(final byte[] key, ScanOptions options

@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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
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;
Expand Down Expand Up @@ -92,6 +91,7 @@
* @author Konstantin Shchepanovskyi
* @author David Liu
* @author Milan Agatonovic
* @author Mark Paluch
*/
public class JedisConnection extends AbstractRedisConnection {

Expand Down Expand Up @@ -3315,7 +3315,7 @@ protected ScanIteration<byte[]> doScan(long cursorId, ScanOptions options) {
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()));
Expand Down Expand Up @@ -3352,7 +3352,7 @@ protected ScanIteration<Tuple> doScan(byte[] key, long cursorId, ScanOptions opt
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
Expand Down Expand Up @@ -3389,7 +3389,7 @@ protected ScanIteration<byte[]> doScan(byte[] key, long cursorId, ScanOptions op
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());
Expand Down Expand Up @@ -3424,27 +3424,14 @@ protected ScanIteration<Entry<byte[], byte[]>> doScan(byte[] key, long cursorId,
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());
}
}.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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
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;
Expand All @@ -51,6 +52,7 @@

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;

Expand Down Expand Up @@ -432,4 +434,26 @@ private static byte[] boundaryToBytes(Boundary boundary, byte[] inclPrefix, byte
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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static org.hamcrest.number.IsCloseTo.*;
import static org.junit.Assert.*;
import static org.springframework.data.redis.connection.ClusterTestVariables.*;
import static org.springframework.data.redis.core.ScanOptions.scanOptions;

import java.io.IOException;
import java.util.Arrays;
Expand Down Expand Up @@ -1769,6 +1770,33 @@ public void zInterStoreShouldWorkForSameSlotKeys() {
public void zInterStoreShouldThrowExceptionWhenKeysDoNotMapToSameSlots() {
clusterConnection.zInterStore(KEY_3_BYTES, KEY_1_BYTES, KEY_2_BYTES);
}


/**
* @see DATAREDIS-479
*/
@Test
public void zScanShouldReadEntireValueRange() {

nativeConnection.zadd(KEY_1_BYTES, 2, VALUE_1_BYTES);
nativeConnection.zadd(KEY_1_BYTES, 1, VALUE_2_BYTES);
nativeConnection.zadd(KEY_1_BYTES, 4, VALUE_3_BYTES);

Cursor<Tuple> tuples = clusterConnection.zScan(KEY_1_BYTES, ScanOptions.NONE);

int count = 0;
while (tuples.hasNext()) {

Tuple tuple = tuples.next();

assertThat(tuple.getValue(), anyOf(equalTo(VALUE_1_BYTES), equalTo(VALUE_2_BYTES), equalTo(VALUE_3_BYTES)));
assertThat(tuple.getScore(), anyOf(equalTo(1D), equalTo(2D), equalTo(4D)));

count++;
}

assertThat(count, equalTo(3));
}

/**
* @see DATAREDIS-315
Expand Down Expand Up @@ -1952,6 +1980,32 @@ public void hGetAllShouldRetrieveEntriesCorrectly() {
assertThat(hGetAll.containsKey(KEY_2_BYTES), is(true));
assertThat(hGetAll.containsKey(KEY_3_BYTES), is(true));
}

/**
* @see DATAREDIS-479
*/
@Test
public void hScanShouldReadEntireValueRange() {

clusterConnection.hSet(KEY_1_BYTES, KEY_1_BYTES, VALUE_1_BYTES);
clusterConnection.hSet(KEY_1_BYTES, KEY_2_BYTES, VALUE_2_BYTES);
clusterConnection.hSet(KEY_1_BYTES, KEY_3_BYTES, VALUE_3_BYTES);

Cursor<Map.Entry<byte[], byte[]>> cursor = clusterConnection
.hScan(KEY_1_BYTES, scanOptions().match("key*").build());

int i = 0;
while (cursor.hasNext()) {

byte[] key = cursor.next().getKey();

assertThat(key, anyOf(equalTo(KEY_1_BYTES), equalTo(KEY_2_BYTES), equalTo(KEY_3_BYTES)));

i++;
}

assertThat(i, is(3));
}

/**
* @see DATAREDIS-315
Expand Down