Use of Redis (Java uses Jedis clients to connect to Redis)

Source: Internet
Author: User

One. Add dependency

<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.6.0</version>
</dependency>

Two. Example:

1. Create Jedis Object Operations Redis

Constructing Jedis objects
Jedis Jedis = new Jedis ("127.0.0.1", 6379);
Adding data to Redis
Jedis.set ("MyTest", "123bin");
Reading data from Redis
String value = Jedis.get ("mytest"); System.out.println (value);
Close connection
Jedis.close (); 2. Build connection pool configuration information by connecting pooling//
Jedispoolconfig jedispoolconfig = new Jedispoolconfig ();
Set maximum number of connections
Jedispoolconfig.setmaxtotal (50); Building Connection Pools
Jedispool Jedispool = new Jedispool (jedispoolconfig, "127.0.0.1", 6379); Getting connections from the connection pool
Jedis Jedis = Jedispool.getresource (); Reading data
System.out.println (Jedis.get ("mytest")); Returning the connection to the connection pool
Jedispool.returnresource (Jedis); Releasing the connection pool
Jedispool.close ();//Note: actually in use. The connection pool cannot be closed, or the connection pool cannot be used once the execution is complete

Use of Redis (Java uses Jedis clients to connect to 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.