Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ClusterServersConfig.readFromSlaves param added. #272
- Loading branch information
Nikita
committed
Nov 3, 2015
1 parent
7d940c0
commit 68f6178
Showing
12 changed files
with
125 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/java/org/redisson/cluster/ClusterConnectionListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/main/java/org/redisson/connection/ConnectionListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/org/redisson/connection/DefaultConnectionListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters