Sha256: 59a1baa43e515ba48ec9a486b71104553b909fe387d9ee774b3809a2aa64945c

Contents?: true

Size: 1.46 KB

Versions: 5

Compression:

Stored size: 1.46 KB

Contents

require 'spec_helper'

describe "Redis::DistributedStore" do
  before(:each) do
    @dmr = Redis::DistributedStore.new [
      {:host => "localhost", :port => "6380", :db => 0},
      {:host => "localhost", :port => "6381", :db => 0}
    ]
    @rabbit = OpenStruct.new :name => "bunny"
    @white_rabbit = OpenStruct.new :color => "white"
    @dmr.set "rabbit", @rabbit
  end

  after(:all) do
    @dmr.ring.nodes.each { |server| server.flushdb }
  end

  it "should accept connection params" do
    dmr = Redis::DistributedStore.new [ :host => "localhost", :port => "6380", :db => "1" ]
    dmr.ring.nodes.size == 1
    mr = dmr.ring.nodes.first
    mr.to_s.should == "Redis Client connected to localhost:6380 against DB 1"
  end

  it "should force reconnection" do
    @dmr.nodes.each do |node|
      node.should_receive(:reconnect)
    end

    @dmr.reconnect
  end

  it "should set an object" do
    @dmr.set "rabbit", @white_rabbit
    @dmr.get("rabbit").should == @white_rabbit
  end

  it "should get an object" do
    @dmr.get("rabbit").should == @rabbit
  end

  describe "namespace" do
    before :each do
      @dmr = Redis::DistributedStore.new [
        {:host => "localhost", :port => "6380", :db => 0},
        {:host => "localhost", :port => "6381", :db => 0}
      ], :namespace => "theplaylist"
    end

    it "should use namespaced key" do
      @dmr.should_receive(:node_for).with("theplaylist:rabbit").and_return @dmr.nodes.first
      @dmr.get "rabbit"
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
instructure-redis-store-1.0.0.2.instructure1 spec/redis/distributed_store_spec.rb
instructure-redis-store-1.0.0.1.instructure1 spec/redis/distributed_store_spec.rb
redis-store-1.0.0.1 spec/redis/distributed_store_spec.rb
redis-store-1.0.0.rc1 spec/redis/distributed_store_spec.rb
redis-store-1.0.0.beta5 spec/redis/distributed_store_spec.rb