Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Remove CommandOptions helper class

  • Loading branch information...
commit b3cb04ab40605d11a96cb3d809b0b73785c83706 1 parent 74d9ca6
@pietern pietern authored
Showing with 16 additions and 46 deletions.
  1. +16 −46 lib/redis.rb
View
62 lib/redis.rb
@@ -1135,13 +1135,16 @@ def zscore(key, member)
# - `:aggregate => String`: aggregate function to use (sum, min, max, ...)
# @return [Fixnum] number of elements in the resulting sorted set
def zinterstore(destination, keys, options = {})
- command = CommandOptions.new(options) do |c|
- c.splat :weights
- c.value :aggregate
- end
+ args = []
+
+ weights = options[:weights]
+ args.concat ["WEIGHTS", *weights] if weights
+
+ aggregate = options[:aggregate]
+ args.concat ["AGGREGATE", aggregate] if aggregate
synchronize do
- @client.call [:zinterstore, destination, keys.size, *(keys + command.to_a)]
+ @client.call [:zinterstore, destination, keys.size, *(keys + args)]
end
end
@@ -1159,13 +1162,16 @@ def zinterstore(destination, keys, options = {})
# - `:aggregate => String`: aggregate function to use (sum, min, max, ...)
# @return [Fixnum] number of elements in the resulting sorted set
def zunionstore(destination, keys, options = {})
- command = CommandOptions.new(options) do |c|
- c.splat :weights
- c.value :aggregate
- end
+ args = []
+
+ weights = options[:weights]
+ args.concat ["WEIGHTS", *weights] if weights
+
+ aggregate = options[:aggregate]
+ args.concat ["AGGREGATE", aggregate] if aggregate
synchronize do
- @client.call [:zunionstore, destination, keys.size, *(keys + command.to_a)]
+ @client.call [:zunionstore, destination, keys.size, *(keys + args)]
end
end
@@ -1866,42 +1872,6 @@ def method_missing(command, *args)
end
end
- class CommandOptions
- def initialize(options)
- @result = []
- @options = options
- yield(self)
- end
-
- def bool(name)
- insert(name) { |argument, value| [argument] }
- end
-
- def value(name)
- insert(name) { |argument, value| [argument, value] }
- end
-
- def splat(name)
- insert(name) { |argument, value| [argument, *value] }
- end
-
- def multi(name)
- insert(name) { |argument, value| [argument].product(Array(value)).flatten }
- end
-
- def words(name)
- insert(name) { |argument, value| value.split(" ") }
- end
-
- def to_a
- @result
- end
-
- def insert(name)
- @result += yield(name.to_s.upcase.gsub("_", ""), @options[name]) if @options[name]
- end
- end
-
private
# Commands returning 1 for true and 0 for false may be executed in a pipeline
Please sign in to comment.
Something went wrong with that request. Please try again.