Java traversal reads the entire Redis database instance _java

Source: Internet
Author: User
Tags redis

Redis provides a flexible way of querying data, and the most bull is the search for key to support regular expressions.

Jedis.keys ("*") means search for all key
Jedis.keys ("abc*") indicates the search for key data beginning with ABC

The key is traversed to the value.

is actually a set

Copy Code code as follows:

Redisdo rd = new redisdo ();
Rd.open ();
Set s = Rd.jedis.keys ("*");
Iterator it = S.iterator ();


while (It.hasnext ()) {
String key = (string) it.next ();
String value = Rd.jedis.get (key);
SYSTEM.OUT.PRINTLN (key + value);
}
Rd.close ();

RD's algorithm for integrated Redis operations
Copy Code code as follows:

Package Com.javaer.click.way;

Import Redis.clients.jedis.Jedis;
Import Redis.clients.jedis.JedisPool;
Import Redis.clients.jedis.JedisPoolConfig;
Import redis.clients.jedis.exceptions.JedisConnectionException;

public class Redisdo {
Public Jedis Jedis;

public void Close () {
Jedis.disconnect ();
Jedis = null;
}

Public Jedis open () {
Jedispoolconfig config = new Jedispoolconfig ();

Config.setmaxactive (100);

Config.setmaxidle (20);

Config.setmaxwait (1000l);
Jedispool Pool;
Pool = new Jedispool (config, "xxxxxxxx.xx.xx.xx", 6379);

Boolean borroworoprsuccess = true;
try {
Jedis = Pool.getresource ();
Do Redis opt by instance
catch (Jedisconnectionexception e) {
Borroworoprsuccess = false;
if (Jedis!= null)
Pool.returnbrokenresource (Jedis);

finally {
if (borroworoprsuccess)
Pool.returnresource (Jedis);
}
Jedis = Pool.getresource ();
return Jedis;
}
/**
* @param args
*/
public static void Main (string[] args) {
TODO auto-generated Method Stub

}

}

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.