package com.lxw1234.redis;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.Pipeline;
import redis.clients.jedis.Response;
public class Test {
public static void main(String[] args) throws Exception {
Jedis redis = new Jedis("127.0.0.1", 6379, 400000);
Map<String,String> data = new HashMap<String,String>();
redis.select(8);
redis.flushDB();
//hmset
long start = System.currentTimeMillis();
//直接hmset
for (int i=0;i<10000;i++) {
data.clear();
data.put("k_" + i, "v_" + i);
redis.hmset("key_" + i, data);
}
long end = System.currentTimeMillis();
System.out.println("dbsize:[" + redis.dbSize() + "] .. ");
System.out.println("hmset without pipeline used [" + (end - start) / 1000 + "] seconds ..");
redis.select(8);
redis.flushDB();
//使用pipeline hmset
Pipeline p = redis.pipelined();
start = System.currentTimeMillis();
for (int i=0;i<10000;i++) {
data.clear();
data.put("k_" + i, "v_" + i);
p.hmset("key_" + i, data);
}
p.sync();
end = System.currentTimeMillis();
System.out.println("dbsize:[" + redis.dbSize() + "] .. ");
System.out.println("hmset with pipeline used [" + (end - start) / 1000 + "] seconds ..");
//hmget
Set<String> keys = redis.keys("*");
//直接使用Jedis hgetall
start = System.currentTimeMillis();
Map<String,Map<String,String>> result = new HashMap<String,Map<String,String>>();
for(String key : keys) {
result.put(key, redis.hgetAll(key));
}
end = System.currentTimeMillis();
System.out.println("result size:[" + result.size() + "] ..");
System.out.println("hgetAll without pipeline used [" + (end - start) / 1000 + "] seconds ..");
//使用pipeline hgetall
Map<String,Response<Map<String,String>>> responses = new HashMap<String,Response<Map<String,String>>>(keys.size());
result.clear();
start = System.currentTimeMillis();
for(String key : keys) {
responses.put(key, p.hgetAll(key));
}
p.sync();
for(String k : responses.keySet()) {
result.put(k, responses.get(k).get());
}
end = System.currentTimeMillis();
System.out.println("result size:[" + result.size() + "] ..");
System.out.println("hgetAll with pipeline used [" + (end - start) / 1000 + "] seconds ..");
redis.disconnect();
}
}
dbsize:[10000] .. hmset without pipeline used [243] seconds .. dbsize:[10000] .. hmset with pipeline used [0] seconds .. result size:[10000] .. hgetAll without pipeline used [243] seconds .. result size:[10000] .. hgetAll with pipeline used [0] seconds ..
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有