redis-store 0.3.7 → 0.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of redis-store might be problematic. Click here for more details.
- data/.gitignore +4 -0
- data/Gemfile +13 -7
- data/README.md +11 -1
- data/Rakefile +19 -5
- data/VERSION +1 -1
- data/lib/cache/merb/redis_store.rb +6 -6
- data/lib/cache/rails/redis_store.rb +10 -10
- data/lib/cache/sinatra/redis_store.rb +14 -11
- data/lib/rack/cache/redis_entitystore.rb +2 -2
- data/lib/rack/cache/redis_metastore.rb +5 -5
- data/lib/rack/session/rails.rb +61 -0
- data/lib/rack/session/redis.rb +10 -10
- data/lib/redis-store.rb +8 -4
- data/lib/redis/distributed_marshaled.rb +18 -0
- data/lib/redis/factory.rb +26 -0
- data/lib/redis/marshaled_client.rb +54 -0
- data/lib/redis/namespace.rb +9 -0
- data/redis-store.gemspec +18 -13
- data/spec/cache/merb/redis_store_spec.rb +9 -14
- data/spec/cache/rails/redis_session_store_spec.rb +77 -0
- data/spec/cache/rails/redis_store_spec.rb +13 -17
- data/spec/cache/sinatra/redis_store_spec.rb +9 -14
- data/spec/config/master.conf +5 -5
- data/spec/config/single.conf +5 -5
- data/spec/config/slave.conf +6 -6
- data/spec/rack/cache/entitystore/redis_spec.rb +21 -11
- data/spec/rack/cache/metastore/redis_spec.rb +169 -16
- data/spec/rack/session/redis_spec.rb +7 -11
- data/spec/redis/distributed_marshaled_redis_spec.rb +9 -11
- data/spec/redis/factory_spec.rb +68 -0
- data/spec/redis/marshaled_client_spec.rb +54 -0
- data/spec/spec_helper.rb +11 -5
- data/tasks/redis.tasks.rb +16 -5
- metadata +28 -12
- data/lib/redis/distributed_marshaled_redis.rb +0 -10
- data/lib/redis/marshaled_redis.rb +0 -33
- data/lib/redis/redis_factory.rb +0 -27
- data/spec/redis/marshaled_redis_spec.rb +0 -54
- data/spec/redis/redis_factory_spec.rb +0 -34
@@ -0,0 +1,68 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "/../spec_helper")
|
2
|
+
|
3
|
+
describe "Redis::Factory" do
|
4
|
+
describe ".create" do
|
5
|
+
context "when not given any arguments" do
|
6
|
+
it "should instantiate a Redis::MarshaledClient store" do
|
7
|
+
store = Redis::Factory.create
|
8
|
+
store.should be_kind_of(Redis::MarshaledClient)
|
9
|
+
store.to_s.should == "Redis Client connected to 127.0.0.1:6379 against DB 0"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
context "when given a Hash" do
|
14
|
+
it "should allow to specify host" do
|
15
|
+
store = Redis::Factory.create :host => "localhost"
|
16
|
+
store.to_s.should == "Redis Client connected to localhost:6379 against DB 0"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should allow to specify port" do
|
20
|
+
store = Redis::Factory.create :host => "localhost", :port => 6380
|
21
|
+
store.to_s.should == "Redis Client connected to localhost:6380 against DB 0"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should allow to specify db" do
|
25
|
+
store = Redis::Factory.create :host => "localhost", :port => 6380, :db => 13
|
26
|
+
store.to_s.should == "Redis Client connected to localhost:6380 against DB 13"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should instantiate a Redis::DistributedMarshaled store" do
|
30
|
+
store = Redis::Factory.create(
|
31
|
+
{:host => "localhost", :port => 6379},
|
32
|
+
{:host => "localhost", :port => 6380}
|
33
|
+
)
|
34
|
+
store.should be_kind_of(Redis::DistributedMarshaled)
|
35
|
+
store.nodes.map {|node| node.to_s}.should == [
|
36
|
+
"Redis Client connected to localhost:6379 against DB 0",
|
37
|
+
"Redis Client connected to localhost:6380 against DB 0",
|
38
|
+
]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context "when given a String" do
|
43
|
+
it "should allow to specify host" do
|
44
|
+
store = Redis::Factory.create "localhost"
|
45
|
+
store.to_s.should == "Redis Client connected to localhost:6379 against DB 0"
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should allow to specify port" do
|
49
|
+
store = Redis::Factory.create "localhost:6380"
|
50
|
+
store.to_s.should == "Redis Client connected to localhost:6380 against DB 0"
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should allow to specify db" do
|
54
|
+
store = Redis::Factory.create "localhost:6380/13"
|
55
|
+
store.to_s.should == "Redis Client connected to localhost:6380 against DB 13"
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should instantiate a Redis::DistributedMarshaled store" do
|
59
|
+
store = Redis::Factory.create "localhost:6379", "localhost:6380"
|
60
|
+
store.should be_kind_of(Redis::DistributedMarshaled)
|
61
|
+
store.nodes.map {|node| node.to_s}.should == [
|
62
|
+
"Redis Client connected to localhost:6379 against DB 0",
|
63
|
+
"Redis Client connected to localhost:6380 against DB 0",
|
64
|
+
]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "/../spec_helper")
|
2
|
+
|
3
|
+
describe "Redis::MarshaledClient" do
|
4
|
+
before(:each) do
|
5
|
+
@store = Redis::MarshaledClient.new
|
6
|
+
@rabbit = OpenStruct.new :name => "bunny"
|
7
|
+
@white_rabbit = OpenStruct.new :color => "white"
|
8
|
+
@store.marshalled_set "rabbit", @rabbit
|
9
|
+
@store.del "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.marshalled_get("rabbit").should === @rabbit
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should marshal object on set" do
|
21
|
+
@store.marshalled_set "rabbit", @white_rabbit
|
22
|
+
@store.marshalled_get("rabbit").should === @white_rabbit
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should not unmarshal object on get if raw option is true" do
|
26
|
+
@store.marshalled_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.marshalled_set "rabbit", @white_rabbit, :raw => true
|
31
|
+
@store.marshalled_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.marshalled_set "empty_string", ""
|
36
|
+
lambda { @store.marshalled_get("empty_string").should == "" }.should_not raise_error
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should not set an object if already exist" do
|
40
|
+
@store.marshalled_setnx "rabbit", @white_rabbit
|
41
|
+
@store.marshalled_get("rabbit").should === @rabbit
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should marshal object on set_unless_exists" do
|
45
|
+
@store.marshalled_setnx "rabbit2", @white_rabbit
|
46
|
+
@store.marshalled_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.marshalled_setnx "rabbit2", @white_rabbit, :raw => true
|
51
|
+
@store.marshalled_get("rabbit2", :raw => true).should == %(#<OpenStruct color="white">)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
data/spec/spec_helper.rb
CHANGED
@@ -1,17 +1,23 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
$:.unshift(File.expand_path(File.join(File.dirname(__FILE__), "/../lib")))
|
2
|
+
ARGV << "-b"
|
3
|
+
require "rubygems"
|
4
|
+
require "bundler"
|
5
|
+
Bundler.setup
|
6
|
+
|
7
|
+
#require "vendor/gems/environment"
|
3
8
|
require "ostruct"
|
4
9
|
require "spec"
|
10
|
+
require "spec/autorun"
|
5
11
|
require "redis"
|
6
12
|
require "merb"
|
7
13
|
require "rack/cache"
|
8
14
|
require "rack/cache/metastore"
|
9
15
|
require "rack/cache/entitystore"
|
10
16
|
require "redis-store"
|
11
|
-
require "
|
17
|
+
require "active_support"
|
18
|
+
require "action_controller/session/abstract_store"
|
12
19
|
require "cache/rails/redis_store"
|
20
|
+
require "rack/session/rails"
|
13
21
|
require "cache/sinatra/redis_store"
|
14
22
|
|
15
|
-
class Redis; attr_reader :host, :port, :db end
|
16
23
|
$DEBUG = ENV["DEBUG"] === "true"
|
17
|
-
|
data/tasks/redis.tasks.rb
CHANGED
@@ -1,8 +1,19 @@
|
|
1
1
|
# steal the cool tasks from redis-rb
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
require 'rbconfig'
|
3
|
+
require "rubygems"
|
4
|
+
require "bundler"
|
5
|
+
Bundler.setup
|
6
|
+
redis_path = $:.
|
7
|
+
find {|path| path =~ /redis-/ }.
|
8
|
+
split("/").
|
9
|
+
tap do |array|
|
10
|
+
array.replace(
|
11
|
+
array[0..array.index(array.find {|segment| segment =~ /redis-/})]
|
12
|
+
)
|
13
|
+
end.
|
14
|
+
join("/")
|
15
|
+
|
16
|
+
load "#{redis_path}/tasks/redis.tasks.rb"
|
6
17
|
|
7
18
|
class RedisRunner
|
8
19
|
def self.port
|
@@ -43,7 +54,7 @@ class SlaveRedisRunner < RedisRunner
|
|
43
54
|
"/tmp/redis_slave.dtach"
|
44
55
|
end
|
45
56
|
|
46
|
-
def self.port
|
57
|
+
def self.port
|
47
58
|
6381
|
48
59
|
end
|
49
60
|
end
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis-store
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 3
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 3
|
9
|
+
- 8
|
10
|
+
version: 0.3.8
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Luca Guidi
|
@@ -9,7 +15,7 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date:
|
18
|
+
date: 2010-05-21 00:00:00 +02:00
|
13
19
|
default_executable:
|
14
20
|
dependencies: []
|
15
21
|
|
@@ -34,13 +40,16 @@ files:
|
|
34
40
|
- lib/rack/cache/redis_entitystore.rb
|
35
41
|
- lib/rack/cache/redis_metastore.rb
|
36
42
|
- lib/rack/session/merb.rb
|
43
|
+
- lib/rack/session/rails.rb
|
37
44
|
- lib/rack/session/redis.rb
|
38
45
|
- lib/redis-store.rb
|
39
|
-
- lib/redis/
|
40
|
-
- lib/redis/
|
41
|
-
- lib/redis/
|
46
|
+
- lib/redis/distributed_marshaled.rb
|
47
|
+
- lib/redis/factory.rb
|
48
|
+
- lib/redis/marshaled_client.rb
|
49
|
+
- lib/redis/namespace.rb
|
42
50
|
- redis-store.gemspec
|
43
51
|
- spec/cache/merb/redis_store_spec.rb
|
52
|
+
- spec/cache/rails/redis_session_store_spec.rb
|
44
53
|
- spec/cache/rails/redis_store_spec.rb
|
45
54
|
- spec/cache/sinatra/redis_store_spec.rb
|
46
55
|
- spec/config/master.conf
|
@@ -51,8 +60,8 @@ files:
|
|
51
60
|
- spec/rack/cache/metastore/redis_spec.rb
|
52
61
|
- spec/rack/session/redis_spec.rb
|
53
62
|
- spec/redis/distributed_marshaled_redis_spec.rb
|
54
|
-
- spec/redis/
|
55
|
-
- spec/redis/
|
63
|
+
- spec/redis/factory_spec.rb
|
64
|
+
- spec/redis/marshaled_client_spec.rb
|
56
65
|
- spec/spec_helper.rb
|
57
66
|
- tasks/redis.tasks.rb
|
58
67
|
has_rdoc: true
|
@@ -65,32 +74,39 @@ rdoc_options:
|
|
65
74
|
require_paths:
|
66
75
|
- lib
|
67
76
|
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
68
78
|
requirements:
|
69
79
|
- - ">="
|
70
80
|
- !ruby/object:Gem::Version
|
81
|
+
hash: 3
|
82
|
+
segments:
|
83
|
+
- 0
|
71
84
|
version: "0"
|
72
|
-
version:
|
73
85
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
74
87
|
requirements:
|
75
88
|
- - ">="
|
76
89
|
- !ruby/object:Gem::Version
|
90
|
+
hash: 3
|
91
|
+
segments:
|
92
|
+
- 0
|
77
93
|
version: "0"
|
78
|
-
version:
|
79
94
|
requirements: []
|
80
95
|
|
81
96
|
rubyforge_project:
|
82
|
-
rubygems_version: 1.3.
|
97
|
+
rubygems_version: 1.3.7
|
83
98
|
signing_key:
|
84
99
|
specification_version: 3
|
85
100
|
summary: Rack::Session, Rack::Cache and cache Redis stores for Ruby web frameworks.
|
86
101
|
test_files:
|
87
102
|
- spec/cache/merb/redis_store_spec.rb
|
103
|
+
- spec/cache/rails/redis_session_store_spec.rb
|
88
104
|
- spec/cache/rails/redis_store_spec.rb
|
89
105
|
- spec/cache/sinatra/redis_store_spec.rb
|
90
106
|
- spec/rack/cache/entitystore/redis_spec.rb
|
91
107
|
- spec/rack/cache/metastore/redis_spec.rb
|
92
108
|
- spec/rack/session/redis_spec.rb
|
93
109
|
- spec/redis/distributed_marshaled_redis_spec.rb
|
94
|
-
- spec/redis/
|
95
|
-
- spec/redis/
|
110
|
+
- spec/redis/factory_spec.rb
|
111
|
+
- spec/redis/marshaled_client_spec.rb
|
96
112
|
- spec/spec_helper.rb
|
@@ -1,33 +0,0 @@
|
|
1
|
-
class MarshaledRedis < Redis
|
2
|
-
def set(key, val, options = nil)
|
3
|
-
val = Marshal.dump val unless raw?(options)
|
4
|
-
super key, val, expires_in(options)
|
5
|
-
end
|
6
|
-
|
7
|
-
def set_unless_exists(key, val, options = nil)
|
8
|
-
val = Marshal.dump val unless raw?(options)
|
9
|
-
super key, val
|
10
|
-
end
|
11
|
-
|
12
|
-
def get(key, options = nil)
|
13
|
-
result = call_command([:get, key])
|
14
|
-
result = Marshal.load result if unmarshal?(result, options)
|
15
|
-
result
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
def unmarshal?(result, options)
|
20
|
-
result && result.size > 0 && !raw?(options)
|
21
|
-
end
|
22
|
-
|
23
|
-
def raw?(options)
|
24
|
-
options && options[:raw]
|
25
|
-
end
|
26
|
-
|
27
|
-
def expires_in(options)
|
28
|
-
if options
|
29
|
-
# Rack::Session Merb Rails/Sinatra
|
30
|
-
options[:expire_after] || options[:expires_in] || options[:expire_in]
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
data/lib/redis/redis_factory.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
class RedisFactory
|
2
|
-
class << self
|
3
|
-
def create(*addresses)
|
4
|
-
addresses = extract_addresses(addresses)
|
5
|
-
if addresses.size > 1
|
6
|
-
DistributedMarshaledRedis.new addresses
|
7
|
-
else
|
8
|
-
MarshaledRedis.new addresses.first || {}
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
private
|
13
|
-
def extract_addresses(addresses)
|
14
|
-
addresses = addresses.flatten.compact
|
15
|
-
addresses.inject([]) do |result, address|
|
16
|
-
host, port = address.split /\:/
|
17
|
-
port, db = port.split /\// if port
|
18
|
-
address = {}
|
19
|
-
address[:host] = host if host
|
20
|
-
address[:port] = port if port
|
21
|
-
address[:db] = db.to_i if db
|
22
|
-
result << address
|
23
|
-
result
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
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
|