I need to generate millions of redis data
with a value size of 1kb
to a redis cluster, assuming that only the value type is string. I learned about two options, the first one is to use debug populate
to generate a specific amount of data, but it does not set the value size
.
127.0.0.1:6379> DEBUG POPULATE 1000000
OK
The second one is to use shell to call redis-cli
and I don't know how to generate 1kb data
for i in `seq 1000000`;
do
redis-cli SET key$i val$i ;
done
I am newbie on this. How do I meet the demand? I really appreciate any help with this.
Try the solution based on Mark Setchell.
#!/bin/bash
# Generate around 32kB (+ around 33% base64 overhead) of random characters
stuff=$(head -c 32000 /dev/urandom | base64)
# Set 100,000 keys to 1kB strings, e.g. SET key32 A87H34..PHNQZ
for ((i=0;i<100;i++)) ; do
echo SET key$i ${stuff:RANDOM:1024}
done | redis-cli -p 6371 -c --pipe
The following error occurs using the above code
sh fake_data_test.sh
All data transferred. Waiting for the last reply...
MOVED 13252 172.20.0.33:6379
MOVED 9189 172.20.0.32:6379
ERR syntax error
ERR syntax error
MOVED 13120 172.20.0.33:6379
MOVED 9057 172.20.0.32:6379
ERR syntax error
ERR syntax error
...
ERR syntax error
Last reply received from server.
errors: 100, replies: 100
Then I thought whether it was a value formatting issue, so I put it in double quotes echo SET key$i "${stuff:RANDOM:1024}"
sh fake_data_test.sh
All data transferred. Waiting for the last reply...
MOVED 13252 172.20.0.33:6379
ERR unknown command `kpshETtdvDBpL1BYimJl3FkpuJMom/heyj02qJwUGUCQvSZODHXHwNGodfVyIR6sWSv8agjlGMtl`, with args beginning with:
...
ERR unknown command `UmBAaiwqgB25mSDhsK7qrveXhJV0cJCBRaz`, with args beginning with:
MOVED 9189 172.20.0.32:6379
ERR unknown command ERR unknown command `gRolxGVLUVbnU5I/ykaXPCA+0Nev`, with args beginning with:
Last reply received from server.
errors: 1397, replies: 1428
for ((i=0;i<100;i++)) ; do
redis-cli -p 6371 -c SET key$i "${stuff:RANDOM:1024}"
done
// All output ok
I don't know if I'm using pipe in the wrong way
Note: OS is centos7. redis cluster creation via docker-compose. images is redis:4.0.11-alpine