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
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user