redis_buddy 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  # (c) 2009 Luca Guidi
2
2
 
3
- class DistributedMarshaledRedis < DistRedis
3
+ class DistributedMarshaledRedis < Redis::Distributed
4
4
  def initialize(addresses)
5
5
  nodes = addresses.map do |address|
6
6
  MarshaledRedis.new address
data/lib/redis_buddy.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'redis'
2
- require 'redis/dist_redis'
2
+ require 'redis/distributed'
3
3
  require 'redis/namespace'
4
4
 
5
5
  require 'redis/redis_factory'
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 3
9
- version: 0.1.3
8
+ - 4
9
+ version: 0.1.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ole Riesenberg
@@ -25,10 +25,10 @@ dependencies:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
27
  segments:
28
+ - 1
28
29
  - 0
29
- - 2
30
- - 0
31
- version: 0.2.0
30
+ - 6
31
+ version: 1.0.6
32
32
  type: :runtime
33
33
  version_requirements: *id001
34
34
  - !ruby/object:Gem::Dependency
@@ -40,9 +40,9 @@ dependencies:
40
40
  - !ruby/object:Gem::Version
41
41
  segments:
42
42
  - 0
43
- - 3
44
- - 0
45
- version: 0.3.0
43
+ - 4
44
+ - 2
45
+ version: 0.4.2
46
46
  type: :runtime
47
47
  version_requirements: *id002
48
48
  description: A namespaced Redis Cache Store for Rails 3, based on redis-store
@@ -90,9 +90,5 @@ rubygems_version: 1.3.6
90
90
  signing_key:
91
91
  specification_version: 3
92
92
  summary: A namespaced Redis Cache Store for Rails 3
93
- test_files:
94
- - spec/spec_helper.rb
95
- - spec/redis/distributed_marshaled_redis_spec.rb
96
- - spec/redis/marshaled_redis_spec.rb
97
- - spec/redis/redis_factory_spec.rb
98
- - spec/cache/redis_buddy_store.rb
93
+ test_files: []
94
+
@@ -1,173 +0,0 @@
1
- require File.join(File.dirname(__FILE__), "/../spec_helper")
2
-
3
- module ActiveSupport
4
- module Cache
5
- describe "ActiveSupport::Cache::RedisBuddyStore" do
6
- before(:each) do
7
- @store = ActiveSupport::Cache::RedisBuddyStore.new
8
- @dstore = ActiveSupport::Cache::RedisBuddyStore.new "localhost:6380/1", "localhost:6381/1"
9
- @rabbit = OpenStruct.new :name => "bunny"
10
- @white_rabbit = OpenStruct.new :color => "white"
11
- with_store_management do |store|
12
- store.write "rabbit", @rabbit
13
- store.delete "counter"
14
- store.delete "rub-a-dub"
15
- end
16
- end
17
-
18
- it "should accept connection params" do
19
- redis = instantiate_store
20
- redis.host.should == "127.0.0.1"
21
- redis.port.should == 6379
22
- redis.db.should == 0
23
-
24
- redis = instantiate_store "localhost"
25
- redis.host.should == "localhost"
26
-
27
- redis = instantiate_store "localhost:6380"
28
- redis.host.should == "localhost"
29
- redis.port.should == 6380
30
-
31
- redis = instantiate_store "localhost:6380/13"
32
- redis.host.should == "localhost"
33
- redis.port.should == 6380
34
- redis.db.should == 13
35
- end
36
-
37
- it "should instantiate a ring" do
38
- store = instantiate_store
39
- store.should be_kind_of(MarshaledRedis)
40
- store = instantiate_store ["localhost:6379/0", "localhost:6379/1"]
41
- store.should be_kind_of(DistributedMarshaledRedis)
42
- end
43
-
44
- it "should read the data" do
45
- with_store_management do |store|
46
- store.read("rabbit").should === @rabbit
47
- end
48
- end
49
-
50
- it "should write the data" do
51
- with_store_management do |store|
52
- store.write "rabbit", @white_rabbit
53
- store.read("rabbit").should === @white_rabbit
54
- end
55
- end
56
-
57
- it "should write the data with expiration time" do
58
- with_store_management do |store|
59
- store.write "rabbit", @white_rabbit, :expires_in => 1.second
60
- store.read("rabbit").should === @white_rabbit ; sleep 2
61
- store.read("rabbit").should be_nil
62
- end
63
- end
64
-
65
- it "should not write data if :unless_exist option is true" do
66
- with_store_management do |store|
67
- store.write "rabbit", @white_rabbit, :unless_exist => true
68
- store.read("rabbit").should === @rabbit
69
- end
70
- end
71
-
72
- it "should read raw data" do
73
- with_store_management do |store|
74
- store.read("rabbit", :raw => true).should == "\004\bU:\017OpenStruct{\006:\tname\"\nbunny"
75
- end
76
- end
77
-
78
- it "should write raw data" do
79
- with_store_management do |store|
80
- store.write "rabbit", @white_rabbit, :raw => true
81
- store.read("rabbit", :raw => true).should == %(#<OpenStruct color="white">)
82
- end
83
- end
84
-
85
- it "should delete data" do
86
- with_store_management do |store|
87
- store.delete "rabbit"
88
- store.read("rabbit").should be_nil
89
- end
90
- end
91
-
92
- it "should delete matched data" do
93
- with_store_management do |store|
94
- store.delete_matched "rabb*"
95
- store.read("rabbit").should be_nil
96
- end
97
- end
98
-
99
- it "should verify existence of an object in the store" do
100
- with_store_management do |store|
101
- store.exist?("rabbit").should be_true
102
- store.exist?("rab-a-dub").should be_false
103
- end
104
- end
105
-
106
- it "should increment a key" do
107
- with_store_management do |store|
108
- 3.times { store.increment "counter" }
109
- store.read("counter", :raw => true).to_i.should == 3
110
- end
111
- end
112
-
113
- it "should decrement a key" do
114
- with_store_management do |store|
115
- 3.times { store.increment "counter" }
116
- 2.times { store.decrement "counter" }
117
- store.read("counter", :raw => true).to_i.should == 1
118
- end
119
- end
120
-
121
- it "should increment a key by given value" do
122
- with_store_management do |store|
123
- store.increment "counter", 3
124
- store.read("counter", :raw => true).to_i.should == 3
125
- end
126
- end
127
-
128
- it "should decrement a key by given value" do
129
- with_store_management do |store|
130
- 3.times { store.increment "counter" }
131
- store.decrement "counter", 2
132
- store.read("counter", :raw => true).to_i.should == 1
133
- end
134
- end
135
-
136
- it "should clear the store" do
137
- with_store_management do |store|
138
- store.clear
139
- store.instance_variable_get(:@data).keys("*").flatten.should be_empty
140
- end
141
- end
142
-
143
- it "should return store stats" do
144
- with_store_management do |store|
145
- store.stats.should_not be_empty
146
- end
147
- end
148
-
149
- it "should fetch data" do
150
- with_store_management do |store|
151
- store.fetch("rabbit").should == @rabbit
152
- store.fetch("rub-a-dub").should be_nil
153
- store.fetch("rub-a-dub") { "Flora de Cana" }
154
- store.fetch("rub-a-dub").should === "Flora de Cana"
155
- store.fetch("rabbit", :force => true).should be_nil # force cache miss
156
- store.fetch("rabbit", :force => true, :expires_in => 1.second) { @white_rabbit }
157
- store.fetch("rabbit").should === @white_rabbit ; sleep 2
158
- store.fetch("rabbit").should be_nil
159
- end
160
- end
161
-
162
- private
163
- def instantiate_store(addresses = nil)
164
- ActiveSupport::Cache::RedisBuddyStore.new(addresses).instance_variable_get(:@data)
165
- end
166
-
167
- def with_store_management
168
- yield @store
169
- yield @dstore
170
- end
171
- end
172
- end
173
- end
@@ -1,35 +0,0 @@
1
- require File.join(File.dirname(__FILE__), "/../spec_helper")
2
-
3
- describe "DistributedMarshaledRedis" do
4
- before(:each) do
5
- @dmr = DistributedMarshaledRedis.new [
6
- {:host => "localhost", :port => "6380", :db => 0},
7
- {:host => "localhost", :port => "6381", :db => 0}
8
- ]
9
- @rabbit = OpenStruct.new :name => "bunny"
10
- @white_rabbit = OpenStruct.new :color => "white"
11
- @dmr.set "rabbit", @rabbit
12
- end
13
-
14
- after(:all) do
15
- @dmr.ring.nodes.each { |server| server.flush_db }
16
- end
17
-
18
- it "should accept connection params" do
19
- dmr = DistributedMarshaledRedis.new [ :host => "localhost", :port => "6380", :db => "1" ]
20
- dmr.ring.should have(1).node
21
- mr = dmr.ring.nodes.first
22
- mr.host.should == "localhost"
23
- mr.port.should == 6380
24
- mr.db.should == 1
25
- end
26
-
27
- it "should set an object" do
28
- @dmr.set "rabbit", @white_rabbit
29
- @dmr.get("rabbit").should == @white_rabbit
30
- end
31
-
32
- it "should get an object" do
33
- @dmr.get("rabbit").should == @rabbit
34
- end
35
- end
@@ -1,54 +0,0 @@
1
- require File.join(File.dirname(__FILE__), "/../spec_helper")
2
-
3
- describe "MarshaledRedis" do
4
- before(:each) do
5
- @store = MarshaledRedis.new
6
- @rabbit = OpenStruct.new :name => "bunny"
7
- @white_rabbit = OpenStruct.new :color => "white"
8
- @store.set "rabbit", @rabbit
9
- @store.delete "rabbit2"
10
- end
11
-
12
- after :each do
13
- @store.quit
14
- end
15
-
16
- it "should unmarshal an object on get" do
17
- @store.get("rabbit").should === @rabbit
18
- end
19
-
20
- it "should marshal object on set" do
21
- @store.set "rabbit", @white_rabbit
22
- @store.get("rabbit").should === @white_rabbit
23
- end
24
-
25
- it "should not unmarshal object on get if raw option is true" do
26
- @store.get("rabbit", :raw => true).should == "\004\bU:\017OpenStruct{\006:\tname\"\nbunny"
27
- end
28
-
29
- it "should not marshal object on set if raw option is true" do
30
- @store.set "rabbit", @white_rabbit, :raw => true
31
- @store.get("rabbit", :raw => true).should == %(#<OpenStruct color="white">)
32
- end
33
-
34
- it "should not unmarshal object if getting an empty string" do
35
- @store.set "empty_string", ""
36
- lambda { @store.get("empty_string").should == "" }.should_not raise_error
37
- end
38
-
39
- it "should not set an object if already exist" do
40
- @store.set_unless_exists "rabbit", @white_rabbit
41
- @store.get("rabbit").should === @rabbit
42
- end
43
-
44
- it "should marshal object on set_unless_exists" do
45
- @store.set_unless_exists "rabbit2", @white_rabbit
46
- @store.get("rabbit2").should === @white_rabbit
47
- end
48
-
49
- it "should not marshal object on set_unless_exists if raw option is true" do
50
- @store.set_unless_exists "rabbit2", @white_rabbit, :raw => true
51
- @store.get("rabbit2", :raw => true).should == %(#<OpenStruct color="white">)
52
- end
53
- end
54
-
@@ -1,34 +0,0 @@
1
- require File.join(File.dirname(__FILE__), "/../spec_helper")
2
-
3
- describe "RedisFactory" do
4
- it "should instantiate a MarshaledRedis store" do
5
- store = RedisFactory.create
6
- store.should be_kind_of(MarshaledRedis)
7
- store.host.should == "127.0.0.1"
8
- store.port.should == 6379
9
- store.db.should == 0
10
- end
11
-
12
- it "should allow to specify host" do
13
- store = RedisFactory.create "localhost"
14
- store.host.should == "localhost"
15
- end
16
-
17
- it "should allow to specify port" do
18
- store = RedisFactory.create "localhost:6380"
19
- store.host.should == "localhost"
20
- store.port.should == 6380
21
- end
22
-
23
- it "should allow to specify db" do
24
- store = RedisFactory.create "localhost:6380/13"
25
- store.host.should == "localhost"
26
- store.port.should == 6380
27
- store.db.should == 13
28
- end
29
-
30
- it "should instantiate a DistributedMarshaledRedis store" do
31
- store = RedisFactory.create "localhost:6379", "localhost:6380"
32
- store.should be_kind_of(DistributedMarshaledRedis)
33
- end
34
- end
data/spec/spec_helper.rb DELETED
@@ -1,14 +0,0 @@
1
- $: << File.join(File.dirname(__FILE__), "/../lib")
2
- require 'bundler'
3
- Bundler.setup :testing
4
- require "ostruct"
5
- require "spec"
6
- require "redis"
7
- require "rails"
8
- require "redis_buddy"
9
-
10
- require "cache/redis_buddy_store"
11
-
12
- class Redis; attr_reader :host, :port, :db end
13
- $DEBUG = ENV["DEBUG"] === "true"
14
-