class Redis

def sort(key, options = {})

Returns:
  • (Array, Array>, Fixnum) -

Parameters:
  • options (Hash) --
  • key (String) --

Other tags:
    Example: Store an alphabetically descending list in "target" -
    Example: Retrieve the first 2 elements from an alphabetically sorted "list" -
def sort(key, options = {})
  args = []
  by = options[:by]
  args.concat(["BY", by]) if by
  limit = options[:limit]
  args.concat(["LIMIT"] + limit) if limit
  get = Array(options[:get])
  args.concat(["GET"].product(get).flatten) unless get.empty?
  order = options[:order]
  args.concat(order.split(" ")) if order
  store = options[:store]
  args.concat(["STORE", store]) if store
  synchronize do |client|
    client.call([:sort, key] + args) do |reply|
      if get.size > 1 && !store
        if reply
          reply.each_slice(get.size).to_a
        end
      else
        reply
      end
    end
  end
end