java遍歷讀取整個(gè)redis數(shù)據(jù)庫(kù)實(shí)例
redis提供了靈活的數(shù)據(jù)查詢方式,最牛的就是key的搜索支持正則表達(dá)式。
jedis.keys(“*”);表示搜索所有key
jedis.keys(“abc*”)表示搜索開頭為abc的key數(shù)據(jù)
遍歷了key就能遍歷到value。
其實(shí)就是一個(gè)set
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 運(yùn)算
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
}
}
相關(guān)文章
Java編程Webservice指定超時(shí)時(shí)間代碼詳解
這篇文章主要介紹了Java編程Webservice指定超時(shí)時(shí)間代碼詳解,簡(jiǎn)單介紹了webservice,然后分享了通過使用JDK對(duì)Webservice的支持進(jìn)行Webservice調(diào)用實(shí)現(xiàn)指定超時(shí)時(shí)間完整示例,具有一定借鑒價(jià)值,需要的朋友可以參考下。2017-11-11
Java?Shell?springboot通用Shell啟動(dòng)腳本方式
這篇文章主要介紹了Java?Shell?springboot通用Shell啟動(dòng)腳本方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-05-05
spring+srpingmvc+hibernate實(shí)現(xiàn)動(dòng)態(tài)ztree生成樹狀圖效果
這篇文章主要介紹了spring+srpingmvc+hibernate動(dòng)態(tài)ztree生成樹狀圖效果,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-11-11
Java如何實(shí)現(xiàn)簡(jiǎn)單后臺(tái)訪問并獲取IP
這篇文章主要介紹了Java如何實(shí)現(xiàn)簡(jiǎn)單后臺(tái)訪問并獲取IP,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-10-10
springBoot+webMagic實(shí)現(xiàn)網(wǎng)站爬蟲的實(shí)例代碼
這篇文章主要介紹了springBoot+webMagic實(shí)現(xiàn)網(wǎng)站爬蟲的實(shí)例代碼,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-05-05
兩種Eclipse部署動(dòng)態(tài)web項(xiàng)目方法
這篇文章主要介紹了兩種Eclipse部署動(dòng)態(tài)web項(xiàng)目方法,需要的朋友可以參考下2015-11-11

