Write by Yin Mingjun, quote please specify.
The article was originally sent in the Baidu space, Baidu said there are problems, had to send to CSDN.
The previous article described how to use Sentinel to create a highly available master and standby, but if there is no reliable client support, Sentinel usage can be cumbersome and Jedis. The latest version of Jedis (2.4.2) has started to support Sentinel.
Let's briefly explain how to use it.
Create a sentinel cluster by first installing the Sentinel mode in front of Redis (note that the example in this article is a Redis service that is released with 127.0.0.1, to be replaced with an external IP), and then build the Java project and introduce the Jedis 2.4.2, you can then use Sentinel as follows:
public class App
{public
static void Main (string[] args)
{
set<string> sentinels = new Hashset< ; String> ();
Sentinels.add ("172.18.18.207:26379");
Jedissentinelpool pool = new Jedissentinelpool ("MyMaster", Sentinels);
Jedis Jedis = Pool.getresource ();
Jedis.set ("Jedis", "Jedis");
Pool.returnresource (Jedis);
}
}
Run again and you'll see the Jedis key value in Redis on port 6500.
ubuntu@ubuntu12:~$ Redis-cli-p 6500
127.0.0.1:6500> keys *
1) "Foo"
2) "Jedis"
127.0.0.1:6500> Get Jedis
"Jedis"
is not surprisingly simple.