lib/redis/connection/memory.rb in fakeredis-0.9.0 vs lib/redis/connection/memory.rb in fakeredis-0.9.1

- old
+ new

@@ -120,11 +120,11 @@ def flushall self.class.databases[database_instance_key] = [] "OK" end - def auth(password) + def auth(*args) "OK" end def select(index) data_type_check(index, Integer) @@ -560,15 +560,21 @@ data[key] = ::Set.new(value.map(&:to_s)) data[key].size end # 0 = false, 1 = true unless an array was passed in - return result == 1 unless should_return_int + if Redis.sadd_returns_boolean && !should_return_int + return result == 1 + end result end + def sadd?(key, value) + sadd(key, value) == 1 + end + def srem(key, value) data_type_check(key, ::Set) raise_argument_error('srem') if Array(value).empty? return false unless data[key] @@ -773,32 +779,32 @@ end def hset(key, *fields) fields = fields.first if fields.size == 1 && fields.first.is_a?(Hash) raise_argument_error('hset') if fields.empty? - + is_list_of_arrays = fields.all?{|field| field.instance_of?(Array)} - + raise_argument_error('hmset') if fields.size.odd? and !is_list_of_arrays raise_argument_error('hmset') if is_list_of_arrays and !fields.all?{|field| field.length == 2} - + data_type_check(key, Hash) insert_count = 0 data[key] ||= {} - + if fields.is_a?(Hash) insert_count = fields.keys.size - (data[key].keys & fields.keys).size - + data[key].merge!(fields) else fields.each_slice(2) do |field| insert_count += 1 if data[key][field[0].to_s].nil? - + data[key][field[0].to_s] = field[1].to_s end end - + insert_count end def hsetnx(key, field, value) data_type_check(key, Hash) @@ -1148,16 +1154,16 @@ zrem(key, member.first) end count.nil? ? results.first : results.flatten end - def bzpopmax(*args) - bzpop(:bzpopmax, args) + def bzpopmax(*args, timeout: 0) + bzpop(:bzpopmax, args, timeout) end - def bzpopmin(*args) - bzpop(:bzpopmin, args) + def bzpopmin(*args, timeout: 0) + bzpop(:bzpopmin, args, timeout) end def zcard(key) data_type_check(key, ZSet) data[key] ? data[key].size : 0 @@ -1592,18 +1598,10 @@ else (1..-number).map { data[key].to_a[rand(data[key].size)] }.flatten end end - def bzpop(command, args) - timeout = - if args.last.is_a?(Hash) - args.pop[:timeout] - elsif args.last.respond_to?(:to_int) - args.pop.to_int - end - - timeout ||= 0 + def bzpop(command, args, timeout) single_pop_command = command.to_s[1..-1] keys = args.flatten keys.each do |key| if data[key] data_type_check(data[key], ZSet)