Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added namespace support for Redis::DistrubutedStore

  • Loading branch information...
commit 5fc0c720121422ca41b7c6060b4fe59a9f22bc60 1 parent 01e9d29
Luca Guidi authored
9 lib/redis/distributed_store.rb
@@ -2,10 +2,11 @@ class Redis
2 2 class DistributedStore < Distributed
3 3 attr_reader :ring
4 4
5   - def initialize(addresses)
  5 + def initialize(addresses, options = { })
6 6 nodes = addresses.map do |address|
7 7 ::Redis::Store.new address
8 8 end
  9 + _extend_namespace options
9 10 @ring = Redis::HashRing.new nodes
10 11 end
11 12
@@ -24,5 +25,11 @@ def get(key, options = nil)
24 25 def setnx(key, value, options = nil)
25 26 node_for(key).setnx(key, value, options)
26 27 end
  28 +
  29 + private
  30 + def _extend_namespace(options)
  31 + @namespace = options[:namespace]
  32 + extend ::Redis::Store::Namespace if @namespace
  33 + end
27 34 end
28 35 end
14 spec/redis/distributed_store_spec.rb
@@ -30,4 +30,18 @@
30 30 it "should get an object" do
31 31 @dmr.get("rabbit").should == @rabbit
32 32 end
  33 +
  34 + describe "namespace" do
  35 + before :each do
  36 + @dmr = Redis::DistributedStore.new [
  37 + {:host => "localhost", :port => "6380", :db => 0},
  38 + {:host => "localhost", :port => "6381", :db => 0}
  39 + ], :namespace => "theplaylist"
  40 + end
  41 +
  42 + it "should use namespaced key" do
  43 + @dmr.should_receive(:node_for).with("theplaylist:rabbit").and_return @dmr.nodes.first
  44 + @dmr.get "rabbit"
  45 + end
  46 + end
33 47 end

0 comments on commit 5fc0c72

Please sign in to comment.
Something went wrong with that request. Please try again.