redis如何循环读出数据库

1391
2021/1/21 13:39:37
栏目: 云计算
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

redis如何循环读出数据库

redis循环读出数据库的示例:

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的算法为集成redis 运算,代码:

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

}

}

辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读: php与数据库交互的方法有哪些