Permalink
Browse files

use pipeling for redis lookups - ~2x faster!

  • Loading branch information...
1 parent 4cf3b8d commit ce47b370302e27a8fdf411a419a84dbf08135fda @igrigorik committed Mar 31, 2011
Showing with 13 additions and 5 deletions.
  1. +13 −5 lib/bloomfilter/redis.rb
View
@@ -18,24 +18,32 @@ def initialize(opts = {})
end
def insert(key, ttl=nil)
- indexes_for(key) { |idx| @db.setbit @opts[:namespace], idx, 1 }
+ @db.pipelined do
+ indexes_for(key) { |idx| @db.setbit @opts[:namespace], idx, 1 }
+ end
end
alias :[]= :insert
def include?(*keys)
keys.each do |key|
- indexes_for(key) do |idx|
- return false if @db.getbit(@opts[:namespace], idx).zero?
+ result = @db.pipelined do
+ indexes_for(key) do |idx|
+ @db.getbit(@opts[:namespace], idx)
+ end
end
+
+ return false if result.include?(0)
end
true
end
alias :key? :include?
def delete(key)
- indexes_for(key) do |idx|
- @db.setbit @opts[:namespace], idx, 0
+ @db.pipelined do
+ indexes_for(key) do |idx|
+ @db.setbit @opts[:namespace], idx, 0
+ end
end
end

0 comments on commit ce47b37

Please sign in to comment.