Redis using the Java operation Redis

Source: Internet
Author: User

1. Working with Redis in Java requires the use of the Jedis plugin and Linux to turn on the relevant firewall.

To restart the Firewall service:

2. Create a new MAVEN project:

3. Add Project Dependencies:

<dependency>        <groupId>redis.clients</groupId>        <artifactid>jedis</artifactid >        <version>2.9.  0</version>    </dependency>

4. Use the Redis tool to test if you can connect to Redis under Windows

5. Add a code test:

 Public Static voidMain (string[] args) {//To create a Jedis object to connect to a Redis databaseJedis Jedis =NewJedis ("192.168.80.162",6379); //gets the value of the specified keyString name= Jedis.Get("name"); if(name==NULL){            //sets the value for the specified keyJedis.Set("name","Siggy"); } System. out. println ("name=="+jedis.Get("name")); Jedis.setnx ("Sex","female"); System. out. println ("sex="+jedis.Get("Sex")); //set Multiple valuesJedis.mset ("bname","Java","Bprice"," -","Bauthor","Sun"); System. out. println (Jedis.mget ("bname","Bprice","Bauthor")); }

Redis using the Java operation Redis

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.