From 9ad7f8091f0c8c83212b4bad2e914d73782e8b3c Mon Sep 17 00:00:00 2001 From: Christoph Dreis Date: Mon, 16 Aug 2021 11:12:03 +0200 Subject: [PATCH] Support Spring-Boot 2.5.x --- .../contrib/redis/common/RedisCommand.java | 3 + opentracing-redis-spring-data2/pom.xml | 6 +- ...TracingReactiveRedisClusterConnection.java | 90 +++++++++++++++++ .../TracingRedisClusterConnection.java | 12 +++ .../connection/TracingRedisConnection.java | 99 +++++++++++++++++++ .../TracingRedisClusterConnectionTest.java | 15 +++ 6 files changed, 222 insertions(+), 3 deletions(-) diff --git a/opentracing-redis-common/src/main/java/io/opentracing/contrib/redis/common/RedisCommand.java b/opentracing-redis-common/src/main/java/io/opentracing/contrib/redis/common/RedisCommand.java index 860c278..afca505 100644 --- a/opentracing-redis-common/src/main/java/io/opentracing/contrib/redis/common/RedisCommand.java +++ b/opentracing-redis-common/src/main/java/io/opentracing/contrib/redis/common/RedisCommand.java @@ -125,6 +125,7 @@ public final class RedisCommand { public static final String LINSERT = "LINSERT"; public static final String LLEN = "LLEN"; public static final String LPOP = "LPOP"; + public static final String LPOS = "LPOS"; public static final String LPUSH = "LPUSH"; public static final String LPUSHX = "LPUSHX"; public static final String LRANGE = "LRANGE"; @@ -247,6 +248,8 @@ public final class RedisCommand { public static final String HSCAN = "HSCAN"; public static final String ZSCAN = "ZSCAN"; public static final String XADD = "XADD"; + public static final String XCLAIM = "XCLAIM"; + public static final String XINFO = "XINFO"; public static final String XRANGE = "XRANGE"; public static final String XREVRANGE = "XREVRANGE"; public static final String XLEN = "XLEN"; diff --git a/opentracing-redis-spring-data2/pom.xml b/opentracing-redis-spring-data2/pom.xml index b242d2d..d51fc61 100644 --- a/opentracing-redis-spring-data2/pom.xml +++ b/opentracing-redis-spring-data2/pom.xml @@ -27,9 +27,9 @@ OpenTracing Instrumentation for Spring Redis classes - 2.2.4.RELEASE - 2.2.4.RELEASE - 5.2.3.RELEASE + 2.5.4 + 2.5.3 + 5.3.9 diff --git a/opentracing-redis-spring-data2/src/main/java/io/opentracing/contrib/redis/spring/data2/connection/TracingReactiveRedisClusterConnection.java b/opentracing-redis-spring-data2/src/main/java/io/opentracing/contrib/redis/spring/data2/connection/TracingReactiveRedisClusterConnection.java index d24f40e..1439352 100644 --- a/opentracing-redis-spring-data2/src/main/java/io/opentracing/contrib/redis/spring/data2/connection/TracingReactiveRedisClusterConnection.java +++ b/opentracing-redis-spring-data2/src/main/java/io/opentracing/contrib/redis/spring/data2/connection/TracingReactiveRedisClusterConnection.java @@ -16,6 +16,10 @@ import io.opentracing.contrib.redis.common.RedisCommand; import io.opentracing.contrib.redis.common.TracingConfiguration; import io.opentracing.contrib.redis.common.TracingHelper; +import java.nio.ByteBuffer; +import java.util.Collection; +import java.util.Map; +import org.springframework.data.redis.connection.ClusterInfo; import org.springframework.data.redis.connection.ReactiveClusterGeoCommands; import org.springframework.data.redis.connection.ReactiveClusterHashCommands; import org.springframework.data.redis.connection.ReactiveClusterHyperLogLogCommands; @@ -31,6 +35,7 @@ import org.springframework.data.redis.connection.ReactiveRedisClusterConnection; import org.springframework.data.redis.connection.ReactiveScriptingCommands; import org.springframework.data.redis.connection.RedisClusterNode; +import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; public class TracingReactiveRedisClusterConnection implements ReactiveRedisClusterConnection { @@ -129,4 +134,89 @@ public ReactiveScriptingCommands scriptingCommands() { public Mono ping() { return helper.doInScope(RedisCommand.PING, () -> reactiveRedisClusterConnection.ping()); } + + @Override + public Flux clusterGetNodes() { + return reactiveRedisClusterConnection.clusterGetNodes(); + } + + @Override + public Flux clusterGetSlaves(RedisClusterNode master) { + return reactiveRedisClusterConnection.clusterGetSlaves(master); + } + + @Override + public Mono>> clusterGetMasterSlaveMap() { + return reactiveRedisClusterConnection.clusterGetMasterSlaveMap(); + } + + @Override + public Mono clusterGetSlotForKey(ByteBuffer key) { + return reactiveRedisClusterConnection.clusterGetSlotForKey(key); + } + + @Override + public Mono clusterGetNodeForSlot(int slot) { + return reactiveRedisClusterConnection.clusterGetNodeForSlot(slot); + } + + @Override + public Mono clusterGetNodeForKey(ByteBuffer key) { + return reactiveRedisClusterConnection.clusterGetNodeForKey(key); + } + + @Override + public Mono clusterGetClusterInfo() { + return reactiveRedisClusterConnection.clusterGetClusterInfo(); + } + + @Override + public Mono clusterAddSlots(RedisClusterNode node, int... slots) { + return reactiveRedisClusterConnection.clusterAddSlots(node, slots); + } + + @Override + public Mono clusterAddSlots(RedisClusterNode node, RedisClusterNode.SlotRange range) { + return reactiveRedisClusterConnection.clusterAddSlots(node, range); + } + + @Override + public Mono clusterCountKeysInSlot(int slot) { + return reactiveRedisClusterConnection.clusterCountKeysInSlot(slot); + } + + @Override + public Mono clusterDeleteSlots(RedisClusterNode node, int... slots) { + return reactiveRedisClusterConnection.clusterDeleteSlots(node, slots); + } + + @Override + public Mono clusterDeleteSlotsInRange(RedisClusterNode node, RedisClusterNode.SlotRange range) { + return reactiveRedisClusterConnection.clusterDeleteSlotsInRange(node, range); + } + + @Override + public Mono clusterForget(RedisClusterNode node) { + return reactiveRedisClusterConnection.clusterForget(node); + } + + @Override + public Mono clusterMeet(RedisClusterNode node) { + return reactiveRedisClusterConnection.clusterMeet(node); + } + + @Override + public Mono clusterSetSlot(RedisClusterNode node, int slot, AddSlots mode) { + return reactiveRedisClusterConnection.clusterSetSlot(node, slot, mode); + } + + @Override + public Flux clusterGetKeysInSlot(int slot, int count) { + return reactiveRedisClusterConnection.clusterGetKeysInSlot(slot, count); + } + + @Override + public Mono clusterReplicate(RedisClusterNode master, RedisClusterNode replica) { + return reactiveRedisClusterConnection.clusterReplicate(master, replica); + } } diff --git a/opentracing-redis-spring-data2/src/main/java/io/opentracing/contrib/redis/spring/data2/connection/TracingRedisClusterConnection.java b/opentracing-redis-spring-data2/src/main/java/io/opentracing/contrib/redis/spring/data2/connection/TracingRedisClusterConnection.java index 1076704..c18c14a 100644 --- a/opentracing-redis-spring-data2/src/main/java/io/opentracing/contrib/redis/spring/data2/connection/TracingRedisClusterConnection.java +++ b/opentracing-redis-spring-data2/src/main/java/io/opentracing/contrib/redis/spring/data2/connection/TracingRedisClusterConnection.java @@ -33,6 +33,7 @@ import static io.opentracing.contrib.redis.common.RedisCommand.CLUSTER_SLAVES; import static io.opentracing.contrib.redis.common.RedisCommand.CONFIG_GET; import static io.opentracing.contrib.redis.common.RedisCommand.CONFIG_RESETSTAT; +import static io.opentracing.contrib.redis.common.RedisCommand.CONFIG_REWRITE; import static io.opentracing.contrib.redis.common.RedisCommand.CONFIG_SET; import static io.opentracing.contrib.redis.common.RedisCommand.DBSIZE; import static io.opentracing.contrib.redis.common.RedisCommand.EXECUTE; @@ -55,6 +56,7 @@ import java.util.Map; import java.util.Properties; import java.util.Set; +import java.util.concurrent.TimeUnit; import org.springframework.data.redis.connection.ClusterInfo; import org.springframework.data.redis.connection.RedisClusterConnection; import org.springframework.data.redis.connection.RedisClusterNode; @@ -264,11 +266,21 @@ public void resetConfigStats(RedisClusterNode node) { helper.doInScope(CONFIG_RESETSTAT, () -> connection.resetConfigStats(node)); } + @Override + public void rewriteConfig(RedisClusterNode node) { + helper.doInScope(CONFIG_REWRITE, () -> connection.rewriteConfig(node)); + } + @Override public Long time(RedisClusterNode node) { return helper.doInScope(TIME, () -> connection.time(node)); } + @Override + public Long time(RedisClusterNode node, TimeUnit timeUnit) { + return helper.doInScope(TIME, () -> connection.time(node, timeUnit)); + } + @Override public List getClientList(RedisClusterNode node) { return helper.doInScope(CLIENT_LIST, () -> connection.getClientList(node)); diff --git a/opentracing-redis-spring-data2/src/main/java/io/opentracing/contrib/redis/spring/data2/connection/TracingRedisConnection.java b/opentracing-redis-spring-data2/src/main/java/io/opentracing/contrib/redis/spring/data2/connection/TracingRedisConnection.java index d993dc0..9137660 100644 --- a/opentracing-redis-spring-data2/src/main/java/io/opentracing/contrib/redis/spring/data2/connection/TracingRedisConnection.java +++ b/opentracing-redis-spring-data2/src/main/java/io/opentracing/contrib/redis/spring/data2/connection/TracingRedisConnection.java @@ -53,8 +53,11 @@ import org.springframework.data.redis.connection.stream.ByteRecord; import org.springframework.data.redis.connection.stream.Consumer; import org.springframework.data.redis.connection.stream.MapRecord; +import org.springframework.data.redis.connection.stream.PendingMessages; +import org.springframework.data.redis.connection.stream.PendingMessagesSummary; import org.springframework.data.redis.connection.stream.ReadOffset; import org.springframework.data.redis.connection.stream.RecordId; +import org.springframework.data.redis.connection.stream.StreamInfo; import org.springframework.data.redis.connection.stream.StreamOffset; import org.springframework.data.redis.connection.stream.StreamReadOptions; import org.springframework.data.redis.core.Cursor; @@ -473,6 +476,11 @@ public Long rPush(byte[] key, byte[]... values) { return helper.doInScope(RedisCommand.RPUSH, key, () -> connection.rPush(key, values)); } + @Override + public List lPos(byte[] key, byte[] element, Integer rank, Integer count) { + return helper.doInScope(RedisCommand.LPOS, key, () -> connection.lPos(key, element, rank, count)); + } + @Override public Long lPush(byte[] key, byte[]... values) { return helper.doInScope(RedisCommand.LPUSH, key, () -> connection.lPush(key, values)); @@ -651,11 +659,21 @@ public Boolean zAdd(byte[] key, double score, byte[] value) { return helper.doInScope(RedisCommand.ZADD, key, () -> connection.zAdd(key, score, value)); } + @Override + public Boolean zAdd(byte[] key, double score, byte[] value, ZAddArgs args) { + return helper.doInScope(RedisCommand.ZADD, key, () -> connection.zAdd(key, score, value, args)); + } + @Override public Long zAdd(byte[] key, Set tuples) { return helper.doInScope(RedisCommand.ZADD, key, () -> connection.zAdd(key, tuples)); } + @Override + public Long zAdd(byte[] key, Set tuples, ZAddArgs args) { + return helper.doInScope(RedisCommand.ZADD, key, () -> connection.zAdd(key, tuples, args)); + } + @Override public Long zRem(byte[] key, byte[]... values) { return helper.doInScope(RedisCommand.ZREM, key, () -> connection.zRem(key, values)); @@ -820,6 +838,11 @@ public Long zCount(byte[] key, Range range) { return helper.doInScope(RedisCommand.ZCOUNT, key, () -> connection.zCount(key, range)); } + @Override + public Long zLexCount(byte[] key, Range range) { + return helper.doInScope(RedisCommand.ZLEXCOUNT, key, () -> connection.zLexCount(key, range)); + } + @Override public Long zCard(byte[] key) { return helper.doInScope(RedisCommand.ZCARD, key, () -> connection.zCard(key)); @@ -836,6 +859,12 @@ public Long zRemRange(byte[] key, long start, long end) { .doInScope(RedisCommand.ZREMRANGE, key, () -> connection.zRemRange(key, start, end)); } + @Override + public Long zRemRangeByLex(byte[] key, Range range) { + return helper + .doInScope(RedisCommand.ZREMRANGEBYLEX, key, () -> connection.zRemRangeByLex(key, range)); + } + @Override public Long zRemRangeByScore(byte[] key, double min, double max) { return helper.doInScope(RedisCommand.ZREMRANGEBYSCORE, @@ -905,6 +934,12 @@ public Set zRangeByLex(byte[] key, Range range, Limit limit) { .doInScope(RedisCommand.ZRANGEBYLEX, key, () -> connection.zRangeByLex(key, range, limit)); } + @Override + public Set zRevRangeByLex(byte[] key, Range range, Limit limit) { + return helper.doInScope(RedisCommand.ZREVRANGEBYLEX, key, + () -> connection.zRevRangeByLex(key, range, limit)); + } + @Override public Boolean hSet(byte[] key, byte[] field, byte[] value) { return helper.doInScope(RedisCommand.HSET, key, () -> connection.hSet(key, field, value)); @@ -1110,11 +1145,21 @@ public void resetConfigStats() { helper.doInScope(RedisCommand.CONFIG_RESETSTAT, () -> connection.resetConfigStats()); } + @Override + public void rewriteConfig() { + helper.doInScope(RedisCommand.CONFIG_REWRITE, () -> connection.rewriteConfig()); + } + @Override public Long time() { return helper.doInScope(RedisCommand.TIME, () -> connection.time()); } + @Override + public Long time(TimeUnit timeUnit) { + return helper.doInScope(RedisCommand.TIME, () -> connection.time(timeUnit)); + } + @Override public void killClient(String host, int port) { helper.doInScope(RedisCommand.CLIENT_KILL, () -> connection.killClient(host, port)); @@ -1305,6 +1350,23 @@ public RecordId xAdd(MapRecord record) { return helper.doInScope(RedisCommand.XADD, () -> connection.xAdd(record)); } + @Override + public RecordId xAdd(MapRecord record, XAddOptions xAddOptions) { + return helper.doInScope(RedisCommand.XADD, () -> connection.xAdd(record, xAddOptions)); + } + + @Override + public List xClaimJustId(byte[] key, String group, String newOwner, XClaimOptions options) { + return helper.doInScope(RedisCommand.XCLAIM, key, + () -> connection.xClaimJustId(key, group, newOwner, options)); + } + + @Override + public List xClaim(byte[] key, String group, String newOwner, XClaimOptions options) { + return helper.doInScope(RedisCommand.XCLAIM, key, + () -> connection.xClaim(key, group, newOwner, options)); + } + @Override public Long xDel(byte[] key, RecordId... recordIds) { return helper.doInScope(RedisCommand.XDEL, () -> connection.xDel(key, recordIds)); @@ -1316,6 +1378,12 @@ public String xGroupCreate(byte[] key, String groupName, ReadOffset readOffset) () -> connection.xGroupCreate(key, groupName, readOffset)); } + @Override + public String xGroupCreate(byte[] key, String groupName, ReadOffset readOffset, boolean mkStream) { + return helper.doInScope(RedisCommand.XGROUPCREATE, + () -> connection.xGroupCreate(key, groupName, readOffset)); + } + @Override public Boolean xGroupDelConsumer(byte[] key, Consumer consumer) { return helper.doInScope(RedisCommand.XGROUPDELCONSUMER, @@ -1328,11 +1396,36 @@ public Boolean xGroupDestroy(byte[] key, String groupName) { .doInScope(RedisCommand.XGROUPDESTROY, () -> connection.xGroupDestroy(key, groupName)); } + @Override + public StreamInfo.XInfoStream xInfo(byte[] key) { + return helper.doInScope(RedisCommand.XINFO, () -> connection.xInfo(key)); + } + + @Override + public StreamInfo.XInfoGroups xInfoGroups(byte[] key) { + return helper.doInScope(RedisCommand.XINFO, () -> connection.xInfoGroups(key)); + } + + @Override + public StreamInfo.XInfoConsumers xInfoConsumers(byte[] key, String groupName) { + return helper.doInScope(RedisCommand.XINFO, () -> connection.xInfoConsumers(key, groupName)); + } + @Override public Long xLen(byte[] key) { return helper.doInScope(RedisCommand.XLEN, () -> connection.xLen(key)); } + @Override + public PendingMessagesSummary xPending(byte[] key, String groupName) { + return helper.doInScope(RedisCommand.XPENDING, () -> connection.xPending(key, groupName)); + } + + @Override + public PendingMessages xPending(byte[] key, String groupName, XPendingOptions options) { + return helper.doInScope(RedisCommand.XPENDING, () -> connection.xPending(key, groupName, options)); + } + @Override public List xRange(byte[] key, org.springframework.data.domain.Range range, Limit limit) { @@ -1361,4 +1454,10 @@ public List xRevRange(byte[] key, org.springframework.data.domain.Ra public Long xTrim(byte[] key, long count) { return helper.doInScope(RedisCommand.XTRIM, () -> connection.xTrim(key, count)); } + + @Override + public Long xTrim(byte[] key, long count, boolean approximateTrimming) { + return helper.doInScope(RedisCommand.XTRIM, () -> connection.xTrim(key, count, approximateTrimming)); + } + } diff --git a/opentracing-redis-spring-data2/src/test/java/io/opentracing/contrib/redis/spring/data2/connection/TracingRedisClusterConnectionTest.java b/opentracing-redis-spring-data2/src/test/java/io/opentracing/contrib/redis/spring/data2/connection/TracingRedisClusterConnectionTest.java index 6fa0929..4b68bc4 100644 --- a/opentracing-redis-spring-data2/src/test/java/io/opentracing/contrib/redis/spring/data2/connection/TracingRedisClusterConnectionTest.java +++ b/opentracing-redis-spring-data2/src/test/java/io/opentracing/contrib/redis/spring/data2/connection/TracingRedisClusterConnectionTest.java @@ -19,6 +19,7 @@ import io.opentracing.contrib.redis.common.RedisCommand; import io.opentracing.mock.MockTracer; +import java.util.concurrent.TimeUnit; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -303,12 +304,26 @@ public void invokingResetConfigStats() { verify(mockRedisConnection()).resetConfigStats(mockRedisClusterNode); } + @Test + public void invokingRewriteConfigStats() { + commandCreatesNewSpan(RedisCommand.CONFIG_REWRITE, + () -> getConnection().rewriteConfig(mockRedisClusterNode)); + verify(mockRedisConnection()).rewriteConfig(mockRedisClusterNode); + } + @Test public void invokingTime() { commandCreatesNewSpan(RedisCommand.TIME, () -> getConnection().time(mockRedisClusterNode)); verify(mockRedisConnection()).time(mockRedisClusterNode); } + @Test + public void invokingTimeWithTimeUnit() { + TimeUnit timeUnit = TimeUnit.SECONDS; + commandCreatesNewSpan(RedisCommand.TIME, () -> getConnection().time(mockRedisClusterNode, timeUnit)); + verify(mockRedisConnection()).time(mockRedisClusterNode, timeUnit); + } + @Test public void invokingGetClientList() { commandCreatesNewSpan(RedisCommand.CLIENT_LIST,