module FakeRedis::SortMethod
def sort(key, *redis_options_array)
def sort(key, *redis_options_array) return [] unless key return [] if type(key) == 'none' unless %w(list set zset).include? type(key) raise Redis::CommandError.new("WRONGTYPE Operation against a key holding the wrong kind of value") end # redis_options is an array of format [BY pattern] [LIMIT offset count] [GET pattern [GET pattern ...]] [ASC|DESC] [ALPHA] [STORE destination] # Lets nibble it back into a hash options = extract_options_from(redis_options_array) # And now to actually do the work of this method projected = project(data[key], options[:by], options[:get]) sorted = sort_by(projected, options[:order]) sliced = slice(sorted, options[:limit]) # We have to flatten it down as redis-rb adds back the array to the return value result = sliced.flatten(1) options[:store] ? rpush(options[:store], sliced) : result end