ClusterServersConfig.readFromSlaves param added. #272
parent
7d940c012a
commit
68f617880a
@ -0,0 +1,26 @@
|
|||||||
|
package org.redisson.cluster;
|
||||||
|
|
||||||
|
import org.redisson.MasterSlaveServersConfig;
|
||||||
|
import org.redisson.client.RedisConnection;
|
||||||
|
import org.redisson.client.RedisException;
|
||||||
|
import org.redisson.client.protocol.RedisCommands;
|
||||||
|
import org.redisson.connection.DefaultConnectionListener;
|
||||||
|
import org.redisson.connection.ConnectionEntry.Mode;
|
||||||
|
|
||||||
|
public class ClusterConnectionListener extends DefaultConnectionListener {
|
||||||
|
|
||||||
|
private final boolean readFromSlaves;
|
||||||
|
|
||||||
|
public ClusterConnectionListener(boolean readFromSlaves) {
|
||||||
|
this.readFromSlaves = readFromSlaves;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onConnect(MasterSlaveServersConfig config, RedisConnection conn, Mode serverMode) throws RedisException {
|
||||||
|
super.onConnect(config, conn, serverMode);
|
||||||
|
if (serverMode == Mode.SLAVE && readFromSlaves) {
|
||||||
|
conn.sync(RedisCommands.READONLY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
package org.redisson.connection;
|
||||||
|
|
||||||
|
import org.redisson.MasterSlaveServersConfig;
|
||||||
|
import org.redisson.client.RedisConnection;
|
||||||
|
import org.redisson.client.RedisException;
|
||||||
|
import org.redisson.connection.ConnectionEntry.Mode;
|
||||||
|
|
||||||
|
public interface ConnectionListener {
|
||||||
|
|
||||||
|
void onConnect(MasterSlaveServersConfig config, RedisConnection redisConnection, Mode serverMode) throws RedisException;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
package org.redisson.connection;
|
||||||
|
|
||||||
|
import org.redisson.MasterSlaveServersConfig;
|
||||||
|
import org.redisson.client.RedisConnection;
|
||||||
|
import org.redisson.client.RedisException;
|
||||||
|
import org.redisson.client.protocol.RedisCommands;
|
||||||
|
import org.redisson.connection.ConnectionEntry.Mode;
|
||||||
|
|
||||||
|
public class DefaultConnectionListener implements ConnectionListener {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onConnect(MasterSlaveServersConfig config, RedisConnection conn, Mode serverMode)
|
||||||
|
throws RedisException {
|
||||||
|
if (config.getPassword() != null) {
|
||||||
|
conn.sync(RedisCommands.AUTH, config.getPassword());
|
||||||
|
}
|
||||||
|
if (config.getDatabase() != 0) {
|
||||||
|
conn.sync(RedisCommands.SELECT, config.getDatabase());
|
||||||
|
}
|
||||||
|
if (config.getClientName() != null) {
|
||||||
|
conn.sync(RedisCommands.CLIENT_SETNAME, config.getClientName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue