Created
March 1, 2019 09:39
-
-
Save DazWorrall/1c1d3d1ddfb0dc41b769f0024c1dd77c to your computer and use it in GitHub Desktop.
Revisions
-
DazWorrall created this gist
Mar 1, 2019 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ require 'redis' require 'active_support/time' redis = Redis.new # members are added with a score that is a timestamp of when they should expire redis.zadd('test-sset', 10.minutes.from_now.to_i, 'app1') # let's add one in the past so we can test some more redis.zadd('test-sset', 10.minutes.ago.to_i, 'app2') puts 'all apps' puts redis.zrange('test-sset', 0, -1) # app1, app2 puts 'active apps' puts redis.zrangebyscore('test-sset', Time.now.utc.to_i, '+inf') #app1 puts 'expiring old apps' puts redis.zremrangebyscore('test-sset', '-inf', Time.now.utc.to_i) # returns # of expired elements puts 'all remaining apps' puts redis.zrange('test-sset', 0, -1) # app1