Sha256: a9152789c9c1d21938e9b22062bfcf5e7a18e9ba70d409d64cef4f43fbe35229

Contents?: true

Size: 1 KB

Versions: 2

Compression:

Stored size: 1 KB

Contents

# encoding: UTF-8

require File.expand_path("./helper", File.dirname(__FILE__))

setup do
  init Redis.new(OPTIONS)
end

test "SORT" do |r|
  r.set("foo:1", "s1")
  r.set("foo:2", "s2")

  r.rpush("bar", "1")
  r.rpush("bar", "2")

  assert ["s1"] == r.sort("bar", :get => "foo:*", :limit => [0, 1])
  assert ["s2"] == r.sort("bar", :get => "foo:*", :limit => [0, 1], :order => "desc alpha")
end

test "SORT with an array of GETs" do |r|
  r.set("foo:1:a", "s1a")
  r.set("foo:1:b", "s1b")

  r.set("foo:2:a", "s2a")
  r.set("foo:2:b", "s2b")

  r.rpush("bar", "1")
  r.rpush("bar", "2")

  assert ["s1a", "s1b"] == r.sort("bar", :get => ["foo:*:a", "foo:*:b"], :limit => [0, 1])
  assert ["s2a", "s2b"] == r.sort("bar", :get => ["foo:*:a", "foo:*:b"], :limit => [0, 1], :order => "desc alpha")
end

test "SORT with STORE" do |r|
  r.set("foo:1", "s1")
  r.set("foo:2", "s2")

  r.rpush("bar", "1")
  r.rpush("bar", "2")

  r.sort("bar", :get => "foo:*", :store => "baz")
  assert ["s1", "s2"] == r.lrange("baz", 0, -1)
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
gorsuch-redis-3.0.0.rc1 test/sorting_test.rb
redis-3.0.0.rc1 test/sorting_test.rb