Fixed - RedissonConnection.set returns null if invoked with expiration parameter. #2217

pull/2247/head^2
Nikita Koksharov 6 years ago
parent 343b3f813c
commit 22ddb6a671

@ -100,9 +100,6 @@ import org.springframework.data.redis.core.types.RedisClientInfo;
import org.springframework.util.Assert;
import org.springframework.util.ReflectionUtils;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.FutureListener;
/**
* Redisson connection
*
@ -612,13 +609,13 @@ public class RedissonConnection extends AbstractRedisConnection {
}
} else {
if (option == null || option == SetOption.UPSERT) {
return write(key, StringCodec.INSTANCE, RedisCommands.SET, key, value, "PX", expiration.getExpirationTimeInMilliseconds());
return write(key, StringCodec.INSTANCE, SET, key, value, "PX", expiration.getExpirationTimeInMilliseconds());
}
if (option == SetOption.SET_IF_ABSENT) {
return write(key, StringCodec.INSTANCE, RedisCommands.SET, key, value, "PX", expiration.getExpirationTimeInMilliseconds(), "NX");
return write(key, StringCodec.INSTANCE, SET, key, value, "PX", expiration.getExpirationTimeInMilliseconds(), "NX");
}
if (option == SetOption.SET_IF_PRESENT) {
return write(key, StringCodec.INSTANCE, RedisCommands.SET, key, value, "PX", expiration.getExpirationTimeInMilliseconds(), "XX");
return write(key, StringCodec.INSTANCE, SET, key, value, "PX", expiration.getExpirationTimeInMilliseconds(), "XX");
}
}
throw new IllegalArgumentException();

@ -609,13 +609,13 @@ public class RedissonConnection extends AbstractRedisConnection {
}
} else {
if (option == null || option == SetOption.UPSERT) {
return write(key, StringCodec.INSTANCE, RedisCommands.SET, key, value, "PX", expiration.getExpirationTimeInMilliseconds());
return write(key, StringCodec.INSTANCE, SET, key, value, "PX", expiration.getExpirationTimeInMilliseconds());
}
if (option == SetOption.SET_IF_ABSENT) {
return write(key, StringCodec.INSTANCE, RedisCommands.SET, key, value, "PX", expiration.getExpirationTimeInMilliseconds(), "NX");
return write(key, StringCodec.INSTANCE, SET, key, value, "PX", expiration.getExpirationTimeInMilliseconds(), "NX");
}
if (option == SetOption.SET_IF_PRESENT) {
return write(key, StringCodec.INSTANCE, RedisCommands.SET, key, value, "PX", expiration.getExpirationTimeInMilliseconds(), "XX");
return write(key, StringCodec.INSTANCE, SET, key, value, "PX", expiration.getExpirationTimeInMilliseconds(), "XX");
}
}
throw new IllegalArgumentException();

@ -3,6 +3,8 @@ package org.redisson.spring.data.connection;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.springframework.data.redis.connection.RedisStringCommands.SetOption;
import org.springframework.data.redis.core.types.Expiration;
public class RedissonConnectionTest extends BaseConnectionTest {
@ -17,6 +19,12 @@ public class RedissonConnectionTest extends BaseConnectionTest {
assertThat(connection.get("key".getBytes())).isEqualTo("value".getBytes());
}
@Test
public void testSetExpiration() {
assertThat(connection.set("key".getBytes(), "value".getBytes(), Expiration.milliseconds(111122), SetOption.SET_IF_ABSENT)).isTrue();
assertThat(connection.get("key".getBytes())).isEqualTo("value".getBytes());
}
@Test
public void testHSetGet() {
assertThat(connection.hSet("key".getBytes(), "field".getBytes(), "value".getBytes())).isTrue();

Loading…
Cancel
Save