4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/fakeredis/sort_method.rb', line 4
def sort(key, *redis_options_array)
return [] unless key
return [] if type(key) == 'none'
unless %w(list set zset).include? type(key)
warn "Operation against a key holding the wrong kind of value: Expected list, set or zset at #{key}."
raise Redis::CommandError.new("WRONGTYPE Operation against a key holding the wrong kind of value")
end
options = (redis_options_array)
projected = project(data[key], options[:by], options[:get])
sorted = sort_by(projected, options[:order])
sliced = slice(sorted, options[:limit])
result = sliced.flatten(1)
options[:store] ? rpush(options[:store], sliced) : result
end
|