jedis查看redis数据库多少条数据
答案:1 悬赏:20 手机版
解决时间 2021-02-05 02:26
- 提问者网友:溺爱和你
- 2021-02-04 04:42
jedis查看redis数据库多少条数据
最佳答案
- 五星知识达人网友:天凉才是好个秋
- 2021-02-04 04:49
redis提供了灵活的数据查询方式,最牛的就是key的搜索支持正则表达式。
jedis.keys(“*”);表示搜索所有key
jedis.keys(“abc*”)表示搜索开头为abc的key数据
遍历了key就能遍历到value。
其实就是一个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 运算
复制代码代码如下:
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;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
jedis.keys(“*”);表示搜索所有key
jedis.keys(“abc*”)表示搜索开头为abc的key数据
遍历了key就能遍历到value。
其实就是一个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 运算
复制代码代码如下:
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;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯