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:
Christoph Strobl
2014-03-24 13:32:50 +01:00
committed by Thomas Darimont
parent 6a6d03eb4c
commit e280a23550
13 changed files with 131 additions and 1 deletions

View File

@@ -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>

View File

@@ -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));
}
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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

View File

@@ -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.");
}
}

View File

@@ -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

View File

@@ -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) {

View File

@@ -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());
}

View File

@@ -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;
}

View File

@@ -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();
}
}

View File

@@ -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();
}
}

View File

@@ -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();
}
}