Sha256: 36eb8c2252af99fcc3b9410c94fc4d1633f77bfa6fbe21c4507773f51c033147

Contents?: true

Size: 1.28 KB

Versions: 54

Compression:

Stored size: 1.28 KB

Contents

# encoding: UTF-8

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

setup do
  log = StringIO.new
  init Redis::Distributed.new(NODES, :logger => ::Logger.new(log))
end

test "hashes consistently" do
  r1 = Redis::Distributed.new ["redis://localhost:6379/15", *NODES]
  r2 = Redis::Distributed.new ["redis://localhost:6379/15", *NODES]
  r3 = Redis::Distributed.new ["redis://localhost:6379/15", *NODES]

  assert r1.node_for("foo").id == r2.node_for("foo").id
  assert r1.node_for("foo").id == r3.node_for("foo").id
end

test "allows clustering of keys" do |r|
  r = Redis::Distributed.new(NODES)
  r.add_node("redis://localhost:6379/14")
  r.flushdb

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

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

test "distributes keys if no clustering is used" do |r|
  r.add_node("redis://localhost:6379/14")
  r.flushdb

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

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

test "allows passing a custom tag extractor" do |r|
  r = Redis::Distributed.new(NODES, :tag => /^(.+?):/)
  r.add_node("redis://localhost:6379/14")
  r.flushdb

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

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

Version data entries

54 entries across 54 versions & 7 rubygems

Version Path
classiccms-0.5.14 vendor/bundle/gems/redis-2.2.2/test/distributed_key_tags_test.rb
classiccms-0.5.13 vendor/bundle/gems/redis-2.2.2/test/distributed_key_tags_test.rb
classiccms-0.5.12 vendor/bundle/gems/redis-2.2.2/test/distributed_key_tags_test.rb
classiccms-0.5.11 vendor/bundle/gems/redis-2.2.2/test/distributed_key_tags_test.rb
classiccms-0.5.10 vendor/bundle/gems/redis-2.2.2/test/distributed_key_tags_test.rb
classiccms-0.5.9 vendor/bundle/gems/redis-2.2.2/test/distributed_key_tags_test.rb
classiccms-0.5.8 vendor/bundle/gems/redis-2.2.2/test/distributed_key_tags_test.rb
classiccms-0.5.7 vendor/bundle/gems/redis-2.2.2/test/distributed_key_tags_test.rb
classiccms-0.5.6 vendor/bundle/gems/redis-2.2.2/test/distributed_key_tags_test.rb
classiccms-0.5.5 vendor/bundle/gems/redis-2.2.2/test/distributed_key_tags_test.rb
classiccms-0.5.2 vendor/bundle/gems/redis-2.2.2/test/distributed_key_tags_test.rb
classiccms-0.5.1 vendor/bundle/gems/redis-2.2.2/test/distributed_key_tags_test.rb
classiccms-0.5.0 vendor/bundle/gems/redis-2.2.2/test/distributed_key_tags_test.rb
classiccms-0.4.2 vendor/bundle/gems/redis-2.2.2/test/distributed_key_tags_test.rb
classiccms-0.4.1 vendor/bundle/gems/redis-2.2.2/test/distributed_key_tags_test.rb
classiccms-0.4.0 vendor/bundle/gems/redis-2.2.2/test/distributed_key_tags_test.rb
classiccms-0.3.9 vendor/bundle/gems/redis-2.2.2/test/distributed_key_tags_test.rb
classiccms-0.3.8 vendor/bundle/gems/redis-2.2.2/test/distributed_key_tags_test.rb
classiccms-0.3.7 vendor/bundle/gems/redis-2.2.2/test/distributed_key_tags_test.rb
classiccms-0.3.6 vendor/bundle/gems/redis-2.2.2/test/distributed_key_tags_test.rb