Sha256: 9d30bf4502af8c0d713000c160a726bb0397af4e0975dadad82346f86d781a24

Contents?: true

Size: 1.3 KB

Versions: 11

Compression:

Stored size: 1.3 KB

Contents

# encoding: UTF-8

require "helper"

class TestDistributedKeyTags < Test::Unit::TestCase

  include Helper
  include Helper::Distributed

  def test_hashes_consistently
    r1 = Redis::Distributed.new ["redis://localhost:#{PORT}/15", *NODES]
    r2 = Redis::Distributed.new ["redis://localhost:#{PORT}/15", *NODES]
    r3 = Redis::Distributed.new ["redis://localhost:#{PORT}/15", *NODES]

    assert_equal r1.node_for("foo").id, r2.node_for("foo").id
    assert_equal r1.node_for("foo").id, r3.node_for("foo").id
  end

  def test_allows_clustering_of_keys
    r = Redis::Distributed.new(NODES)
    r.add_node("redis://localhost:#{PORT}/14")
    r.flushdb

    100.times do |i|
      r.set "{foo}users:#{i}", i
    end

    assert_equal [0, 100], r.nodes.map { |node| node.keys.size }
  end

  def test_distributes_keys_if_no_clustering_is_used
    r.add_node("redis://localhost:#{PORT}/14")
    r.flushdb

    r.set "users:1", 1
    r.set "users:4", 4

    assert_equal [1, 1], r.nodes.map { |node| node.keys.size }
  end

  def test_allows_passing_a_custom_tag_extractor
    r = Redis::Distributed.new(NODES, :tag => /^(.+?):/)
    r.add_node("redis://localhost:#{PORT}/14")
    r.flushdb

    100.times do |i|
      r.set "foo:users:#{i}", i
    end

    assert_equal [0, 100], r.nodes.map { |node| node.keys.size }
  end
end

Version data entries

11 entries across 11 versions & 3 rubygems

Version Path
redis-3.0.5 test/distributed_key_tags_test.rb
sidekiq-statsd-0.1.1 vendor/ruby/1.9.1/gems/redis-3.0.4/test/distributed_key_tags_test.rb
sidekiq-statsd-0.1.0 vendor/ruby/1.9.1/gems/redis-3.0.4/test/distributed_key_tags_test.rb
redis-3.0.4 test/distributed_key_tags_test.rb
redis-3.0.3 test/distributed_key_tags_test.rb
remq-0.0.4 vendor/bundle/gems/redis-3.0.2/test/distributed_key_tags_test.rb
remq-0.0.3 vendor/bundle/gems/redis-3.0.2/test/distributed_key_tags_test.rb
redis-3.0.2 test/distributed_key_tags_test.rb
redis-3.0.1 test/distributed_key_tags_test.rb
redis-3.0.0 test/distributed_key_tags_test.rb
redis-3.0.0.rc2 test/distributed_key_tags_test.rb