Accessing Redis's Sentinel using Jedis

Source: Internet
Author: User
Tags redis


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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.