Created
February 1, 2017 09:06
-
-
Save antirez/6f4ab9f084d14479dab095b81597af2b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'redis' | |
Chars=('A'..'Z').to_a | |
def g(prefix) | |
choice = rand(9) | |
if (choice == 0) | |
# Values around this size stress the cascading update. | |
len = [252,250].shuffle.first | |
prefix += rand(1000000).to_s | |
string = prefix + ("A"*(len-prefix.length)) | |
elsif (choice == 1) | |
string = prefix+(rand(10000000).to_s) | |
elsif (choice == 2) | |
string = rand(20) | |
elsif (choice == 3) | |
string = rand(2**32) | |
elsif (choice == 4) | |
string = rand(2**64) | |
elsif (choice == 5) | |
string = ["a","b","c","d","e","f","g"].shuffle.first | |
elsif (choice == 6) | |
string = "" | |
elsif (choice == 7 || choice == 8) | |
len = rand(32) | |
len = rand(256) if (rand() < 0.1) | |
len = rand(1024) if (rand() < 0.1) | |
string = "" | |
len.times { | |
if choice == 7 | |
c = Chars.shuffle.first | |
else | |
c = rand(256).chr | |
end | |
string << c | |
} | |
string | |
end | |
end | |
def get_key(prefix) | |
return g(prefix) | |
end | |
def get_value(prefix) | |
return g(prefix) | |
end | |
def stress_hash_api(r) | |
r.del(:hash) | |
keys = [] | |
vals = [] | |
size = rand(2000) | |
r.pipelined { | |
size.times { | |
keys << get_key("key") | |
vals << get_value("val") | |
r.hset(:hash,keys[-1],vals[-1]); | |
} | |
size.times { | |
r.hset(:hash,keys.shuffle.first,get_value("v")) | |
r.hset(:hash,get_key("k"),get_value("v")) | |
# Force an encoding check | |
r.hdel(:hash,:nonexisting) | |
} | |
size.times { | |
r.hset(:hash,keys.shuffle.first,"a") if (rand()<0.1) | |
r.hdel(:hash,keys.shuffle.first) if (rand()<0.1) | |
r.hset(:hash,keys.shuffle.first,get_value("v")) if (rand()<0.1) | |
r.hset(:hash,get_key("k"),get_value("v")) if (rand()<0.1) | |
# Force an encoding check | |
r.hdel(:hash,:nonexisting) | |
} | |
} | |
all = r.hgetall(:hash).to_s | |
if all.index("\xff") != nil | |
puts "FF byte detected in element" | |
end | |
end | |
def stress_list_api(r) | |
r.del(:list) | |
elements = [] | |
r.pipelined { | |
100.times { | |
elements << g("ele") | |
r.rpush(:list,elements[-1]) | |
} | |
100.times { | |
r.lrem(:list,1,elements.shuffle.first) if (rand()<0.5) | |
r.linsert(:list,:after,elements.shuffle.first,g("ele")) if (rand()<0.5) | |
} | |
} | |
all = r.lrange(:list,0,-1).to_s | |
if all.index("\xff") != nil | |
puts "FF byte detected in element" | |
end | |
end | |
r = Redis.new() | |
r.config(:set,"hash-max-ziplist-value",20000) | |
r.config(:set,"hash-max-ziplist-entries",20000) | |
while true | |
stress_list_api(r) | |
# stress_hash_api(r) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment