-
-
Save Orphist/9182371 to your computer and use it in GitHub Desktop.
redis sets
This file contains 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 'hiredis' | |
require "redis/connection/hiredis" | |
require 'redis' | |
$redis = Redis.new(:host => "127.0.0.1", :port => 6379) | |
unless $redis.exists 'SanDiego' | |
puts "Creating 35 million entries" | |
start = Time.now | |
idx = 0 | |
3_500.times do |n| | |
$redis.pipelined do | |
10_000.times {|m| $redis.setbit('SanDiego', idx, rand(2)); idx += 1} | |
end | |
end | |
finish = Time.now | |
puts "took #{finish - start} to create 35M entries" | |
end | |
100.times do | |
user_id = rand(35_000_000) | |
subscribed = $redis.getbit('SanDiego', user_id) == 1 | |
puts "User #{user_id} is #{subscribed ? 'subscribed' : 'not yet subscribed'}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment