Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Commit

Permalink
Added very basic redis pipelining functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
willcosgrove committed Nov 21, 2011
1 parent 0500c64 commit ab3055c
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/soulmate/loader.rb
Expand Up @@ -36,8 +36,10 @@ def add(item, opts = {})
Soulmate.redis.hset(database, item["id"], MultiJson.encode(item))
phrase = ([item["term"]] + (item["aliases"] || [])).join(' ')
prefixes_for_phrase(phrase).each do |p|
Soulmate.redis.sadd(base, p) # remember this prefix in a master set
Soulmate.redis.zadd("#{base}:#{p}", item["score"], item["id"]) # store the id of this term in the index
Soulmate.redis.pipelined do
Soulmate.redis.sadd(base, p) # remember this prefix in a master set
Soulmate.redis.zadd("#{base}:#{p}", item["score"], item["id"]) # store the id of this term in the index
end
end
end

Expand All @@ -50,8 +52,10 @@ def remove(item)
Soulmate.redis.hdel(database, prev_item["id"])
phrase = ([prev_item["term"]] + (prev_item["aliases"] || [])).join(' ')
prefixes_for_phrase(phrase).each do |p|
Soulmate.redis.srem(base, p)
Soulmate.redis.zrem("#{base}:#{p}", prev_item["id"])
Soulmate.redis.pipelined do
Soulmate.redis.srem(base, p)
Soulmate.redis.zrem("#{base}:#{p}", prev_item["id"])
end
end
end
end
Expand Down

0 comments on commit ab3055c

Please sign in to comment.