Sha256: b53186a7d685114448d6d29afc268a369730e3b763ce06440301ec7bfb04db7e

Contents?: true

Size: 1.28 KB

Versions: 2

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

2 entries across 2 versions & 2 rubygems

Version Path
gorsuch-redis-3.0.0.rc1 test/distributed_key_tags_test.rb
redis-3.0.0.rc1 test/distributed_key_tags_test.rb