Skip to content

DATAREDIS-277 - Add support for 'SLAVEOF'. #57

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 @@ -138,7 +138,7 @@
<row><entry><code>SINTER</code></entry><entry>X</entry></row>
<row><entry><code>SINTERSTORE</code></entry><entry>X</entry></row>
<row><entry><code>SISMEMBER</code></entry><entry>X</entry></row>
<row><entry><code>SLAVEOF</code></entry><entry>-</entry></row>
<row><entry><code>SLAVEOF</code></entry><entry>X</entry></row>
<row><entry><code>SLOWLOG</code></entry><entry>-</entry></row>
<row><entry><code>SMEMBERS</code></entry><entry>X</entry></row>
<row><entry><code>SMOVE</code></entry><entry>X</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-277-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 @@ -2197,6 +2197,24 @@ public List<RedisClientInfo> getClientList() {
return this.delegate.getClientList();
}

/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisServerCommands#slaveOf(java.lang.String, int)
*/
@Override
public void slaveOf(String host, int port) {
this.delegate.slaveOf(host, port);
}

/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisServerCommands#slaveOfNoOne()
*/
@Override
public void slaveOfNoOne() {
this.delegate.slaveOfNoOne();
}

/**
* Specifies if pipelined and tx results should be deserialized to Strings. If false, results of
* {@link #closePipeline()} and {@link #exec()} will be of the type returned by the underlying connection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public enum ShutdownOption {
Long time();

/**
* Closes a given client connection identified by {@literal ip:port}.
* <<<<<<< HEAD Closes a given client connection identified by {@literal ip:port}.
*
* @param host of connection to close.
* @param port of connection to close
Expand Down Expand Up @@ -197,4 +197,22 @@ public enum ShutdownOption {
* @see http://redis.io/commands/client-list
*/
List<RedisClientInfo> getClientList();

/**
* Change redis replication setting to new master.
*
* @param host
* @param port
* @since 1.3
* @see http://redis.io/commands/slaveof
*/
void slaveOf(String host, int port);

/**
* Change server into master.
*
* @since 1.3
* @see http://redis.io/commands/slaveof
*/
void slaveOfNoOne();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2051,8 +2051,7 @@ public Double zIncrBy(byte[] key, double increment, byte[] value) {

public Long zInterStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) {
try {
ZParams zparams = new ZParams().weights(weights).aggregate(
redis.clients.jedis.ZParams.Aggregate.valueOf(aggregate.name()));
ZParams zparams = new ZParams().weights(weights).aggregate(ZParams.Aggregate.valueOf(aggregate.name()));

if (isPipelined()) {
pipeline(new JedisResult(pipeline.zinterstore(destKey, zparams, sets)));
Expand Down Expand Up @@ -2382,8 +2381,7 @@ public Double zScore(byte[] key, byte[] value) {

public Long zUnionStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) {
try {
ZParams zparams = new ZParams().weights(weights).aggregate(
redis.clients.jedis.ZParams.Aggregate.valueOf(aggregate.name()));
ZParams zparams = new ZParams().weights(weights).aggregate(ZParams.Aggregate.valueOf(aggregate.name()));

if (isPipelined()) {
pipeline(new JedisResult(pipeline.zunionstore(destKey, zparams, sets)));
Expand Down Expand Up @@ -2830,6 +2828,23 @@ public void killClient(String host, int port) {
}
}

/*
* @see org.springframework.data.redis.connection.RedisServerCommands#slaveOf(java.lang.String, int)
*/
@Override
public void slaveOf(String host, int port) {

Assert.hasText(host, "Host must not be null for 'SLAVEOF' command.");
if (isQueueing() || isPipelined()) {
throw new UnsupportedOperationException("'SLAVEOF' cannot be called in pipline / transaction mode.");
}
try {
this.jedis.slaveof(host, port);
} catch (Exception e) {
throw convertJedisAccessException(e);
}
}

/*
* @see org.springframework.data.redis.connection.RedisServerCommands#setClientName(java.lang.String)
*/
Expand Down Expand Up @@ -2868,6 +2883,23 @@ public List<RedisClientInfo> getClientList() {
return JedisConverters.toListOfRedisClientInformation(this.jedis.clientList());
}

/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisServerCommands#slaveOfNoOne()
*/
@Override
public void slaveOfNoOne() {

if (isQueueing() || isPipelined()) {
throw new UnsupportedOperationException("'SLAVEOF' cannot be called in pipline / transaction mode.");
}
try {
this.jedis.slaveofNoOne();
} catch (Exception e) {
throw convertJedisAccessException(e);
}
}

/**
* 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 @@ -1197,6 +1197,20 @@ public void setClientName(byte[] name) {
throw new UnsupportedOperationException("'CLIENT SETNAME' is not supported by the JRedis driver.");
}

/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisServerCommands#slaveOf(java.lang.String, int)
*/
@Override
public void slaveOf(String host, int port) {

try {
this.jredis.slaveof(host, port);
} catch (Exception e) {
throw convertJredisAccessException(e);
}
}

/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisServerCommands#getClientName()
Expand All @@ -1209,4 +1223,17 @@ public String getClientName() {
public List<RedisClientInfo> getClientList() {
throw new UnsupportedOperationException();
}

/*
* @see org.springframework.data.redis.connection.RedisServerCommands#slaveOfNoOne()
*/
@Override
public void slaveOfNoOne() {

try {
this.jredis.slaveofnone();
} catch (Exception e) {
throw convertJredisAccessException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2939,6 +2939,29 @@ public void setClientName(byte[] name) {
getAsyncConnection().clientSetname(name);
}

/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisServerCommands#slaveOf(java.lang.String, int)
*/
@Override
public void slaveOf(String host, int port) {

Assert.hasText(host, "Host must not be null for 'SLAVEOF' command.");
try {
if (isPipelined()) {
pipeline(new LettuceStatusResult(getAsyncConnection().slaveof(host, port)));
return;
}
if (isQueueing()) {
transaction(new LettuceTxResult(getConnection().slaveof(host, port)));
return;
}
getConnection().slaveof(host, port);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}

/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisServerCommands#getClientName()
Expand Down Expand Up @@ -2978,6 +3001,27 @@ public List<RedisClientInfo> getClientList() {
return LettuceConverters.toListOfRedisClientInformation(getConnection().clientList());
}

/*
* @see org.springframework.data.redis.connection.RedisServerCommands#slaveOfNoOne()
*/
@Override
public void slaveOfNoOne() {

try {
if (isPipelined()) {
pipeline(new LettuceStatusResult(getAsyncConnection().slaveofNoOne()));
return;
}
if (isQueueing()) {
transaction(new LettuceTxResult(getConnection().slaveofNoOne()));
return;
}
getConnection().slaveofNoOne();
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}
}

/**
* 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 @@ -2262,6 +2262,25 @@ public void setClientName(byte[] name) {
}
}

/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisServerCommands#slaveOf(java.lang.String, int)
*/
@Override
public void slaveOf(String host, int port) {

Assert.hasText(host, "Host must not be null for 'SLAVEOF' command.");
try {
if (isPipelined()) {
pipeline(new SrpStatusResult(pipeline.slaveof(host, port)));
return;
}
client.slaveof(host, port);
} catch (Exception e) {
throw convertSrpAccessException(e);
}
}

/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisServerCommands#getClientName()
Expand Down Expand Up @@ -2295,6 +2314,23 @@ public List<RedisClientInfo> getClientList() {
return SrpConverters.toListOfRedisClientInformation(this.client.client_list());
}

/*
* @see org.springframework.data.redis.connection.RedisServerCommands#slaveOfNoOne()
*/
@Override
public void slaveOfNoOne() {

try {
if (isPipelined()) {
pipeline(new SrpStatusResult(pipeline.slaveof("NO", "ONE")));
return;
}
client.slaveof("NO", "ONE");
} catch (Exception e) {
throw convertSrpAccessException(e);
}
}

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 @@ -303,4 +303,20 @@ <T> T execute(RedisScript<T> script, RedisSerializer<?> argsSerializer, RedisSer
* @since 1.3
*/
void killClient(String host, int port);

/**
* Change redis replication setting to new master.
*
* @param host
* @param port
* @since 1.3
*/
void slaveOf(String host, int port);

/**
* Change server into master.
*
* @since 1.3
*/
void slaveOfNoOne();
}
Original file line number Diff line number Diff line change
Expand Up @@ -1019,4 +1019,38 @@ public List<RedisClientInfo> doInRedis(RedisConnection connection) throws DataAc
}
});
}

/*
* @see org.springframework.data.redis.core.RedisOperations#slaveOf(java.lang.String, int)
*/
@Override
public void slaveOf(final String host, final int port) {

execute(new RedisCallback<Void>() {
@Override
public Void doInRedis(RedisConnection connection) throws DataAccessException {

connection.slaveOf(host, port);
return null;
}

});
}

/*
* (non-Javadoc)
* @see org.springframework.data.redis.core.RedisOperations#slaveOfNoOne()
*/
@Override
public void slaveOfNoOne() {

execute(new RedisCallback<Void>() {

@Override
public Void doInRedis(RedisConnection connection) throws DataAccessException {
connection.slaveOfNoOne();
return null;
}
});
}
}
Loading