Convert cross-server commands to utilize master-slave redis instances rather than a stand-alone instance.

Add new slave instance on port 6377.
This commit is contained in:
Ty Sayers 2015-03-11 21:42:52 -04:00
parent 7dbf970df7
commit 9788436700
2 changed files with 10 additions and 13 deletions

View File

@ -28,8 +28,9 @@ public class ServerCommandManager
*/ */
private ServerCommandManager() private ServerCommandManager()
{ {
_writePool = Utility.generatePool(ServerManager.getPubSubConnection()); // Hardcoded connection to standalone redis instance _writePool = Utility.generatePool(ServerManager.getMasterConnection()); // Publish to master instance
_readPool = _writePool; _readPool = Utility.generatePool(ServerManager.getSlaveConnection()); // Read from slave instance
_commandTypes = new HashMap<String, CommandType>(); _commandTypes = new HashMap<String, CommandType>();
initialize(); initialize();

View File

@ -11,8 +11,12 @@ import java.util.Random;
*/ */
public class ServerManager public class ServerManager
{ {
// Connection host to server database
private static final String DATABASE_HOST = "10.33.53.16";
// Ports associated with slave redis instances // Ports associated with slave redis instances
private static final int[] SLAVE_PORTS = {6378, 6380, 6381}; private static final int[] SLAVE_PORTS = {6377, 6378, 6380, 6381};
private static Random random = new Random(); private static Random random = new Random();
// The cached repository instances // The cached repository instances
@ -49,7 +53,7 @@ public class ServerManager
*/ */
public static ConnectionData getMasterConnection() public static ConnectionData getMasterConnection()
{ {
return new ConnectionData("10.33.53.16", 6379); return new ConnectionData(DATABASE_HOST, 6379);
} }
/** /**
@ -59,14 +63,6 @@ public class ServerManager
public static ConnectionData getSlaveConnection() public static ConnectionData getSlaveConnection()
{ {
int port = SLAVE_PORTS[random.nextInt(SLAVE_PORTS.length)]; int port = SLAVE_PORTS[random.nextInt(SLAVE_PORTS.length)];
return new ConnectionData("10.33.53.16", port); return new ConnectionData(DATABASE_HOST, port);
}
/**
* @return the {@link ConnectionData} associated with the dedicated PubSub instance.
*/
public static ConnectionData getPubSubConnection()
{
return new ConnectionData("10.33.53.16", 6377);
} }
} }