In this post I would share some commands to help you get started quickly with Redis and Jedis provider.
"Redis Sentinel is a distributed system:
Sentinel itself is designed to run in a configuration where there are multiple
Sentinel processes cooperating together. The advantages of having multiple
Sentinel processes cooperating are the following:
1. Failure detection is performed when multiple Sentinels agree about the
fact a given master is no longer available. This lowers the probability of
false positives.
2. Sentinel works even if not all the Sentinel processes are working,
making the system robust against failures. There is no fun in having a
fail over system which is itself a single point of failure, after all."
Starting a redis server in sentinel mode:
redis-server /path/to/sentinel.conf --sentinel
Setting a sentinel option:
sentinel <option_name> <master_name> <option_value>
Setting a sentinel master:
sentinel monitor <master-group-name> <ip> <port> <quorum>
All these configuration should be placed in "sentinel.conf":
sentinel monitor mymaster 127.0.0.1 6379 2
sentinel down-after-milliseconds mymaster 60000
sentinel failover-timeout mymaster 180000
sentinel parallel-syncs mymaster 1
First config row - Sentinel configuration INCLUDING master (slaves are auto-discovered).
The last value ("2") is the quorum number (number of Sentinels that need to agree about the fact the master is not reachable).
Last config row - parallel-syncs is the number of slaves which will participate in configuring the new master after failover.
(Bigger number = Faster sync, but if the data is old in some of them, it might be written to the new master)
Jedis Java Provider
Common Pool Constructors:
JedisPool(Config poolConfig, String host)
JedisPool(Config poolConfig, String host, int host)
JedisSentinelPool(String masterName, Set<String> sentinels)
Parameters:
masterName – Name of the sentinel master given in "sentinel monitor" line in
"sentinel.conf". In the example above it's "mymaster".
sentinels - Entire set of IP addresses of all sentinels (Master + Slaves).
For Example:
HashSet<String> sentinels = new HashSet<String>();
sentinels.add("127.0.0.1:1234");
JedisSentinelPool jedisPool = new JedisSentinelPool("mymaster", sentinels);
Get key example:
Jedis jedis = jedisPool.getResource();
String result = jedis.get(key);
jedisPool.returnResource(jedis);
Set key example:
Jedis jedis = jedisPool.getResource();
jedis.setex(key,secondsTillExpired, value); // setting a key and a value with expiration
jedisPool.returnResource(jedis);
CLUSTER
Redis Cluster provides a way to run a Redis installation where data is automatically
sharded across multiple Redis nodes.