Permalink
Browse files

+ Redis scripting branch, first try

  • Loading branch information...
1 parent 86d21ad commit 4fcd563b5b34fca8ae99b19ae9e0bd94f45b135f @floere committed Nov 21, 2011
Showing with 28 additions and 22 deletions.
  1. +28 −22 server/lib/picky/backends/redis.rb
View
50 server/lib/picky/backends/redis.rb
@@ -88,26 +88,28 @@ def redis_version
#
# Note: We use the amount and offset hints to speed Redis up.
#
-# def ids combinations, amount, offset
-# if redis_with_scripting?
-# @@script = <<-SCRIPT
-# redis.call('zinterstore', KEYS[1], ARGV[1]);
-# local result = redis.call('zrange', KEYS[1], ARGV[2], ARGV[3])
-# redis.call('del', KEYS[1])
-# return result
-# SCRIPT
-# # Scripting version of #ids.
-# #
-# def ids combinations, amount, offset
-# identifiers = combinations.inject([]) do |identifiers, combination|
-# identifiers << "#{combination.identifier}"
-# end
-#
-# # Assume it's using EVALSHA.
-# #
-# client.eval @@script, generate_intermediate_result_id, identifiers, offset, (offset + amount)
-# end
-# else
+ def ids combinations, amount, offset
+ if redis_with_scripting?
+ @@script = <<-SCRIPT
+redis.call('zinterstore', KEYS[1], ARGV);
+local results = redis.call('zrange', KEYS[1], tonumber(KEYS[2]), tonumber(KEYS[3]));
+redis.call('del', KEYS[1]);
+return results;
+SCRIPT
+ # Scripting version of #ids.
+ #
+ def ids combinations, amount, offset
+ identifiers = combinations.inject([]) do |identifiers, combination|
+ identifiers << "#{combination.identifier}"
+ end
+
+ # Assume it's using EVALSHA.
+ #
+ # TODO It's not.
+ #
+ client.eval @@script, 3, generate_intermediate_result_id, offset, (offset + amount), *identifiers
+ end
+ else
# Non-Scripting version of #ids.
#
def ids combinations, amount, offset
@@ -133,8 +135,12 @@ def ids combinations, amount, offset
results
end
- # end
- # end
+ end
+
+ # Call the newly installed version.
+ #
+ ids combinations, amount, offset
+ end
# Generate a multiple host/process safe result id.
#

0 comments on commit 4fcd563

Please sign in to comment.