Benchmarking Redis Map and INCR Operations with FunTester
This article demonstrates how to use the FunTester framework to benchmark Redis hash (map) and INCR commands, detailing the test design, Java code implementation, multithreaded execution, and summarizing the observed performance results.
Map Test
Idea
Design a simple scenario where a key‑value pair is stored in a Redis hash (map), verified for correctness, and then deleted. The case serves as an illustrative example rather than a specific production use case.
Test case
import com.funtester.base.constaint.FixedThread
import com.funtester.base.constaint.ThreadBase
import com.funtester.config.Constant
import com.funtester.db.redis.RedisBase
import com.funtester.frame.execute.Concurrent
import com.funtester.utils.StringUtil
import java.util.concurrent.atomic.AtomicInteger
/**
* FunTester testing framework, Redis benchmark, map
*/
class RedisList05 extends RedisBase {
static AtomicInteger num = new AtomicInteger(0)
static RedisBase drive
public static void main(String[] args) {
String host = "FunTester"
int port = 6379
drive = new RedisBase(host, port)
drive.index = 2
int times = 200
int thread = 10
Constant.RUNUP_TIME = 0
def tester = new FunTester(times)
def task = new Concurrent(tester, thread, "redis测试实践之map")
task.start()
drive.close()
}
private static class FunTester extends FixedThread {
String key = DEFAULT_STRING + num.getAndIncrement()
FunTester(int limit) {
super(null, limit, true)
}
@Override
protected void doing() throws Exception {
def k = "f" + getNanoMark()
def v = StringUtil.getString(10000)
drive.hset(key, k, v)
def hget = drive.hget(key, k)
if (v != hget) fail()
drive.hdel(key, k)
}
@Override
ThreadBase clone() {
return new FunTester(this.limit)
}
}
}Test result
Detailed performance numbers and charts are omitted for brevity.
INCR Test
Idea
Multiple threads concurrently increment a single Redis key using the INCR command to verify thread‑safety; a second variant with both increment and decrement is mentioned but not demonstrated.
Test case
import com.funtester.base.constaint.FixedThread
import com.funtester.base.constaint.ThreadBase
import com.funtester.config.Constant
import com.funtester.db.redis.RedisBase
import com.funtester.frame.execute.Concurrent
import java.util.concurrent.atomic.AtomicInteger
/**
* FunTester testing framework, Redis benchmark, incr
*/
class RedisList06 extends RedisBase {
static AtomicInteger num = new AtomicInteger(0)
static RedisBase drive
public static void main(String[] args) {
String host = "FunTester"
int port = 6379
drive = new RedisBase(host, port)
drive.index = 2
int times = 200
int thread = 20
Constant.RUNUP_TIME = 0
def tester = new FunTester(times)
def task = new Concurrent(tester, thread, "redis测试实践之INCR")
task.start()
drive.close()
}
private static class FunTester extends FixedThread {
String listName = DEFAULT_STRING + num.getAndIncrement()
FunTester(int limit) {
super(null, limit, true)
}
@Override
protected void doing() throws Exception {
drive.incr("FunTester1123")
}
@Override
ThreadBase clone() {
return new FunTester(this.limit)
}
}
}Test result
Detailed performance numbers and charts are omitted for brevity.
Conclusion
The FunTester framework series for Redis performance testing is now complete; the next planned series will apply the framework to MySQL benchmarking.
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.
