redis-store 0.3.9 → 1.0.0.beta1
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/Gemfile +22 -8
- data/MIT-LICENSE +1 -1
- data/README.md +32 -11
- data/Rakefile +7 -0
- data/VERSION +1 -1
- data/lib/cache/rails/redis_store.rb +46 -15
- data/lib/rack/session/rails.rb +57 -48
- data/lib/redis/distributed_marshaled.rb +11 -1
- data/lib/redis/marshaled_client.rb +8 -4
- data/lib/redis-store.rb +8 -1
- data/lib/redis_store/version.rb +10 -0
- data/redis-store.gemspec +9 -5
- data/spec/cache/rails/redis_session_store_spec.rb +60 -62
- data/spec/cache/rails/redis_store_spec.rb +39 -12
- data/spec/config/master.conf +195 -54
- data/spec/config/single.conf +195 -54
- data/spec/config/slave.conf +195 -54
- data/spec/rack/cache/entitystore/redis_spec.rb +4 -4
- data/spec/redis/distributed_marshaled_redis_spec.rb +1 -1
- data/spec/redis/marshaled_client_spec.rb +8 -2
- data/spec/redis_store/version_spec.rb +7 -0
- data/spec/spec_helper.rb +6 -1
- data/tasks/redis.tasks.rb +12 -41
- metadata +33 -14
- data/Gemfile.lock +0 -181
- data/lib/redis/namespace.rb +0 -9
data/Gemfile
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
source :gemcutter
|
2
|
-
gem "redis", "
|
2
|
+
gem "redis", ">= 2.0.0"
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
group :development do
|
5
|
+
gem "jeweler"
|
6
|
+
gem "git"
|
7
|
+
end
|
8
|
+
|
9
|
+
group :development, :test, :rails3 do
|
6
10
|
gem "ruby-debug"
|
7
11
|
gem "rspec"
|
8
|
-
gem "rack", "1.0.0"
|
9
12
|
gem "rack-cache"
|
10
|
-
gem "activesupport", "2.3.5"
|
11
|
-
gem "actionpack", "2.3.5"
|
12
13
|
gem "merb"
|
13
|
-
gem "
|
14
|
-
|
14
|
+
gem "methopara" if RUBY_VERSION.match /1\.9/
|
15
|
+
end
|
16
|
+
|
17
|
+
if ENV["REDIS_STORE_ENV"] == "rails3"
|
18
|
+
group :rails3 do
|
19
|
+
gem "rack", "1.1.0"
|
20
|
+
gem "activesupport", "3.0.0.beta4"
|
21
|
+
gem "actionpack", "3.0.0.beta4"
|
22
|
+
end
|
23
|
+
else
|
24
|
+
group :test do
|
25
|
+
gem "rack", "1.0.0"
|
26
|
+
gem "activesupport", "2.3.5"
|
27
|
+
gem "actionpack", "2.3.5"
|
28
|
+
end
|
15
29
|
end
|
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
@@ -4,29 +4,38 @@
|
|
4
4
|
|
5
5
|
Download and install Redis from [http://code.google.com/p/redis/](http://code.google.com/p/redis/)
|
6
6
|
|
7
|
-
|
8
|
-
tar -
|
9
|
-
mv redis-
|
7
|
+
wget http://redis.googlecode.com/files/redis-2.0.0-rc1.tar.gz
|
8
|
+
tar -zxf redis-2.0.0-rc1.tar.gz
|
9
|
+
mv redis-2.0.0-rc1 redis
|
10
10
|
cd redis
|
11
11
|
make
|
12
12
|
|
13
|
-
Install the
|
13
|
+
Install the gem
|
14
14
|
|
15
|
-
sudo gem install redis
|
15
|
+
sudo gem install redis-store
|
16
16
|
|
17
17
|
## Cache store
|
18
18
|
|
19
19
|
Provides a cache store for your Ruby web framework of choice.
|
20
20
|
|
21
|
-
### Rails
|
21
|
+
### Rails 2.x
|
22
22
|
|
23
|
-
config.gem "redis-store"
|
24
|
-
|
23
|
+
config.gem "redis-store"
|
24
|
+
config.cache_store = :redis_store
|
25
|
+
|
26
|
+
### Rails 3.x
|
27
|
+
|
28
|
+
# Gemfile
|
29
|
+
gem 'rails', '3.0.0.beta4'
|
30
|
+
gem 'redis'
|
31
|
+
gem 'redis-store', '1.0.0.beta1'
|
32
|
+
|
33
|
+
# config/environments/production.rb
|
25
34
|
config.cache_store = :redis_store
|
26
35
|
|
27
36
|
### Merb
|
28
37
|
|
29
|
-
dependency "redis-store", "0.
|
38
|
+
dependency "redis-store", "1.0.0.beta1"
|
30
39
|
dependency("merb-cache", merb_gems_version) do
|
31
40
|
Merb::Cache.setup do
|
32
41
|
register(:redis, Merb::Cache::RedisStore, :servers => ["127.0.0.1:6379"])
|
@@ -56,14 +65,24 @@ Provides a Redis store for Rack::Session. See [http://rack.rubyforge.org/doc/Rac
|
|
56
65
|
use Rack::Session::Redis
|
57
66
|
run Application.new
|
58
67
|
|
59
|
-
### Rails
|
68
|
+
### Rails 2.x
|
60
69
|
|
61
70
|
config.gem "redis-store"
|
62
71
|
ActionController::Base.session_store = :redis_session_store
|
63
72
|
|
73
|
+
### Rails 3.x
|
74
|
+
|
75
|
+
# Gemfile
|
76
|
+
gem 'rails', '3.0.0.beta4'
|
77
|
+
gem 'redis'
|
78
|
+
gem 'redis-store', '1.0.0.beta1'
|
79
|
+
|
80
|
+
# config/initializers/session_store.rb
|
81
|
+
Rails.application.config.session_store :redis_session_store
|
82
|
+
|
64
83
|
### Merb
|
65
84
|
|
66
|
-
dependency "redis-store", "0.
|
85
|
+
dependency "redis-store", "1.0.0.beta1"
|
67
86
|
Merb::Config.use do |c|
|
68
87
|
c[:session_store] = "redis"
|
69
88
|
end
|
@@ -104,9 +123,11 @@ Provides a Redis store for HTTP caching. See [http://github.com/rtomayko/rack-ca
|
|
104
123
|
git clone git://github.com/jodosha/redis-store.git
|
105
124
|
cd redis-store
|
106
125
|
bundle install
|
126
|
+
REDIS_STORE_ENV=rails3 bundle install # to install Rails 3.x gems
|
107
127
|
rake dtach:install
|
108
128
|
rake redis:install
|
109
129
|
rake
|
130
|
+
REDIS_STORE_ENV=rails3 rake # to test against Rails 3.x
|
110
131
|
|
111
132
|
If you are on **Snow Leopard** you have to run `env ARCHFLAGS="-arch x86_64" bundle install`
|
112
133
|
|
data/Rakefile
CHANGED
@@ -17,6 +17,7 @@ begin
|
|
17
17
|
gemspec.homepage = "http://github.com/jodosha/redis-store"
|
18
18
|
gemspec.authors = [ "Luca Guidi" ]
|
19
19
|
gemspec.executables = [ ]
|
20
|
+
gemspec.add_dependency "redis", ">= 2.0.0"
|
20
21
|
end
|
21
22
|
|
22
23
|
Jeweler::GemcutterTasks.new
|
@@ -59,6 +60,12 @@ namespace :redis_cluster do
|
|
59
60
|
end
|
60
61
|
end
|
61
62
|
|
63
|
+
namespace :bundle do
|
64
|
+
task :clean do
|
65
|
+
system "rm -rf ~/.bundle/ ~/.gem/ .bundle/ Gemfile.lock"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
62
69
|
# courtesy of http://github.com/ezmobius/redis-rb team
|
63
70
|
load "tasks/redis.tasks.rb"
|
64
71
|
def invoke_with_redis_cluster(task_name)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
1.0.0.beta1
|
@@ -1,18 +1,6 @@
|
|
1
|
-
module
|
1
|
+
module RedisStore
|
2
2
|
module Cache
|
3
|
-
|
4
|
-
# Instantiate the store.
|
5
|
-
#
|
6
|
-
# Example:
|
7
|
-
# RedisStore.new # => host: localhost, port: 6379, db: 0
|
8
|
-
# RedisStore.new "example.com" # => host: example.com, port: 6379, db: 0
|
9
|
-
# RedisStore.new "example.com:23682" # => host: example.com, port: 23682, db: 0
|
10
|
-
# RedisStore.new "example.com:23682/1" # => host: example.com, port: 23682, db: 1
|
11
|
-
# RedisStore.new "localhost:6379/0", "localhost:6380/0" # => instantiate a cluster
|
12
|
-
def initialize(*addresses)
|
13
|
-
@data = Redis::Factory.create(addresses)
|
14
|
-
end
|
15
|
-
|
3
|
+
module Rails2
|
16
4
|
def write(key, value, options = nil)
|
17
5
|
super
|
18
6
|
method = options && options[:unless_exist] ? :marshalled_setnx : :marshalled_set
|
@@ -28,6 +16,49 @@ module ActiveSupport
|
|
28
16
|
super
|
29
17
|
@data.del key
|
30
18
|
end
|
19
|
+
end
|
20
|
+
|
21
|
+
module Rails3
|
22
|
+
protected
|
23
|
+
def write_entry(key, entry, options)
|
24
|
+
method = options && options[:unless_exist] ? :marshalled_setnx : :marshalled_set
|
25
|
+
@data.send method, key, entry, options
|
26
|
+
end
|
27
|
+
|
28
|
+
def read_entry(key, options)
|
29
|
+
entry = @data.marshalled_get key, options
|
30
|
+
if entry
|
31
|
+
entry.is_a?(ActiveSupport::Cache::Entry) ? entry : ActiveSupport::Cache::Entry.new(entry)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def delete_entry(key, options)
|
36
|
+
@data.del key
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
module Store
|
41
|
+
include RedisStore.rails3? ? Rails3 : Rails2
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
module ActiveSupport
|
47
|
+
module Cache
|
48
|
+
class RedisStore < Store
|
49
|
+
include ::RedisStore::Cache::Store
|
50
|
+
|
51
|
+
# Instantiate the store.
|
52
|
+
#
|
53
|
+
# Example:
|
54
|
+
# RedisStore.new # => host: localhost, port: 6379, db: 0
|
55
|
+
# RedisStore.new "example.com" # => host: example.com, port: 6379, db: 0
|
56
|
+
# RedisStore.new "example.com:23682" # => host: example.com, port: 23682, db: 0
|
57
|
+
# RedisStore.new "example.com:23682/1" # => host: example.com, port: 23682, db: 1
|
58
|
+
# RedisStore.new "localhost:6379/0", "localhost:6380/0" # => instantiate a cluster
|
59
|
+
def initialize(*addresses)
|
60
|
+
@data = Redis::Factory.create(addresses)
|
61
|
+
end
|
31
62
|
|
32
63
|
def exist?(key, options = nil)
|
33
64
|
super
|
@@ -91,7 +122,7 @@ module ActiveSupport
|
|
91
122
|
# Example:
|
92
123
|
# cache.del_matched "rab*"
|
93
124
|
def delete_matched(matcher, options = nil)
|
94
|
-
|
125
|
+
log "delete_matched", matcher, options
|
95
126
|
@data.keys(matcher).each { |key| @data.del key }
|
96
127
|
end
|
97
128
|
|
data/lib/rack/session/rails.rb
CHANGED
@@ -1,61 +1,70 @@
|
|
1
|
-
module
|
2
|
-
module
|
3
|
-
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
# :
|
9
|
-
# :
|
10
|
-
# :
|
11
|
-
# :
|
12
|
-
# :
|
13
|
-
# :
|
1
|
+
module RedisStore
|
2
|
+
module Rack
|
3
|
+
module Session
|
4
|
+
# Redis session storage for Rails, and for Rails only. Derived from
|
5
|
+
# the MemCacheStore code, simply dropping in Redis instead.
|
6
|
+
#
|
7
|
+
# Options:
|
8
|
+
# :key => Same as with the other cookie stores, key name
|
9
|
+
# :secret => Encryption secret for the key
|
10
|
+
# :host => Redis host name, default is localhost
|
11
|
+
# :port => Redis port, default is 6379
|
12
|
+
# :db => Database number, defaults to 0. Useful to separate your session storage from other data
|
13
|
+
# :key_prefix => Prefix for keys used in Redis, e.g. myapp-. Useful to separate session storage keys visibly from others
|
14
|
+
# :expire_after => A number in seconds to set the timeout interval for the session. Will map directly to expiry in Redis
|
15
|
+
module Rails
|
16
|
+
def initialize(app, options = {})
|
17
|
+
# Support old :expires option
|
18
|
+
options[:expire_after] ||= options[:expires]
|
14
19
|
|
15
|
-
|
20
|
+
super
|
16
21
|
|
17
|
-
|
18
|
-
|
19
|
-
|
22
|
+
@options = { :key_prefix => "" }.update(options)
|
23
|
+
servers = [options[:servers]].flatten.compact.map do |server_options|
|
24
|
+
{
|
25
|
+
:namespace => 'rack:session',
|
26
|
+
:host => 'localhost',
|
27
|
+
:port => '6379',
|
28
|
+
:db => 0
|
29
|
+
}.update(Redis::Factory.convert_to_redis_client_options(server_options))
|
30
|
+
end
|
20
31
|
|
21
|
-
|
22
|
-
|
23
|
-
@options = { :key_prefix => "" }.update(options)
|
24
|
-
servers = [options[:servers]].flatten.compact.map do |server_options|
|
25
|
-
{
|
26
|
-
:namespace => 'rack:session',
|
27
|
-
:host => 'localhost',
|
28
|
-
:port => '6379',
|
29
|
-
:db => 0
|
30
|
-
}.update(Redis::Factory.convert_to_redis_client_options(server_options))
|
32
|
+
@pool = Redis::Factory.create(*servers)
|
31
33
|
end
|
32
34
|
|
33
|
-
|
34
|
-
|
35
|
+
private
|
36
|
+
def prefixed(sid)
|
37
|
+
"#{@options[:key_prefix]}#{sid}"
|
38
|
+
end
|
35
39
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
+
def get_session(env, sid)
|
41
|
+
sid ||= generate_sid
|
42
|
+
begin
|
43
|
+
session = @pool.marshalled_get(prefixed(sid)) || {}
|
44
|
+
rescue Errno::ECONNREFUSED
|
45
|
+
session = {}
|
46
|
+
end
|
47
|
+
[sid, session]
|
48
|
+
end
|
40
49
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
50
|
+
def set_session(env, sid, session_data)
|
51
|
+
options = env['rack.session.options']
|
52
|
+
@pool.marshalled_set(prefixed(sid), session_data, options)
|
53
|
+
return true
|
45
54
|
rescue Errno::ECONNREFUSED
|
46
|
-
|
55
|
+
return false
|
47
56
|
end
|
48
|
-
[sid, session]
|
49
|
-
end
|
50
|
-
|
51
|
-
def set_session(env, sid, session_data)
|
52
|
-
options = env['rack.session.options']
|
53
|
-
@pool.marshalled_set(prefixed(sid), session_data, options)
|
54
|
-
return true
|
55
|
-
rescue Errno::ECONNREFUSED
|
56
|
-
return false
|
57
57
|
end
|
58
|
-
|
59
58
|
end
|
60
59
|
end
|
61
60
|
end
|
61
|
+
|
62
|
+
unless defined?(ActionDispatch) # rails 2.3.x
|
63
|
+
class ActionController::Session::RedisSessionStore < ActionController::Session::AbstractStore
|
64
|
+
include RedisStore::Rack::Session::Rails
|
65
|
+
end
|
66
|
+
else # rails 3.x
|
67
|
+
class ActionDispatch::Session::RedisSessionStore < ActionDispatch::Session::AbstractStore
|
68
|
+
include RedisStore::Rack::Session::Rails
|
69
|
+
end
|
70
|
+
end
|
@@ -13,6 +13,16 @@ class Redis
|
|
13
13
|
ring.nodes
|
14
14
|
end
|
15
15
|
|
16
|
-
|
16
|
+
def marshalled_set(key, val, options = nil)
|
17
|
+
node_for(key).marshalled_set(key, val, options)
|
18
|
+
end
|
19
|
+
|
20
|
+
def marshalled_get(key, options = nil)
|
21
|
+
node_for(key).marshalled_get(key, options)
|
22
|
+
end
|
23
|
+
|
24
|
+
def marshalled_setnx(key, value, options = nil)
|
25
|
+
node_for(key).marshalled_setnx(key, value, options)
|
26
|
+
end
|
17
27
|
end
|
18
28
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
class Redis
|
2
|
-
class MarshaledClient <
|
2
|
+
class MarshaledClient < self
|
3
3
|
def marshalled_set(key, val, options = nil)
|
4
4
|
val = marshal_value(val, options)
|
5
|
-
if
|
6
|
-
|
5
|
+
if ttl = expires_in(options)
|
6
|
+
setex key, ttl, val
|
7
7
|
else
|
8
8
|
set key, val
|
9
9
|
end
|
@@ -26,11 +26,15 @@ class Redis
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def marshalled_get(key, options = nil)
|
29
|
-
result =
|
29
|
+
result = @client.call(:get, key)
|
30
30
|
result = Marshal.load result if unmarshal?(result, options)
|
31
31
|
result
|
32
32
|
end
|
33
33
|
|
34
|
+
def to_s
|
35
|
+
"Redis Client connected to #{@client.host}:#{@client.port} against DB #{@client.db}"
|
36
|
+
end
|
37
|
+
|
34
38
|
private
|
35
39
|
def marshal_value(val, options)
|
36
40
|
raw?(options) ? val : Marshal.dump(val)
|
data/lib/redis-store.rb
CHANGED
@@ -1,8 +1,15 @@
|
|
1
1
|
require "redis"
|
2
|
-
require "redis/
|
2
|
+
require "redis/distributed"
|
3
3
|
require "redis/factory"
|
4
4
|
require "redis/marshaled_client"
|
5
5
|
require "redis/distributed_marshaled"
|
6
|
+
require "redis_store/version"
|
7
|
+
|
8
|
+
module RedisStore
|
9
|
+
def self.rails3? #:nodoc:
|
10
|
+
defined?(::Rails) && ::Rails.version =~ /3\.0\.0/
|
11
|
+
end
|
12
|
+
end
|
6
13
|
|
7
14
|
# Cache store
|
8
15
|
if defined?(Sinatra)
|
data/redis-store.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{redis-store}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "1.0.0.beta1"
|
9
9
|
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new("
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Luca Guidi"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-06-09}
|
13
13
|
s.description = %q{Rack::Session, Rack::Cache and cache Redis stores for Ruby web frameworks.}
|
14
14
|
s.email = %q{guidi.luca@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -18,7 +18,6 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.files = [
|
19
19
|
".gitignore",
|
20
20
|
"Gemfile",
|
21
|
-
"Gemfile.lock",
|
22
21
|
"MIT-LICENSE",
|
23
22
|
"README.md",
|
24
23
|
"Rakefile",
|
@@ -35,7 +34,7 @@ Gem::Specification.new do |s|
|
|
35
34
|
"lib/redis/distributed_marshaled.rb",
|
36
35
|
"lib/redis/factory.rb",
|
37
36
|
"lib/redis/marshaled_client.rb",
|
38
|
-
"lib/
|
37
|
+
"lib/redis_store/version.rb",
|
39
38
|
"redis-store.gemspec",
|
40
39
|
"spec/cache/merb/redis_store_spec.rb",
|
41
40
|
"spec/cache/rails/redis_session_store_spec.rb",
|
@@ -51,6 +50,7 @@ Gem::Specification.new do |s|
|
|
51
50
|
"spec/redis/distributed_marshaled_redis_spec.rb",
|
52
51
|
"spec/redis/factory_spec.rb",
|
53
52
|
"spec/redis/marshaled_client_spec.rb",
|
53
|
+
"spec/redis_store/version_spec.rb",
|
54
54
|
"spec/spec_helper.rb",
|
55
55
|
"tasks/redis.tasks.rb"
|
56
56
|
]
|
@@ -70,6 +70,7 @@ Gem::Specification.new do |s|
|
|
70
70
|
"spec/redis/distributed_marshaled_redis_spec.rb",
|
71
71
|
"spec/redis/factory_spec.rb",
|
72
72
|
"spec/redis/marshaled_client_spec.rb",
|
73
|
+
"spec/redis_store/version_spec.rb",
|
73
74
|
"spec/spec_helper.rb"
|
74
75
|
]
|
75
76
|
|
@@ -78,9 +79,12 @@ Gem::Specification.new do |s|
|
|
78
79
|
s.specification_version = 3
|
79
80
|
|
80
81
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
82
|
+
s.add_runtime_dependency(%q<redis>, [">= 2.0.0"])
|
81
83
|
else
|
84
|
+
s.add_dependency(%q<redis>, [">= 2.0.0"])
|
82
85
|
end
|
83
86
|
else
|
87
|
+
s.add_dependency(%q<redis>, [">= 2.0.0"])
|
84
88
|
end
|
85
89
|
end
|
86
90
|
|
@@ -1,77 +1,75 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), "/../../spec_helper")
|
2
|
+
RAILS_SESSION_STORE_CLASS = RedisStore.rails3? ? ActionDispatch::Session::RedisSessionStore : ActionController::Session::RedisSessionStore
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
public :get_session, :set_session
|
17
|
-
end
|
18
|
-
store.set_session({'rack.session.options' => {}}, "rabbit", @rabbit)
|
19
|
-
store.pool.del "counter"
|
20
|
-
store.pool.del "rub-a-dub"
|
21
|
-
end
|
4
|
+
describe RAILS_SESSION_STORE_CLASS do
|
5
|
+
attr_reader :app
|
6
|
+
|
7
|
+
before :each do
|
8
|
+
@app = Object.new
|
9
|
+
@store = RAILS_SESSION_STORE_CLASS.new(app)
|
10
|
+
@dstore = RAILS_SESSION_STORE_CLASS.new app, :servers => ["localhost:6380/1", "localhost:6381/1"]
|
11
|
+
@rabbit = OpenStruct.new :name => "bunny"
|
12
|
+
@white_rabbit = OpenStruct.new :color => "white"
|
13
|
+
with_store_management do |store|
|
14
|
+
class << store
|
15
|
+
attr_reader :pool
|
16
|
+
public :get_session, :set_session
|
22
17
|
end
|
18
|
+
store.set_session({'rack.session.options' => {}}, "rabbit", @rabbit)
|
19
|
+
store.pool.del "counter"
|
20
|
+
store.pool.del "rub-a-dub"
|
21
|
+
end
|
22
|
+
end
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
it "should accept connection params" do
|
25
|
+
redis = instantiate_store
|
26
|
+
redis.to_s.should == "Redis Client connected to 127.0.0.1:6379 against DB 0"
|
27
27
|
|
28
|
-
|
29
|
-
|
28
|
+
redis = instantiate_store :servers => "localhost"
|
29
|
+
redis.to_s.should == "Redis Client connected to localhost:6379 against DB 0"
|
30
30
|
|
31
|
-
|
32
|
-
|
31
|
+
redis = instantiate_store :servers => "localhost:6380"
|
32
|
+
redis.to_s.should == "Redis Client connected to localhost:6380 against DB 0"
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
34
|
+
redis = instantiate_store :servers => "localhost:6380/13"
|
35
|
+
redis.to_s.should == "Redis Client connected to localhost:6380 against DB 13"
|
36
|
+
end
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
38
|
+
it "should instantiate a ring" do
|
39
|
+
store = instantiate_store
|
40
|
+
store.should be_kind_of(Redis::MarshaledClient)
|
41
|
+
store = instantiate_store :servers => ["localhost:6379/0", "localhost:6379/1"]
|
42
|
+
store.should be_kind_of(Redis::DistributedMarshaled)
|
43
|
+
end
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
45
|
+
it "should read the data" do
|
46
|
+
with_store_management do |store|
|
47
|
+
store.get_session({}, "rabbit").should === ["rabbit", @rabbit]
|
48
|
+
end
|
49
|
+
end
|
50
50
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
51
|
+
it "should write the data" do
|
52
|
+
with_store_management do |store|
|
53
|
+
store.set_session({"rack.session.options" => {}}, "rabbit", @white_rabbit)
|
54
|
+
store.get_session({}, "rabbit").should === ["rabbit", @white_rabbit]
|
55
|
+
end
|
56
|
+
end
|
57
57
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
58
|
+
it "should write the data with expiration time" do
|
59
|
+
with_store_management do |store|
|
60
|
+
store.set_session({"rack.session.options" => {:expires_in => 1.second}}, "rabbit", @white_rabbit)
|
61
|
+
store.get_session({}, "rabbit").should === ["rabbit", @white_rabbit]; sleep 2
|
62
|
+
store.get_session({}, "rabbit").should === ["rabbit", {}]
|
63
|
+
end
|
64
|
+
end
|
65
65
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
66
|
+
private
|
67
|
+
def instantiate_store(params={})
|
68
|
+
RAILS_SESSION_STORE_CLASS.new(app, params).instance_variable_get(:@pool)
|
69
|
+
end
|
70
70
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
end
|
71
|
+
def with_store_management
|
72
|
+
yield @store
|
73
|
+
yield @dstore
|
75
74
|
end
|
76
|
-
end
|
77
75
|
end
|