Skip to content

Avoid wrapping RedisConnection into StringRedisConnection via StringRedisTemplate #3193

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion 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>4.0.0-SNAPSHOT</version>
<version>4.0.x-GH-3191-SNAPSHOT</version>

<name>Spring Data Redis</name>
<description>Spring Data module for Redis</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,93 +45,146 @@ public enum RedisCommand {
// -- A
APPEND("rw", 2, 2), //
AUTH("rw", 1, 1), //

// -- B
BGREWRITEAOF("r", 0, 0, "bgwriteaof"), //
BGSAVE("r", 0, 0), //
BITCOUNT("r", 1, 3), //
BITFIELD("rw", 1), //
BITFIELD_RO("r", 1),
BITOP("rw", 3), //
BITPOS("r", 2, 4), //
BLMOVE("rw", 4), //
BLMPOP("rw", 4), //
BLPOP("rw", 2), //
BRPOP("rw", 2), //
BRPOPLPUSH("rw", 3), //
BZMPOP("rw", 3), //
BZPOPMAX("rw", 2), //
BZPOPMIN("rw", 2), //

// -- C
CLIENT_GETREDIR("r", 0, 0), //
CLIENT_ID("r", 0, 0), //
CLIENT_INFO("r", 0, 0), //
CLIENT_KILL("rw", 1, 1), //
CLIENT_LIST("r", 0, 0), //
CLIENT_GETNAME("r", 0, 0), //
CLIENT_PAUSE("rw", 1, 1), //
CLIENT_SETINFO("w", 1), //
CLIENT_SETNAME("w", 1, 1), //
CLIENT_NO_EVICT("w", 1, 1, "client no-evict"), //
CLIENT_NO_TOUCH("w", 1, 1, "client no-touch"), //
CLIENT_TRACKING("rw", 1), //
CONFIG_GET("r", 1, 1, "getconfig"), //
CONFIG_REWRITE("rw", 0, 0), //
CONFIG_SET("w", 2, 2, "setconfig"), //
CONFIG_RESETSTAT("w", 0, 0, "resetconfigstats"), //
COPY("rw", 2), //

// -- D
DBSIZE("r", 0, 0), //
DECR("w", 1, 1), //
DECRBY("w", 2, 2), //
DEL("rw", 1), //
DISCARD("rw", 0, 0), //
DUMP("r", 1, 1), //

// -- E
ECHO("r", 1, 1), //
EVAL("rw", 2), //
EVAL_RO("r", 2), //
EVALSHA("rw", 2), //
EVALSHA_RO("r", 2), //
EXEC("rw", 0, 0), //
EXISTS("r", 1, 1), //
EXPIRE("rw", 2), //
EXPIREAT("rw", 2), //
EXPIRETIME("r", 1), //

// -- F
FCALL("rw", 2), //
FCALL_RO("r", 2), //
FLUSHALL("w", 0, 0), //
FLUSHDB("w", 0, 0), //
FUNCTION_DELETE("w", 1), //
FUNCTION_DUMP("w", 0, 0), //
FUNCTION_FLUSH("w", 0, 0), //
FUNCTION_KILL("w", 0, 0), //

// -- G
GET("r", 1, 1), //
GETBIT("r", 2, 2), //
GETDEL("rw", 1), //
GETEX("rw", 1), //
GETRANGE("r", 3, 3), //
GETSET("rw", 2, 2), //
GEOADD("w", 3), //
GEODIST("r", 2), //
GEOHASH("r", 2), //
GEOPOS("r", 2), //
GEORADIUS("r", 4), //
GEORADIUSBYMEMBER("r", 3), //
GEORADIUS("rw", 4), //
GEORADIUS_RO("r", 4), //
GEORADIUSBYMEMBER("rw", 3), //
GEORADIUSBYMEMBER_RO("r", 3), //
GEOSEARCH("r", 1), //
GEOSEARCH_STORE("rw", 1), //

// -- H
HDEL("rw", 2), //
HELLO("rw", 0, 0), //
HEXISTS("r", 2, 2), //
HGET("r", 2, 2), //
HGETALL("r", 1, 1), //
HGETDEL("rw", 2), //
HGETEX("rw", 2), //
HINCRBY("rw", 3, 3), //
HINCBYFLOAT("rw", 3, 3), //
HKEYS("r", 1), //
HLEN("r", 1), //
HMGET("r", 2), //
HMSET("w", 3), //
HPOP("rw", 3),
HSET("w", 3, 3), //
HSETNX("w", 3, 3), //
HVALS("r", 1, 1), //
HEXPIRE("w", 5), //
HEXPIREAT("w", 5), //
HPEXPIRE("w", 5), //
HPEXPIREAT("w", 5), //
HPEXPIRETIME("r", 4), //
HPERSIST("w", 4), //
HTTL("r", 4), //
HPTTL("r", 4), //
HSCAN("r", 2), //
HSTRLEN("r", 2), //

// -- I
INCR("rw", 1), //
INCRBY("rw", 2, 2), //
INCRBYFLOAT("rw", 2, 2), //
INFO("r", 0), //

// -- K
KEYS("r", 1), //

// -- L
LCS("r", 2), //
LASTSAVE("r", 0), //
LINDEX("r", 2, 2), //
LINSERT("rw", 4, 4), //
LLEN("r", 1, 1), //
LMOVE("rw", 2), //
LMPOP("rw", 2), //
LPOP("rw", 1, 1), //
LPOS("r", 2), //
LPUSH("rw", 2), //
LPUSHX("rw", 2), //
LRANGE("r", 3, 3), //
LREM("rw", 3, 3), //
LSET("w", 3, 3), //
LTRIM("w", 3, 3), //

// -- M
MGET("r", 1), //
MIGRATE("rw", 0), //
Expand All @@ -140,19 +193,26 @@ public enum RedisCommand {
MSET("w", 2), //
MSETNX("w", 2), //
MULTI("rw", 0, 0), //

// -- P
PERSIST("rw", 1, 1), //
PEXPIRE("rw", 2), //
PEXPIREAT("rw", 2), //
PEXPIRETIME("r", 1), //
PFADD("w", 10), //
PFCOUNT("r", 1), //
PFMERGE("rw", 2), //
PING("r", 0, 0), //
PSETEX("w", 3), //
PSUBSCRIBE("r", 1), //
PTTL("r", 1, 1), //
// -- Q
QUIT("rw", 0, 0), //

// -- R
RANDOMKEY("r", 0, 0), //

READONLY("w", 0, 0), //
READWRITE("w", 0, 0), //
RENAME("w", 2, 2), //
RENAMENX("w", 2, 2), //
REPLICAOF("w", 2), //
Expand All @@ -161,9 +221,11 @@ public enum RedisCommand {
RPOPLPUSH("rw", 2, 2), //
RPUSH("rw", 2), //
RPUSHX("rw", 2, 2), //

// -- S
SADD("rw", 2), //
SAVE("rw", 0, 0), //
SCAN("r", 1), //
SCARD("r", 1, 1), //
SCRIPT_EXISTS("r", 1), //
SCRIPT_FLUSH("rw", 0, 0), //
Expand All @@ -179,28 +241,47 @@ public enum RedisCommand {
SETRANGE("rw", 3, 3), //
SHUTDOWN("rw", 0), //
SINTER("r", 1), //
SINTERCARD("r", 1), //
SINTERSTORE("rw", 2), //
SISMEMBER("r", 2), //
SLAVEOF("w", 2), //
SLOWLOG("rw", 1), //
SMEMBERS("r", 1, 1), //
SMOVE("rw", 3, 3), //
SORT("rw", 1), //
SORT_RO("r", 1), //
SPOP("rw", 1, 1), //
SRANDMEMBER("r", 1, 1), //
SREM("rw", 2), //
SSCAN("r", 1), //
STRLEN("r", 1, 1), //
SUBSCRIBE("rw", 1), //
SUBSTR("r", 3), //
SUNION("r", 1), //
SUNIONSTORE("rw ", 2), //
SYNC("rw", 0, 0), //

// -- T
TIME("r", 0, 0), //
TTL("r", 1, 1), //
TYPE("r", 1, 1), //

// -- U
UNLINK("w", 1), //
UNSUBSCRIBE("rw", 0), //
UNWATCH("rw", 0, 0), //

// -- V
VADD("w", 3), //
VCARD("r", 1), //
VDIM("r", 1), //
VEMB("r", 2), //
VISMEMBER("r", 2), //
VLINKS("r", 2, 3), //
VRANDMEMBER("r", 1, 2), //
VREM("w", 2), //
VSIM("w", 1), //

// -- W
WATCH("rw", 1), //
// -- Z
Expand All @@ -220,10 +301,8 @@ public enum RedisCommand {
ZREVRANK("r", 2, 2), //
ZSCORE("r", 2, 2), //
ZUNIONSTORE("rw", 3), //
SCAN("r", 1), //
SSCAN("r", 2), //
HSCAN("r", 2), //
ZSCAN("r", 2), //

// -- UNKNOWN / DEFAULT
UNKNOWN("rw", -1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,4 @@ public StringRedisTemplate(RedisConnectionFactory connectionFactory) {
setConnectionFactory(connectionFactory);
afterPropertiesSet();
}

protected RedisConnection preProcessConnection(RedisConnection connection, boolean existingConnection) {
return new DefaultStringRedisConnection(connection);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ void commandRequiresExactNumberOfArgumentsIsCorrect() {

Arrays.stream(RedisCommand.values())
.forEach(command -> assertThat(command.requiresExactNumberOfArguments())
.describedAs("Redis command [%s] failed requires exact arguments check").isEqualTo(
.describedAs("Redis command [%s] failed requires exact arguments check".formatted(command.name())).isEqualTo(
ReflectionTestUtils.getField(command, "minArgs") == ReflectionTestUtils.getField(command, "maxArgs")));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.springframework.data.redis.Person;
import org.springframework.data.redis.SettingsUtils;
import org.springframework.data.redis.connection.DataType;
import org.springframework.data.redis.connection.DefaultStringRedisConnection;
import org.springframework.data.redis.connection.ExpirationOptions;
import org.springframework.data.redis.connection.RedisClusterConnection;
import org.springframework.data.redis.connection.RedisConnection;
Expand Down Expand Up @@ -161,7 +162,7 @@ void testTemplateNotInitialized() throws Exception {
void testStringTemplateExecutesWithStringConn() {
assumeThat(redisTemplate instanceof StringRedisTemplate).isTrue();
String value = redisTemplate.execute((RedisCallback<String>) connection -> {
StringRedisConnection stringConn = (StringRedisConnection) connection;
StringRedisConnection stringConn = new DefaultStringRedisConnection(connection);
stringConn.set("test", "it");
return stringConn.get("test");
});
Expand Down Expand Up @@ -307,7 +308,7 @@ void testExecutePipelinedCustomSerializer() {
assumeThat(redisTemplate instanceof StringRedisTemplate).isTrue();

List<Object> results = redisTemplate.executePipelined((RedisCallback) connection -> {
StringRedisConnection stringRedisConn = (StringRedisConnection) connection;
StringRedisConnection stringRedisConn = new DefaultStringRedisConnection(connection);
stringRedisConn.set("foo", "5");
stringRedisConn.get("foo");
stringRedisConn.rPush("foolist", "10");
Expand Down
Loading