Benchmarking Redis Key‑Value Inserts with FunTester: Java & Groovy Test Cases
This article walks through a practical performance test for continuously adding key‑value pairs to Redis using the FunTester framework, detailing the test design, Java and Groovy implementations, execution logs, result metrics, and key takeaways for future Redis benchmarking.
The author builds on a previous FunTester Redis stress‑test preparation and moves into the implementation phase, focusing on a test case that repeatedly inserts key‑value entries into Redis.
Test Design
The approach mirrors earlier stress tests: a single thread repeatedly performs an operation, a thread pool runs multiple tasks concurrently, and the framework aggregates the results. Connection handling follows a pattern similar to HTTP connection pooling—acquire a connection, execute operations, then release it.
Java Test Case
/**
* redis添加key-value性能测试用例
*/
public class RedisPerTest extends SourceCode {
public static final String host = "FunTester隐藏地址";
public static final int port = 6379;
public static RedisBase drive;
public static void main(String[] args) {
drive = new RedisBase(host, port);
drive.index = 1;
RUNUP_TIME = 0;
drive.set("fun" + StringUtil.getString(10), "FunTester", 100);
FunTester funTester = new FunTester(100);
Concurrent concurrent = new Concurrent(funTester, 400, "redis添加key-value性能测试用例");
concurrent.start();
drive.close();
}
private static class FunTester extends FixedThread {
public FunTester(int limit) {
super(null, limit, true);
}
@Override
protected void doing() throws Exception {
drive.set("fun" + StringUtil.getString(10), "FunTester", 100);
}
@Override
public ThreadBase clone() {
return new FunTester(limit);
}
}
}The Groovy version follows the same logic and is omitted for brevity.
Console Output
INFO-> 当前用户:oker,工作目录:/Users/oker/IdeaProjects/funtester/,系统编码格式:UTF-8,系统Mac OS X版本:10.16
INFO-> redis连接池IP:106.53.152.151,端口:6379,超时设置:5000
INFO-> =========预热完成,开始测试!=========
INFO-> Redis测试进度:▍▍▍▍▍▍▍▍▍ 14% ,当前QPS: 1605
... (log lines omitted) ...
INFO-> 总计400个线程,共用时:26.252 s,执行总数:38,905,错误数:0,失败数:0
INFO-> 数据保存成功!文件名:/Users/oker/IdeaProjects/funtester/long/data/Redis测试021516_400
{ "rt":267, "failRate":0.0, "threads":400, "deviation":"1.08%", "errorRate":0.0, "executeTotal":38905, "qps2":1481.9823251561786, "total":38905, "qps":1498.1273408239701, "startTime":"2021-09-02 15:16:35", "endTime":"2021-09-02 15:17:01", "mark":"Redis测试021516", "table":"..." }Conclusion
The test demonstrates a straightforward way to benchmark Redis insert performance using FunTester. The author plans to extend the work to multi‑operation scenarios, set‑type values, and Redis atomic increments. Although real‑world projects rarely test Redis directly, maintaining such skills can be valuable when the need arises.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
