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
|
# frozen_string_literal: true
require "helper"
class TestDistributed < Minitest::Test
include Helper::Distributed
def test_handle_multiple_servers
@r = Redis::Distributed.new ["redis://127.0.0.1:#{PORT}/15", *NODES]
100.times do |idx|
@r.set(idx.to_s, "foo#{idx}")
end
100.times do |idx|
assert_equal "foo#{idx}", @r.get(idx.to_s)
end
assert_equal "0", @r.keys("*").min
assert_equal "string", @r.type("1")
end
def test_add_nodes
@r = Redis::Distributed.new NODES, timeout: 10
assert_equal "127.0.0.1", @r.nodes[0]._client.host
assert_equal PORT, @r.nodes[0]._client.port
assert_equal 15, @r.nodes[0]._client.db
assert_equal 10, @r.nodes[0]._client.timeout
@r.add_node("redis://127.0.0.1:6380/14")
assert_equal "127.0.0.1", @r.nodes[1]._client.host
assert_equal 6380, @r.nodes[1]._client.port
assert_equal 14, @r.nodes[1]._client.db
assert_equal 10, @r.nodes[1]._client.timeout
end
def test_pipelining_commands_cannot_be_distributed
assert_raises Redis::Distributed::CannotDistribute do
r.pipelined do
r.lpush "foo", "s1"
r.lpush "foo", "s2"
end
end
end
def test_unknown_commands_does_not_work_by_default
assert_raises NoMethodError do
r.not_yet_implemented_command
end
end
end
|