From abff264000a9926bb7b96172fd49dae3b804c4e0 Mon Sep 17 00:00:00 2001 From: ShooterIT Date: Mon, 18 May 2020 18:18:20 +0800 Subject: [PATCH] Redis Benchmark: generate random test data The function of generating random data is designed by antirez. See #7196. --- src/redis-benchmark.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/redis-benchmark.c b/src/redis-benchmark.c index 2df41580b..19c72551c 100644 --- a/src/redis-benchmark.c +++ b/src/redis-benchmark.c @@ -1269,6 +1269,17 @@ static void updateClusterSlotsConfiguration() { pthread_mutex_unlock(&config.is_updating_slots_mutex); } +/* Generate random data for redis benchmark. See #7196. */ +static void genBenchmarkRandomData(char *data, int count) { + static uint32_t state = 1234; + int i = 0; + + while (count--) { + state = (state*1103515245+12345); + data[i++] = '0'+((state>>16)&63); + } +} + /* Returns number of consumed options. */ int parseOptions(int argc, const char **argv) { int i; @@ -1619,7 +1630,7 @@ int main(int argc, const char **argv) { /* Run default benchmark suite. */ data = zmalloc(config.datasize+1); do { - memset(data,'x',config.datasize); + genBenchmarkRandomData(data, config.datasize); data[config.datasize] = '\0'; if (test_is_selected("ping_inline") || test_is_selected("ping"))