Skip to content

Instantly share code, notes, and snippets.

@tysonmote
Last active August 29, 2015 14:06
Show Gist options
  • Select an option

  • Save tysonmote/883d813f94ca98f7a8fa to your computer and use it in GitHub Desktop.

Select an option

Save tysonmote/883d813f94ca98f7a8fa to your computer and use it in GitHub Desktop.

Start master in another window with redis-server master.conf

Fill master server with 10% keys that will expire very soon and 90% keys that wont expire for a while:

% ruby fill.rb | redis-cli --pipe -p 9998
All data transferred. Waiting for the last reply...
Last reply received from server.
errors: 0, replies: 1000002

Wait a few seconds and then start slave in another window with redis-server slave.conf

Verify that the slave expunged all low-TTL keys prematurely:

% redis-cli -p 9998 info | grep db0
db0:keys=999800,expires=999800,avg_ttl=19697029
% redis-cli -p 9999 info | grep db0
db0:keys=900001,expires=900001,avg_ttl=0
def send(*cmd)
proto = []
proto << "*#{cmd.length}\r\n"
cmd.each do |arg|
proto << "$#{arg.to_s.bytesize}\r\n"
proto << "#{arg}\r\n"
end
STDOUT.write( proto.join( "" ) )
end
send( "FLUSHALL" )
(0...10_000).each do |n|
send( "SETEX", n, 5, "x" )
end
(10_000..1_000_000).each do |n|
send( "SETEX", n, 21600, "x" )
end
port 9998
dbfilename master.rdb
dir ./
port 9999
dbfilename slave.rdb
dir ./
slaveof localhost 9998
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment