org.redisson.config.ReadMode Java Examples
The following examples show how to use
org.redisson.config.ReadMode.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ElasticacheSessionManager.java From redis-session-manager with Apache License 2.0 | 5 votes |
@Override protected Config configure(Config config) { if (nodes == null || nodes.trim().length() == 0) { throw new IllegalStateException("Manager must specify node string. e.g., nodes=\"node1.com:6379 node2.com:6379\""); } LoadBalancer lb = null; if (loadBalancerClass != null && loadBalancerClass.trim().length() != 0) { try { lb = LoadBalancer.class.cast(Class.forName(loadBalancerClass).newInstance()); } catch (Exception e) { log.error("Failed to instantiate LoadBalancer", e); } } ReplicatedServersConfig ecCfg = config.useReplicatedServers(); ecCfg .addNodeAddress(nodes.trim().split("\\s+")) .setDatabase(database) .setMasterConnectionPoolSize(masterConnectionPoolSize) .setSlaveConnectionPoolSize(slaveConnectionPoolSize) .setPassword(password) .setTimeout(timeout) .setReadMode(ReadMode.MASTER_SLAVE) .setPingTimeout(pingTimeout) .setRetryAttempts(retryAttempts) .setRetryInterval(retryInterval) .setScanInterval(nodePollInterval); if (lb != null) { ecCfg.setLoadBalancer(lb); } return config; }
Example #2
Source File: LoadBalancerManager.java From redisson with Apache License 2.0 | 5 votes |
public void changeType(InetSocketAddress address, NodeType nodeType) { ClientConnectionsEntry entry = getEntry(address); if (entry != null) { if (connectionManager.isClusterMode()) { entry.getClient().getConfig().setReadOnly(nodeType == NodeType.SLAVE && connectionManager.getConfig().getReadMode() != ReadMode.MASTER); } entry.setNodeType(nodeType); } }
Example #3
Source File: MasterSlaveEntry.java From redisson with Apache License 2.0 | 5 votes |
public void releaseRead(RedisConnection connection) { if (config.getReadMode() == ReadMode.MASTER) { releaseWrite(connection); return; } slaveBalancer.returnConnection(connection); }
Example #4
Source File: SingleConnectionManager.java From redisson with Apache License 2.0 | 5 votes |
private static MasterSlaveServersConfig create(SingleServerConfig cfg) { MasterSlaveServersConfig newconfig = new MasterSlaveServersConfig(); newconfig.setPingConnectionInterval(cfg.getPingConnectionInterval()); newconfig.setSslEnableEndpointIdentification(cfg.isSslEnableEndpointIdentification()); newconfig.setSslProvider(cfg.getSslProvider()); newconfig.setSslTruststore(cfg.getSslTruststore()); newconfig.setSslTruststorePassword(cfg.getSslTruststorePassword()); newconfig.setSslKeystore(cfg.getSslKeystore()); newconfig.setSslKeystorePassword(cfg.getSslKeystorePassword()); newconfig.setRetryAttempts(cfg.getRetryAttempts()); newconfig.setRetryInterval(cfg.getRetryInterval()); newconfig.setTimeout(cfg.getTimeout()); newconfig.setPassword(cfg.getPassword()); newconfig.setUsername(cfg.getUsername()); newconfig.setDatabase(cfg.getDatabase()); newconfig.setClientName(cfg.getClientName()); newconfig.setMasterAddress(cfg.getAddress()); newconfig.setMasterConnectionPoolSize(cfg.getConnectionPoolSize()); newconfig.setSubscriptionsPerConnection(cfg.getSubscriptionsPerConnection()); newconfig.setSubscriptionConnectionPoolSize(cfg.getSubscriptionConnectionPoolSize()); newconfig.setConnectTimeout(cfg.getConnectTimeout()); newconfig.setIdleConnectionTimeout(cfg.getIdleConnectionTimeout()); newconfig.setDnsMonitoringInterval(cfg.getDnsMonitoringInterval()); newconfig.setMasterConnectionMinimumIdleSize(cfg.getConnectionMinimumIdleSize()); newconfig.setSubscriptionConnectionMinimumIdleSize(cfg.getSubscriptionConnectionMinimumIdleSize()); newconfig.setReadMode(ReadMode.MASTER); newconfig.setSubscriptionMode(SubscriptionMode.MASTER); newconfig.setKeepAlive(cfg.isKeepAlive()); return newconfig; }
Example #5
Source File: MultipleServerConfig.java From redisson-spring-boot-starter with GNU Lesser General Public License v3.0 | 4 votes |
public ReadMode getReadMode() { return readMode; }
Example #6
Source File: MultipleServerConfig.java From redisson-spring-boot-starter with GNU Lesser General Public License v3.0 | 4 votes |
public void setReadMode(ReadMode readMode) { this.readMode = readMode; }
Example #7
Source File: RedissonClusterConfig.java From game-server with MIT License | 4 votes |
public ReadMode getReadMode() { return readMode; }
Example #8
Source File: RedissonClusterConfig.java From game-server with MIT License | 4 votes |
public void setReadMode(ReadMode readMode) { this.readMode = readMode; }
Example #9
Source File: ClientConnectionsEntry.java From redisson with Apache License 2.0 | 4 votes |
public boolean isMasterForRead() { return getFreezeReason() == FreezeReason.SYSTEM && connectionManager.getConfig().getReadMode() == ReadMode.MASTER_SLAVE && getNodeType() == NodeType.MASTER; }
Example #10
Source File: MasterSlaveEntry.java From redisson with Apache License 2.0 | 4 votes |
public RFuture<RedisConnection> connectionReadOp(RedisCommand<?> command) { if (config.getReadMode() == ReadMode.MASTER) { return connectionWriteOp(command); } return slaveBalancer.nextConnection(command); }
Example #11
Source File: MasterSlaveEntry.java From redisson with Apache License 2.0 | 4 votes |
public RFuture<RedisConnection> connectionReadOp(RedisCommand<?> command, RedisClient client) { if (config.getReadMode() == ReadMode.MASTER) { return connectionWriteOp(command); } return slaveBalancer.getConnection(command, client); }
Example #12
Source File: ReplicatedConnectionManager.java From redisson with Apache License 2.0 | 4 votes |
public ReplicatedConnectionManager(ReplicatedServersConfig cfg, Config config, UUID id) { super(config, id); this.config = create(cfg); initTimer(this.config); for (String address : cfg.getNodeAddresses()) { RedisURI addr = new RedisURI(address); RFuture<RedisConnection> connectionFuture = connectToNode(cfg, addr, null, addr.getHost()); connectionFuture.awaitUninterruptibly(); RedisConnection connection = connectionFuture.getNow(); if (connection == null) { continue; } Role role = Role.valueOf(connection.sync(RedisCommands.INFO_REPLICATION).get(ROLE_KEY)); if (Role.master.equals(role)) { if (currentMaster.get() != null) { stopThreads(); throw new RedisException("Multiple masters detected"); } currentMaster.set(addr); log.info("{} is the master", addr); this.config.setMasterAddress(addr.toString()); } else { log.info("{} is a slave", addr); this.config.addSlaveAddress(addr.toString()); } } if (currentMaster.get() == null) { stopThreads(); throw new RedisConnectionException("Can't connect to servers!"); } if (this.config.getReadMode() != ReadMode.MASTER && this.config.getSlaveAddresses().isEmpty()) { log.warn("ReadMode = " + this.config.getReadMode() + ", but slave nodes are not found! Please specify all nodes in replicated mode."); } initSingleEntry(); scheduleMasterChangeCheck(cfg); }
Example #13
Source File: ClusterConnectionManager.java From redisson with Apache License 2.0 | 4 votes |
@Override protected RedisClientConfig createRedisConfig(NodeType type, RedisURI address, int timeout, int commandTimeout, String sslHostname) { RedisClientConfig result = super.createRedisConfig(type, address, timeout, commandTimeout, sslHostname); result.setReadOnly(type == NodeType.SLAVE && config.getReadMode() != ReadMode.MASTER); return result; }
Example #14
Source File: WeightedRoundRobinBalancerTest.java From redisson with Apache License 2.0 | 4 votes |
@Test(expected = WriteRedisConnectionException.class) public void testUseMasterForReadsIfNoConnectionsToSlaves() throws IOException, InterruptedException { RedisProcess master = null; RedisProcess slave = null; RedissonClient client = null; try { master = redisTestInstance(); slave = redisTestInstance(); Map<String, Integer> weights = new HashMap<>(); weights.put(master.getRedisServerAddressAndPort(), 1); weights.put(slave.getRedisServerAddressAndPort(), 2); Config config = new Config(); config.useMasterSlaveServers() .setReadMode(ReadMode.SLAVE) .setMasterAddress(master.getRedisServerAddressAndPort()) .addSlaveAddress(slave.getRedisServerAddressAndPort()) .setLoadBalancer(new WeightedRoundRobinBalancer(weights, 1)); client = Redisson.create(config); // To simulate network connection issues to slave, stop the slave // after creating the client. Cannot create the client without the // slave running. See https://github.com/mrniko/redisson/issues/580 slave.stop(); RedissonClient clientCopy = client; assertThat(clientCopy.getBucket("key").get()).isNull(); } finally { if (master != null) { master.stop(); } if (slave != null) { slave.stop(); } if (client != null) { client.shutdown(); } } }