Home » NoSQL » The Redis+linux cluster (five)

The Redis+linux cluster (five)

one, what is the redis cluster:
?
1, the Redis cluster is a high-level version of Redis that implements distributed and allows single point failures.

2, the Redis cluster is not the most important or central node, and the most important goal of this release is

Design a linear scalable (optionally add and delete nodes) function.

3, Redis clusters, in order to data consistency, may sacrifice part of the functionality that allows for single point failures,

Therefore, when the network fails and the node fails, the system will try its best to ensure the consistency and validity of the data.

(here we consider node faults as a special case of network failures)

To solve the problem of single point of failure, we need both masters and slaves.

Even if the master node (Master) is functionally consistent with the slave node (slave),

They are even deployed on the same server, and the node is only used to replace the fault master node.

Actually, it should be said that if there is no read-after-write from the node (write and immediately read the data,

To avoid the need for data in the data synchronization process, then only the read-only operation is accepted from the node.


two, simple simulation cluster

1, improve the redisproperties and add another machine with the redis service to it.

Note: the two redis here are all the same, just the IP is different.

Redis.pool.maxActive=1024

Redis.pool.maxIdle=200

Redis.pool.maxWait=1000

Redis.pool.testOnBorrow=true

Redis.pool.testOnReturn=true

Redis.ip=192.168.14.215

Redis.port=6379

Redis.ip2=192.168.14.137


2 uses ShardedJedisPool to create the pool, before reading the configuration of redis with JedisShardInfo and coexisting with a List
The back is the same as using the pool
Specific code:
Import java.util.LinkedList;
Import java.util.List;
Import java.util.ResourceBundle;
Import redis.clients.jedis.JedisPoolConfig;
Import redis.clients.jedis.JedisShardInfo;
Import redis.clients.jedis.ShardedJedis;
Import redis.clients.jedis.ShardedJedisPool;
Public, class, Test1 {
Private static ShardedJedisPool pool;
Static {
ResourceBundle bundle = ResourceBundle.getBundle ("redis2");
If (bundle = = null) {
Throw new IllegalArgumentException ("[redis.properties] is not found!");
}
JedisPoolConfig config = new, JedisPoolConfig ();
Config.setMaxTotal (Integer.valueOf (bundle.getString ("redis.pool.maxActive"));
Config.setMaxIdle (Integer.valueOf (bundle.getString ("redis.pool.maxIdle"));
Config.setMaxWaitMillis (Long.valueOf (bundle.getString ("redis.pool.maxWait"));
Config.setTestOnBorrow (Boolean.valueOf (bundle.getString ("redis.pool.testOnBorrow"));
Config.setTestOnReturn (Boolean.valueOf (bundle.getString ("redis.pool.testOnReturn"));
JedisShardInfo, jedisShardInfo1 = new, JedisShardInfo (bundle.getString ("redis.ip"), Integer.valueOf (bundle.getString ("redis.port"));
JedisShardInfo, jedisShardInfo2 = new, JedisShardInfo (bundle.getString ("redis.ip2"), Integer.valueOf (bundle.getString ("redis.port"));
List list = new, LinkedList ();
List.add (jedisShardInfo1);
List.add (jedisShardInfo2);
Pool = new, ShardedJedisPool (config, list);
//pool = new, JedisPool (config, bundle.getString ("redis.ip"), Integer.valueOf (bundle.getString ("redis.port"));
}
Public, static, void, main (String[], args) {
/ / Jedis jedis=new Jedis ("192.168.15.215");
//Jedis jedis = pool.getResource ();
/ / get an Jedis object from the pool
ShardedJedis jedis = pool.getResource ();
String keys = "name"";
Jedis.del (keys);
Jedis.set (keys, YJL);
String value = jedis.get (keys);
System.out.println (value);
Pool.returnBrokenResource (jedis); / / release connection pool
}
}

Latest