Skip to content

DATAREDIS-269 - Add support for 'CLIENT SETNAME'. #54

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

Closed
wants to merge 2 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ jredisVersion=06052013
jedisVersion=2.4.1
springVersion=3.2.8.RELEASE
log4jVersion=1.2.17
version=1.3.0.BUILD-SNAPSHOT
version=1.3.0.DATAREDIS-269-SNAPSHOT
srpVersion=0.7
jacksonVersion=1.8.8
fasterXmlJacksonVersion=2.2.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2239,4 +2239,22 @@ private List<Object> convertResults(List<Object> results, Queue<Converter> conve
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));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,10 @@ public enum ShutdownOption {
*/
void killClient(String host, int port);

/**
* Assign given name to current connection.
*
* @since 1.3
*/
void setClientName(byte[] name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -292,4 +292,13 @@ public interface StringTuple extends Tuple {
<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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2828,6 +2828,19 @@ public void killClient(String host, int port) {
}
}

/*
* @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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1190,4 +1190,9 @@ public Long time() {
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.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2920,6 +2920,21 @@ public void killClient(String host, int port) {
}
}

@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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2240,6 +2240,26 @@ public void killClient(String host, int port) {
}
}

/*
* (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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1884,6 +1884,14 @@ public void testGetTimeShouldRequestServerTime() {
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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1710,6 +1710,16 @@ public void testShutdownInDelegatedCorrectlyToNativeConnection() {
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,12 @@ public void testInfoBySection() throws Exception {
public void testZAddMultiple() {
super.testZAddMultiple();
}

/**
* @see DATAREDIS-269
*/
@Test(expected = UnsupportedOperationException.class)
public void clientSetNameWorksCorrectly() {
super.clientSetNameWorksCorrectly();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,13 @@ public void testRestoreBadData() {
public void testRestoreExistingKey() {
super.testRestoreExistingKey();
}

/**
* @see DATAREDIS-269
*/
@Test(expected = UnsupportedOperationException.class)
public void clientSetNameWorksCorrectly() {
super.clientSetNameWorksCorrectly();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -809,4 +809,13 @@ public void testExecuteShouldConvertArrayReplyCorrectly() {
public void testPsetEx() throws Exception {
super.testPsetEx();
}

/**
* @see DATAREDIS-269
*/
@Override
@Test(expected = UnsupportedOperationException.class)
public void clientSetNameWorksCorrectly() {
super.clientSetNameWorksCorrectly();
}
}