Using Redis for Java

Source: Internet
Author: User

The caching framework of 1.redis and Memecache is divided into server side and client.

We use in the project, the equivalent of the client, to introduce the client to use the Redis jar package

    • First you need to download the driver package, download the Jedis.jar, and make sure to download the latest driver package.

2.redis is connected via Jedis, so instantiate the Jedis, then connect the server to

Jedis=newJedis("localhost");

3.redis Store list data
JedisJedis= New Jedis("LocalHost"); System.Out.println("Connection to Server sucessfully"); Storing data in a listJedis.Lpush("Tutorial-list", "Redis");Jedis.Lpush("Tutorial-list", "Mongodb");Jedis.Lpush("Tutorial-list", "Mysql"); Get the stored data and output List<String>List=Jedis.Lrange("Tutorial-list", 0 ,5);For  (int i=0; i<list.  Size(); i+ +) { System.  Out.  println("Stored string in Redis::"+list. ) Get(i));  }< /c15> 
4.redis get the key value, enter
 JedisJedis= New Jedis("LocalHost"); System.Out.println("Connection to Server sucessfully"); Get the data and output List<String>List=Jedis.Keys("*" for (int I =0; I< list. I++)  { system.. Println ( "List of stored keys::" +listget (i               /span>                 

Java uses 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.