4. Use of Redis and Java

Source: Internet
Author: User
Tags redis cluster redis server


This article mainly explains how to operate Redis in Java.


Using Java to connect Redis requires the introduction of a corresponding Jedis jar package.


Java connects to a single redis, Redis connection pool, Redis cluster (explained later)


//Connection Single Redis server   

Jedis jedis= New Jedis  ("192.168.0.100", 6379);

//Connection Redis thread Pool   

Redis Configuration Objects

Jedispoolconfig config = New jedispoolconfig ();

// maximum number of available Redis connection instances

Config.setmaxactive (8);

//maximum idle (idle) Number of Jedis instances, the default value is also 8 Config.setmaxidle (8);

//The maximum time to wait for an available connection, in units milliseconds , the default value is-1, which means that never times out. If the waiting time is exceeded, the jedisconnectionexception is thrown directly;

Config.setmaxwait (10000);

Whether validate operations are performed in advance when a Jedis instance is borrow, and if true, the resulting Jedis instances are available;

Config.settestonborrow (Test_on_borrow);

Redis Connection Pool Object

Jedispool Jedispool = New jedispool(config, "192.168.0.100", "6379", "10000");

Jedis resource = jedispool.getresource ();

Releasing Jedis Resources

Jedispool. Returnresource (Jedis) ;



The string, Hash, List, Set, Zset, respectively, are explained in turn


One, string manipulation



Second,the hash operation


4. Use of Redis and Java

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.