DATAREDIS-269 - Add support for 'CLIENT SETNAME'.
Setting client name is possible for 'jedis', 'lettuce' and 'srp'. Using 'jredis' throws 'UnspupportedOperationException'. Original Pull Request: #54
This commit is contained in:
committed by
Thomas Darimont
parent
6a6d03eb4c
commit
e280a23550
@@ -26,7 +26,7 @@
|
||||
<row><entry><code>CLIENT GETNAME</code></entry><entry>-</entry></row>
|
||||
<row><entry><code>CLIENT KILL</code></entry><entry>X</entry></row>
|
||||
<row><entry><code>CLIENT LIST</code></entry><entry>-</entry></row>
|
||||
<row><entry><code>CLIENT SETNAME</code></entry><entry>-</entry></row>
|
||||
<row><entry><code>CLIENT SETNAME</code></entry><entry>X</entry></row>
|
||||
<row><entry><code>CONFIG GET</code></entry><entry>X</entry></row>
|
||||
<row><entry><code>CONFIG RESETSTAT</code></entry><entry>X</entry></row>
|
||||
<row><entry><code>CONFIG REWRITE</code></entry><entry>-</entry></row>
|
||||
|
||||
@@ -2239,4 +2239,22 @@ public class DefaultStringRedisConnection implements StringRedisConnection {
|
||||
return convertedResults;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisServerCommands#setClientName(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public void setClientName(byte[] name) {
|
||||
this.delegate.setClientName(name);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.StringRedisConnection#setClientName(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public void setClientName(String name) {
|
||||
setClientName(this.serializer.serialize(name));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -171,4 +171,10 @@ public interface RedisServerCommands {
|
||||
*/
|
||||
void killClient(String host, int port);
|
||||
|
||||
/**
|
||||
* Assign given name to current connection.
|
||||
*
|
||||
* @since 1.3
|
||||
*/
|
||||
void setClientName(byte[] name);
|
||||
}
|
||||
|
||||
@@ -292,4 +292,13 @@ public interface StringRedisConnection extends RedisConnection {
|
||||
<T> T eval(String script, ReturnType returnType, int numKeys, String... keysAndArgs);
|
||||
|
||||
<T> T evalSha(String scriptSha1, ReturnType returnType, int numKeys, String... keysAndArgs);
|
||||
|
||||
/**
|
||||
* Assign given {@code name} to connection using registered {@link RedisSerializer} for name conversion.
|
||||
*
|
||||
* @param name
|
||||
* @see #setClientName(byte[])
|
||||
* @sice 1.3
|
||||
*/
|
||||
void setClientName(String name);
|
||||
}
|
||||
|
||||
@@ -2828,6 +2828,19 @@ public class JedisConnection implements RedisConnection {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.springframework.data.redis.connection.RedisServerCommands#setClientName(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public void setClientName(byte[] name) {
|
||||
|
||||
if (isPipelined() || isQueueing()) {
|
||||
throw new UnsupportedOperationException("'CLIENT SETNAME' is not suppored in transacton / pipeline mode.");
|
||||
}
|
||||
|
||||
jedis.clientSetname(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
||||
@@ -1190,4 +1190,9 @@ public class JredisConnection implements RedisConnection {
|
||||
public void killClient(String host, int port) {
|
||||
throw new UnsupportedOperationException("The 'CLIENT KILL' command is not supported by the JRedis driver.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setClientName(byte[] name) {
|
||||
throw new UnsupportedOperationException("'CLIENT SETNAME' is not supported by the JRedis driver.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2920,6 +2920,21 @@ public class LettuceConnection implements RedisConnection {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setClientName(byte[] name) {
|
||||
|
||||
if (isQueueing()) {
|
||||
pipeline(new LettuceStatusResult(getAsyncConnection().clientSetname(name)));
|
||||
return;
|
||||
}
|
||||
if (isQueueing()) {
|
||||
transaction(new LettuceTxResult(getConnection().clientSetname(name)));
|
||||
return;
|
||||
}
|
||||
|
||||
getAsyncConnection().clientSetname(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies if pipelined and transaction 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 Lettuce driver
|
||||
|
||||
@@ -2240,6 +2240,26 @@ public class SrpConnection implements RedisConnection {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisServerCommands#setClientName(byte[])
|
||||
*/
|
||||
@Override
|
||||
public void setClientName(byte[] name) {
|
||||
|
||||
try {
|
||||
|
||||
if (isPipelined()) {
|
||||
pipeline(new SrpStatusResult(pipeline.client_setname(name)));
|
||||
return;
|
||||
}
|
||||
|
||||
this.client.client_setname(name);
|
||||
} catch (Exception ex) {
|
||||
throw convertSrpAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private List<Object> closeTransaction() {
|
||||
List<Object> results = Collections.emptyList();
|
||||
if (txTracker != null) {
|
||||
|
||||
@@ -1884,6 +1884,14 @@ public abstract class AbstractConnectionIntegrationTests {
|
||||
assertThat(time > 0, equalTo(true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREDIS-269
|
||||
*/
|
||||
@Test
|
||||
public void clientSetNameWorksCorrectly() {
|
||||
connection.setClientName("foo".getBytes());
|
||||
}
|
||||
|
||||
protected void verifyResults(List<Object> expected) {
|
||||
assertEquals(expected, getResults());
|
||||
}
|
||||
|
||||
@@ -1710,6 +1710,16 @@ public class DefaultStringRedisConnectionTests {
|
||||
verify(nativeConnection, times(1)).shutdown(eq(ShutdownOption.NOSAVE));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREDIS-269
|
||||
*/
|
||||
@Test
|
||||
public void settingClientNameShouldDelegateToNativeConnection() {
|
||||
|
||||
connection.setClientName("foo");
|
||||
verify(nativeConnection, times(1)).setClientName(eq("foo".getBytes()));
|
||||
}
|
||||
|
||||
protected List<Object> getResults() {
|
||||
return actual;
|
||||
}
|
||||
|
||||
@@ -246,4 +246,12 @@ public class JedisConnectionPipelineIntegrationTests extends AbstractConnectionP
|
||||
public void testZAddMultiple() {
|
||||
super.testZAddMultiple();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREDIS-269
|
||||
*/
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void clientSetNameWorksCorrectly() {
|
||||
super.clientSetNameWorksCorrectly();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -191,4 +191,13 @@ public class JedisConnectionTransactionIntegrationTests extends AbstractConnecti
|
||||
public void testRestoreExistingKey() {
|
||||
super.testRestoreExistingKey();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREDIS-269
|
||||
*/
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void clientSetNameWorksCorrectly() {
|
||||
super.clientSetNameWorksCorrectly();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -809,4 +809,13 @@ public class JRedisConnectionIntegrationTests extends AbstractConnectionIntegrat
|
||||
public void testPsetEx() throws Exception {
|
||||
super.testPsetEx();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREDIS-269
|
||||
*/
|
||||
@Override
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void clientSetNameWorksCorrectly() {
|
||||
super.clientSetNameWorksCorrectly();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user