File: commands_on_strings_test.rb

package info (click to toggle)
ruby-redis 5.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,160 kB
  • sloc: ruby: 11,445; makefile: 117; sh: 24
file content (78 lines) | stat: -rw-r--r-- 1,733 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# frozen_string_literal: true

require "helper"

class TestDistributedCommandsOnStrings < Minitest::Test
  include Helper::Distributed
  include Lint::Strings

  def test_mget
    r.set("foo", "s1")
    r.set("bar", "s2")

    assert_equal ["s1", "s2"], r.mget("foo", "bar")
    assert_equal ["s1", "s2", nil], r.mget("foo", "bar", "baz")
    assert_equal ["s1", "s2", nil], r.mget(["foo", "bar", "baz"])
  end

  def test_mget_mapped
    r.set("foo", "s1")
    r.set("bar", "s2")

    response = r.mapped_mget("foo", "bar")

    assert_equal "s1", response["foo"]
    assert_equal "s2", response["bar"]

    response = r.mapped_mget("foo", "bar", "baz")

    assert_equal "s1", response["foo"]
    assert_equal "s2", response["bar"]
    assert_nil response["baz"]
  end

  def test_mset
    assert_raises Redis::Distributed::CannotDistribute do
      r.mset(:foo, "s1", :bar, "s2")
    end
  end

  def test_mset_mapped
    assert_raises Redis::Distributed::CannotDistribute do
      r.mapped_mset(foo: "s1", bar: "s2")
    end
  end

  def test_msetnx
    assert_raises Redis::Distributed::CannotDistribute do
      r.set("foo", "s1")
      r.msetnx(:foo, "s2", :bar, "s3")
    end
  end

  def test_msetnx_mapped
    assert_raises Redis::Distributed::CannotDistribute do
      r.set("foo", "s1")
      r.mapped_msetnx(foo: "s2", bar: "s3")
    end
  end

  def test_bitop
    assert_raises Redis::Distributed::CannotDistribute do
      r.set("foo", "a")
      r.set("bar", "b")

      r.bitop(:and, "foo&bar", "foo", "bar")
    end
  end

  def test_mapped_mget_in_a_pipeline_returns_hash
    assert_raises Redis::Distributed::CannotDistribute do
      super
    end
  end

  def test_bitfield
    # Not implemented yet
  end
end