Skip to content
Permalink
Browse files
GEODE-10080: Upgrade jedis to 4.1.1 (#165)
  • Loading branch information
ezoerner committed Mar 10, 2022
1 parent a173546 commit 0604473ec335dd2d70ce9045bc1eceecd2a2834f
Showing 7 changed files with 28 additions and 44 deletions.
@@ -16,21 +16,20 @@
package org.apache.geode.benchmark.redis.tasks;

import static java.lang.Thread.currentThread;
import static redis.clients.jedis.BinaryJedisCluster.HASHSLOTS;

import java.net.InetSocketAddress;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import io.vavr.Function3;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import redis.clients.jedis.ConnectionPoolConfig;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.JedisPubSub;

import org.apache.geode.benchmark.redis.tests.PubSubBenchmarkConfiguration;
@@ -72,12 +71,12 @@ public long zrem(final String key, final String value) {
}

@Override
public Set<String> zrange(final String key, final long start, final long stop) {
public List<String> zrange(final String key, final long start, final long stop) {
return jedisCluster.zrange(key, start, stop);
}

@Override
public Set<String> zrangeByScore(final String key, final long start, final long stop) {
public List<String> zrangeByScore(final String key, final long start, final long stop) {
return jedisCluster.zrangeByScore(key, start, stop);
}

@@ -122,15 +121,8 @@ public void publish(final String channel, final String message) {

@Override
public void flushdb() {
final Set<String> seen = new HashSet<>();
for (int i = 0; i < HASHSLOTS; ++i) {
try (final Jedis connectionFromSlot = jedisCluster.getConnectionFromSlot(i)) {
if (seen.add(connectionFromSlot.getClient().getHost())) {
logger.info("Executing flushdb on {}", connectionFromSlot.getClient().getHost());
connectionFromSlot.flushDB();
}
}
}
jedisCluster.getClusterNodes()
.forEach((nodeKey, nodePool) -> new Jedis(nodePool.getResource()).flushDB());
}
};

@@ -141,15 +133,15 @@ public void connect(final Collection<InetSocketAddress> servers) {
final Set<HostAndPort> nodes = servers.stream()
.map(i -> new HostAndPort(i.getHostString(), i.getPort())).collect(Collectors.toSet());

final JedisPoolConfig poolConfig = new JedisPoolConfig();
final ConnectionPoolConfig poolConfig = new ConnectionPoolConfig();
poolConfig.setMaxTotal(-1);
poolConfig.setMaxIdle(-1);
poolConfig.setLifo(false);
final JedisCluster jedisCluster = new JedisCluster(nodes, Integer.MAX_VALUE, poolConfig);

final long start = System.nanoTime();
while (true) {
try (final Jedis jedis = jedisCluster.getConnectionFromSlot(0)) {
try (final Jedis jedis = new Jedis(jedisCluster.getConnectionFromSlot(0))) {
logger.info("Waiting for cluster to come up.");
final String clusterInfo = jedis.clusterInfo();
if (clusterInfo.contains("cluster_state:ok")) {
@@ -19,9 +19,7 @@

import java.net.InetSocketAddress;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import io.lettuce.core.Range;
@@ -83,14 +81,13 @@ public long zrem(String key, String value) {
}

@Override
public Set<String> zrange(String key, long start, long stop) {
return new HashSet<>(redisAdvancedClusterCommands.get().zrange(key, start, stop));
public List<String> zrange(String key, long start, long stop) {
return redisAdvancedClusterCommands.get().zrange(key, start, stop);
}

@Override
public Set<String> zrangeByScore(String key, long start, long stop) {
return new HashSet<>(
redisAdvancedClusterCommands.get().zrangebyscore(key, Range.create(start, stop)));
public List<String> zrangeByScore(String key, long start, long stop) {
return redisAdvancedClusterCommands.get().zrangebyscore(key, Range.create(start, stop));
}

@Override
@@ -19,9 +19,7 @@

import java.net.InetSocketAddress;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import io.lettuce.core.Range;
@@ -84,16 +82,14 @@ public long zrem(String key, String value) {
}

@Override
public Set<String> zrange(String key, long start, long stop) {
return new HashSet<>(
LettucePubSubClientManager.redisClusterCommands.get().zrange(key, start, stop));
public List<String> zrange(String key, long start, long stop) {
return LettucePubSubClientManager.redisClusterCommands.get().zrange(key, start, stop);
}

@Override
public Set<String> zrangeByScore(String key, long start, long stop) {
return new HashSet<>(
LettucePubSubClientManager.redisClusterCommands.get().zrangebyscore(key,
Range.create(start, stop)));
public List<String> zrangeByScore(String key, long start, long stop) {
return LettucePubSubClientManager.redisClusterCommands.get().zrangebyscore(key,
Range.create(start, stop));
}

@Override
@@ -16,7 +16,6 @@
package org.apache.geode.benchmark.redis.tasks;

import java.util.List;
import java.util.Set;

import io.vavr.Function3;

@@ -37,9 +36,9 @@ public interface RedisClient {

long zrem(String key, String value);

Set<String> zrange(String key, long start, long stop);
List<String> zrange(String key, long start, long stop);

Set<String> zrangeByScore(String key, long start, long stop);
List<String> zrangeByScore(String key, long start, long stop);

/**
* Create a subscription listener.
@@ -21,8 +21,8 @@
import static org.assertj.core.api.Assertions.assertThat;

import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.Collectors;
import java.util.stream.LongStream;
@@ -73,16 +73,16 @@ public boolean test(final Map<Object, Object> ctx) throws Exception {
.nextLong(0, RedisSplitKey.NUM_PARTS_PER_KEY - start);
final long stop = start + len;

final Set<String> values = redisClient.zrangeByScore(key, start, stop);
final List<String> values = redisClient.zrangeByScore(key, start, stop);
if (validate) {
final LongRange range =
new LongRange(start, stop);

final Set<String> expectedValues =
final List<String> expectedValues =
LongStream.range(range.getMin(), range.getMax())
.boxed()
.map(keyCache::valueOf)
.collect(Collectors.toSet());
.collect(Collectors.toList());

assertThat(values).isEqualTo(expectedValues);
}
@@ -21,8 +21,8 @@
import static org.assertj.core.api.Assertions.assertThat;

import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.Collectors;
import java.util.stream.LongStream;
@@ -72,16 +72,16 @@ public boolean test(final Map<Object, Object> ctx) throws Exception {
.nextLong(0, RedisSplitKey.NUM_PARTS_PER_KEY - start);
final long stop = start + len;

final Set<String> values = redisClient.zrange(key, start, stop);
final List<String> values = redisClient.zrange(key, start, stop);
if (validate) {
final LongRange range =
new LongRange(start, stop);

final Set<String> expectedValues =
final List<String> expectedValues =
LongStream.range(range.getMin(), range.getMax())
.boxed()
.map(keyCache::valueOf)
.collect(Collectors.toSet());
.collect(Collectors.toList());

assertThat(values).isEqualTo(expectedValues);
}
@@ -27,7 +27,7 @@ sshd-core.version = 2.6.0
assertj-core.version = 3.19.0
software-amazon-awssdk.version = 2.16.60
JSON.version = 20210307
jedis.version = 3.6.0
jedis.version = 4.1.1
lettuce.version = 6.1.1.RELEASE
classgraph.version = 4.8.105
vavr.version = 1.0.0-alpha-4

0 comments on commit 0604473

Please sign in to comment.