Sha256: b3a63c3dc4c4c3d947b0bc2dad1f45e66754888448132af8208f379f8d760540

Contents?: true

Size: 1.34 KB

Versions: 16

Compression:

Stored size: 1.34 KB

Contents

# encoding: UTF-8

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

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://127.0.0.1:#{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://127.0.0.1:#{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://127.0.0.1:#{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

16 entries across 15 versions & 7 rubygems

Version Path
finsync_redis-3.3.5 test/distributed_key_tags_test.rb
redis-3.3.5 test/distributed_key_tags_test.rb
logstash-filter-cache-redis-0.3.1 vendor/bundle/jruby/1.9/gems/redis-3.3.3/test/distributed_key_tags_test.rb
logstash-filter-cache-redis-0.3.0 vendor/bundle/jruby/1.9/gems/redis-3.3.3/test/distributed_key_tags_test.rb
logstash-filter-cache-redis-0.2.0 vendor/bundle/jruby/1.9/gems/redis-3.3.3/test/distributed_key_tags_test.rb
logstash-filter-cache-redis-0.1.0 vendor/bundle/jruby/1.9/gems/redis-3.3.3/test/distributed_key_tags_test.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/redis-3.3.3/test/distributed_key_tags_test.rb
redis-3.3.3 test/distributed_key_tags_test.rb
abaci-0.3.0 vendor/bundle/gems/redis-3.3.2/test/distributed_key_tags_test.rb
abaci-0.3.0 vendor/bundle/gems/redis-3.3.1/test/distributed_key_tags_test.rb
redis-3.3.2 test/distributed_key_tags_test.rb
redis-3.3.1 test/distributed_key_tags_test.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/redis-3.3.0/test/distributed_key_tags_test.rb
redis-3.3.0 test/distributed_key_tags_test.rb
discourse-redis-3.2.2 test/distributed_key_tags_test.rb
redis-3.2.2 test/distributed_key_tags_test.rb