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
abaci-0.3.0 vendor/bundle/gems/redis-2.2.2/test/distributed_key_tags_test.rb
classiccms-0.7.5 vendor/bundle/gems/redis-2.2.2/test/distributed_key_tags_test.rb
classiccms-0.7.4 vendor/bundle/gems/redis-2.2.2/test/distributed_key_tags_test.rb
classiccms-0.7.3 vendor/bundle/gems/redis-2.2.2/test/distributed_key_tags_test.rb
classiccms-0.7.2 vendor/bundle/gems/redis-2.2.2/test/distributed_key_tags_test.rb
classiccms-0.7.1 vendor/bundle/gems/redis-2.2.2/test/distributed_key_tags_test.rb
classiccms-0.7.0 vendor/bundle/gems/redis-2.2.2/test/distributed_key_tags_test.rb
classiccms-0.6.9 vendor/bundle/gems/redis-2.2.2/test/distributed_key_tags_test.rb
classiccms-0.6.8 vendor/bundle/gems/redis-2.2.2/test/distributed_key_tags_test.rb
classiccms-0.6.7 vendor/bundle/gems/redis-2.2.2/test/distributed_key_tags_test.rb
classiccms-0.6.6 vendor/bundle/gems/redis-2.2.2/test/distributed_key_tags_test.rb
classiccms-0.6.5 vendor/bundle/gems/redis-2.2.2/test/distributed_key_tags_test.rb
classiccms-0.6.4 vendor/bundle/gems/redis-2.2.2/test/distributed_key_tags_test.rb
classiccms-0.6.3 vendor/bundle/gems/redis-2.2.2/test/distributed_key_tags_test.rb
classiccms-0.6.2 vendor/bundle/gems/redis-2.2.2/test/distributed_key_tags_test.rb
classiccms-0.6.1 vendor/bundle/gems/redis-2.2.2/test/distributed_key_tags_test.rb
classiccms-0.6.0 vendor/bundle/gems/redis-2.2.2/test/distributed_key_tags_test.rb
classiccms-0.5.17 vendor/bundle/gems/redis-2.2.2/test/distributed_key_tags_test.rb
classiccms-0.5.16 vendor/bundle/gems/redis-2.2.2/test/distributed_key_tags_test.rb
classiccms-0.5.15 vendor/bundle/gems/redis-2.2.2/test/distributed_key_tags_test.rb