redis-store 1.0.0.beta2 → 1.0.0.beta3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of redis-store might be problematic. Click here for more details.

Files changed (51) hide show
  1. data/CHANGELOG +74 -23
  2. data/Gemfile +12 -7
  3. data/Gemfile.lock +183 -0
  4. data/MIT-LICENSE +1 -1
  5. data/README.md +49 -14
  6. data/Rakefile +8 -4
  7. data/VERSION +1 -1
  8. data/lib/{rack/session/rails.rb → action_controller/session/redis_session_store.rb} +24 -20
  9. data/lib/{cache/rails → active_support/cache}/redis_store.rb +64 -22
  10. data/lib/cache/merb/redis_store.rb +20 -8
  11. data/lib/cache/sinatra/redis_store.rb +20 -8
  12. data/lib/i18n/backend/redis.rb +67 -0
  13. data/lib/rack/cache/redis_metastore.rb +4 -4
  14. data/lib/rack/session/redis.rb +7 -7
  15. data/lib/redis-store.rb +16 -14
  16. data/lib/redis/distributed_store.rb +35 -0
  17. data/lib/redis/factory.rb +29 -10
  18. data/lib/redis/store.rb +30 -0
  19. data/lib/redis/store/interface.rb +17 -0
  20. data/lib/redis/store/marshalling.rb +41 -0
  21. data/lib/redis/store/namespace.rb +54 -0
  22. data/lib/redis/store/ttl.rb +37 -0
  23. data/lib/redis/store/version.rb +12 -0
  24. data/redis-store.gemspec +32 -20
  25. data/spec/action_controller/session/redis_session_store_spec.rb +121 -0
  26. data/spec/{cache/rails → active_support/cache}/redis_store_spec.rb +93 -19
  27. data/spec/cache/merb/redis_store_spec.rb +14 -11
  28. data/spec/cache/sinatra/redis_store_spec.rb +14 -11
  29. data/spec/config/master.conf +1 -1
  30. data/spec/config/single.conf +1 -1
  31. data/spec/config/slave.conf +1 -1
  32. data/spec/i18n/backend/redis_spec.rb +56 -0
  33. data/spec/rack/cache/entitystore/redis_spec.rb +10 -8
  34. data/spec/rack/cache/metastore/redis_spec.rb +2 -2
  35. data/spec/rack/session/redis_spec.rb +6 -6
  36. data/spec/redis/distributed_store_spec.rb +47 -0
  37. data/spec/redis/factory_spec.rb +58 -16
  38. data/spec/redis/store/interface_spec.rb +23 -0
  39. data/spec/redis/store/marshalling_spec.rb +83 -0
  40. data/spec/redis/store/namespace_spec.rb +76 -0
  41. data/spec/redis/store/version_spec.rb +7 -0
  42. data/spec/spec_helper.rb +16 -5
  43. data/tasks/redis.tasks.rb +19 -12
  44. metadata +33 -21
  45. data/lib/redis/distributed_marshaled.rb +0 -28
  46. data/lib/redis/marshaled_client.rb +0 -65
  47. data/lib/redis_store/version.rb +0 -10
  48. data/spec/rack/session/redis_session_store_spec.rb +0 -75
  49. data/spec/redis/distributed_marshaled_redis_spec.rb +0 -33
  50. data/spec/redis/marshaled_client_spec.rb +0 -83
  51. data/spec/redis_store/version_spec.rb +0 -7
data/tasks/redis.tasks.rb CHANGED
@@ -9,7 +9,7 @@ class RedisRunner
9
9
  end
10
10
 
11
11
  def self.redisdir
12
- "/tmp/redis/"
12
+ @@redisdir ||= File.expand_path File.join(File.dirname(__FILE__), '..', 'vendor', 'redis')
13
13
  end
14
14
 
15
15
  def self.redisconfdir
@@ -124,17 +124,19 @@ namespace :redis do
124
124
  end
125
125
 
126
126
  desc 'Install the lastest verison of Redis from Github (requires git, duh)'
127
- task :install => [:about, :download, :make] do
127
+ task :install => [ :about, :download, :make ] do
128
128
  %w(redis-benchmark redis-cli redis-server).each do |bin|
129
- sh "sudo cp /tmp/redis/#{bin} /usr/bin/"
129
+ if File.exist?(path = "#{RedisRunner.redisdir}/src/#{bin}")
130
+ sh "sudo cp #{path} /usr/bin/"
131
+ else
132
+ sh "sudo cp #{RedisRunner.redisdir}/#{bin} /usr/bin/"
133
+ end
130
134
  end
131
135
 
132
136
  puts "Installed redis-benchmark, redis-cli and redis-server to /usr/bin/"
133
137
 
134
- unless File.exists?('/etc/redis.conf')
135
- sh 'sudo cp /tmp/redis/redis.conf /etc/'
136
- puts "Installed redis.conf to /etc/ \n You should look at this file!"
137
- end
138
+ sh "sudo cp #{RedisRunner.redisdir}/redis.conf /etc/"
139
+ puts "Installed redis.conf to /etc/ \n You should look at this file!"
138
140
  end
139
141
 
140
142
  task :make do
@@ -144,13 +146,18 @@ namespace :redis do
144
146
 
145
147
  desc "Download package"
146
148
  task :download do
147
- sh 'rm -rf /tmp/redis/' if File.exists?("#{RedisRunner.redisdir}/.svn")
148
- sh 'git clone git://github.com/antirez/redis.git /tmp/redis' unless File.exists?(RedisRunner.redisdir)
149
+ require 'git'
150
+
151
+ sh "rm -rf #{RedisRunner.redisdir} && mkdir -p vendor && rm -rf redis"
152
+ Git.clone("git://github.com/antirez/redis.git", "redis")
153
+ sh "mv redis vendor"
149
154
 
150
- if File.exists?("#{RedisRunner.redisdir}/.git")
151
- arguments = ENV['COMMIT'].nil? ? "pull" : "reset --hard #{ENV['COMMIT']}"
152
- sh "cd #{RedisRunner.redisdir} && git #{arguments}"
155
+ commit = case ENV['VERSION']
156
+ when "1.2.6" then "570e43c8285a4e5e3f31"
153
157
  end
158
+
159
+ arguments = commit.nil? ? "pull origin master" : "reset --hard #{commit}"
160
+ sh "cd #{RedisRunner.redisdir} && git #{arguments}"
154
161
  end
155
162
 
156
163
  desc "Open an IRb session"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-store
3
3
  version: !ruby/object:Gem::Version
4
- hash: -1848230054
4
+ hash: -1848230053
5
5
  prerelease: true
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
9
  - 0
10
- - beta2
11
- version: 1.0.0.beta2
10
+ - beta3
11
+ version: 1.0.0.beta3
12
12
  platform: ruby
13
13
  authors:
14
14
  - Luca Guidi
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-06-12 00:00:00 +02:00
19
+ date: 2010-09-10 00:00:00 +02:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -35,7 +35,7 @@ dependencies:
35
35
  version: 2.0.0
36
36
  type: :runtime
37
37
  version_requirements: *id001
38
- description: Rack::Session, Rack::Cache and cache Redis stores for Ruby web frameworks.
38
+ description: Namespaced Rack::Session, Rack::Cache, I18n and cache Redis stores for Ruby web frameworks.
39
39
  email: guidi.luca@gmail.com
40
40
  executables: []
41
41
 
@@ -47,39 +47,48 @@ files:
47
47
  - .gitignore
48
48
  - CHANGELOG
49
49
  - Gemfile
50
+ - Gemfile.lock
50
51
  - MIT-LICENSE
51
52
  - README.md
52
53
  - Rakefile
53
54
  - VERSION
55
+ - lib/action_controller/session/redis_session_store.rb
56
+ - lib/active_support/cache/redis_store.rb
54
57
  - lib/cache/merb/redis_store.rb
55
- - lib/cache/rails/redis_store.rb
56
58
  - lib/cache/sinatra/redis_store.rb
59
+ - lib/i18n/backend/redis.rb
57
60
  - lib/rack/cache/redis_entitystore.rb
58
61
  - lib/rack/cache/redis_metastore.rb
59
62
  - lib/rack/session/merb.rb
60
- - lib/rack/session/rails.rb
61
63
  - lib/rack/session/redis.rb
62
64
  - lib/redis-store.rb
63
- - lib/redis/distributed_marshaled.rb
65
+ - lib/redis/distributed_store.rb
64
66
  - lib/redis/factory.rb
65
- - lib/redis/marshaled_client.rb
66
- - lib/redis_store/version.rb
67
+ - lib/redis/store.rb
68
+ - lib/redis/store/interface.rb
69
+ - lib/redis/store/marshalling.rb
70
+ - lib/redis/store/namespace.rb
71
+ - lib/redis/store/ttl.rb
72
+ - lib/redis/store/version.rb
67
73
  - redis-store.gemspec
74
+ - spec/action_controller/session/redis_session_store_spec.rb
75
+ - spec/active_support/cache/redis_store_spec.rb
68
76
  - spec/cache/merb/redis_store_spec.rb
69
- - spec/cache/rails/redis_store_spec.rb
70
77
  - spec/cache/sinatra/redis_store_spec.rb
71
78
  - spec/config/master.conf
72
79
  - spec/config/single.conf
73
80
  - spec/config/slave.conf
81
+ - spec/i18n/backend/redis_spec.rb
74
82
  - spec/rack/cache/entitystore/pony.jpg
75
83
  - spec/rack/cache/entitystore/redis_spec.rb
76
84
  - spec/rack/cache/metastore/redis_spec.rb
77
- - spec/rack/session/redis_session_store_spec.rb
78
85
  - spec/rack/session/redis_spec.rb
79
- - spec/redis/distributed_marshaled_redis_spec.rb
86
+ - spec/redis/distributed_store_spec.rb
80
87
  - spec/redis/factory_spec.rb
81
- - spec/redis/marshaled_client_spec.rb
82
- - spec/redis_store/version_spec.rb
88
+ - spec/redis/store/interface_spec.rb
89
+ - spec/redis/store/marshalling_spec.rb
90
+ - spec/redis/store/namespace_spec.rb
91
+ - spec/redis/store/version_spec.rb
83
92
  - spec/spec_helper.rb
84
93
  - tasks/redis.tasks.rb
85
94
  has_rdoc: true
@@ -117,17 +126,20 @@ rubyforge_project:
117
126
  rubygems_version: 1.3.7
118
127
  signing_key:
119
128
  specification_version: 3
120
- summary: Rack::Session, Rack::Cache and cache Redis stores for Ruby web frameworks.
129
+ summary: Namespaced Rack::Session, Rack::Cache, I18n and cache Redis stores for Ruby web frameworks.
121
130
  test_files:
131
+ - spec/action_controller/session/redis_session_store_spec.rb
132
+ - spec/active_support/cache/redis_store_spec.rb
122
133
  - spec/cache/merb/redis_store_spec.rb
123
- - spec/cache/rails/redis_store_spec.rb
124
134
  - spec/cache/sinatra/redis_store_spec.rb
135
+ - spec/i18n/backend/redis_spec.rb
125
136
  - spec/rack/cache/entitystore/redis_spec.rb
126
137
  - spec/rack/cache/metastore/redis_spec.rb
127
- - spec/rack/session/redis_session_store_spec.rb
128
138
  - spec/rack/session/redis_spec.rb
129
- - spec/redis/distributed_marshaled_redis_spec.rb
139
+ - spec/redis/distributed_store_spec.rb
130
140
  - spec/redis/factory_spec.rb
131
- - spec/redis/marshaled_client_spec.rb
132
- - spec/redis_store/version_spec.rb
141
+ - spec/redis/store/interface_spec.rb
142
+ - spec/redis/store/marshalling_spec.rb
143
+ - spec/redis/store/namespace_spec.rb
144
+ - spec/redis/store/version_spec.rb
133
145
  - spec/spec_helper.rb
@@ -1,28 +0,0 @@
1
- class Redis
2
- class DistributedMarshaled < Distributed
3
- attr_reader :ring
4
-
5
- def initialize(addresses)
6
- nodes = addresses.map do |address|
7
- MarshaledClient.new address
8
- end
9
- @ring = Redis::HashRing.new nodes
10
- end
11
-
12
- def nodes
13
- ring.nodes
14
- end
15
-
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
27
- end
28
- end
@@ -1,65 +0,0 @@
1
- class Redis
2
- class MarshaledClient < self
3
- def marshalled_set(key, val, options = nil)
4
- val = marshal_value(val, options)
5
- if ttl = expires_in(options)
6
- setex key, ttl, val
7
- else
8
- set key, val
9
- end
10
- end
11
-
12
- def marshalled_setnx(key, val, options = nil)
13
- val = marshal_value(val, options)
14
- if expires_in = expires_in(options)
15
- setnx_with_expire key, val, expires_in
16
- else
17
- setnx key, val
18
- end
19
- end
20
-
21
- def setnx_with_expire(key, value, ttl)
22
- multi do
23
- setnx(key, val)
24
- expire(key, expires_in)
25
- end
26
- end
27
-
28
- def marshalled_get(key, options = nil)
29
- result = @client.call(:get, key)
30
- result = Marshal.load result if unmarshal?(result, options)
31
- result
32
- end
33
-
34
- def marshalled_mget(*keys)
35
- options = keys.flatten.pop if keys.flatten.last.is_a?(Hash)
36
- mget(*keys).map do |result|
37
- unmarshal?(result, options) ? Marshal.load(result) : result
38
- end
39
- end
40
-
41
- def to_s
42
- "Redis Client connected to #{@client.host}:#{@client.port} against DB #{@client.db}"
43
- end
44
-
45
- private
46
- def marshal_value(val, options)
47
- raw?(options) ? val : Marshal.dump(val)
48
- end
49
-
50
- def unmarshal?(result, options)
51
- result && result.size > 0 && !raw?(options)
52
- end
53
-
54
- def raw?(options)
55
- options && options[:raw]
56
- end
57
-
58
- def expires_in(options)
59
- if options
60
- # Rack::Session Merb Rails/Sinatra
61
- options[:expire_after] || options[:expires_in] || options[:expire_in]
62
- end
63
- end
64
- end
65
- end
@@ -1,10 +0,0 @@
1
- module ::RedisStore
2
- module VERSION #:nodoc:
3
- MAJOR = 1
4
- MINOR = 0
5
- TINY = 0
6
- BUILD = "beta2"
7
-
8
- STRING = [MAJOR, MINOR, TINY, BUILD].join('.')
9
- end
10
- end
@@ -1,75 +0,0 @@
1
- require File.join(File.dirname(__FILE__), "/../../spec_helper")
2
- RAILS_SESSION_STORE_CLASS = ::RedisStore.rails3? ? ActionDispatch::Session::RedisSessionStore : ActionController::Session::RedisSessionStore
3
-
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
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
-
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
-
28
- redis = instantiate_store :servers => "localhost"
29
- redis.to_s.should == "Redis Client connected to localhost:6379 against DB 0"
30
-
31
- redis = instantiate_store :servers => "localhost:6380"
32
- redis.to_s.should == "Redis Client connected to localhost:6380 against DB 0"
33
-
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
-
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
-
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
-
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
-
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
-
66
- private
67
- def instantiate_store(params={})
68
- RAILS_SESSION_STORE_CLASS.new(app, params).instance_variable_get(:@pool)
69
- end
70
-
71
- def with_store_management
72
- yield @store
73
- yield @dstore
74
- end
75
- end
@@ -1,33 +0,0 @@
1
- require File.join(File.dirname(__FILE__), "/../spec_helper")
2
-
3
- describe "Redis::DistributedMarshaled" do
4
- before(:each) do
5
- @dmr = Redis::DistributedMarshaled.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.marshalled_set "rabbit", @rabbit
12
- end
13
-
14
- after(:all) do
15
- @dmr.ring.nodes.each { |server| server.flushdb }
16
- end
17
-
18
- it "should accept connection params" do
19
- dmr = Redis::DistributedMarshaled.new [ :host => "localhost", :port => "6380", :db => "1" ]
20
- dmr.ring.nodes.size == 1
21
- mr = dmr.ring.nodes.first
22
- mr.to_s.should == "Redis Client connected to localhost:6380 against DB 1"
23
- end
24
-
25
- it "should set an object" do
26
- @dmr.marshalled_set "rabbit", @white_rabbit
27
- @dmr.marshalled_get("rabbit").should == @white_rabbit
28
- end
29
-
30
- it "should get an object" do
31
- @dmr.marshalled_get("rabbit").should == @rabbit
32
- end
33
- end
@@ -1,83 +0,0 @@
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
- if RUBY_VERSION.match /1\.9/
26
- it "should not unmarshal object on get if raw option is true" do
27
- @store.marshalled_get("rabbit", :raw => true).should == "\x04\bU:\x0FOpenStruct{\x06:\tnameI\"\nbunny\x06:\rencoding\"\rUS-ASCII"
28
- end
29
- else
30
- it "should not unmarshal object on get if raw option is true" do
31
- @store.marshalled_get("rabbit", :raw => true).should == "\004\bU:\017OpenStruct{\006:\tname\"\nbunny"
32
- end
33
- end
34
-
35
- it "should not marshal object on set if raw option is true" do
36
- @store.marshalled_set "rabbit", @white_rabbit, :raw => true
37
- @store.marshalled_get("rabbit", :raw => true).should == %(#<OpenStruct color="white">)
38
- end
39
-
40
- it "should not unmarshal object if getting an empty string" do
41
- @store.marshalled_set "empty_string", ""
42
- lambda { @store.marshalled_get("empty_string").should == "" }.should_not raise_error
43
- end
44
-
45
- it "should not set an object if already exist" do
46
- @store.marshalled_setnx "rabbit", @white_rabbit
47
- @store.marshalled_get("rabbit").should === @rabbit
48
- end
49
-
50
- it "should marshal object on set_unless_exists" do
51
- @store.marshalled_setnx "rabbit2", @white_rabbit
52
- @store.marshalled_get("rabbit2").should === @white_rabbit
53
- end
54
-
55
- it "should not marshal object on set_unless_exists if raw option is true" do
56
- @store.marshalled_setnx "rabbit2", @white_rabbit, :raw => true
57
- @store.marshalled_get("rabbit2", :raw => true).should == %(#<OpenStruct color="white">)
58
- end
59
-
60
- it "should unmarshal object(s) on multi get" do
61
- @store.marshalled_set "rabbit2", @white_rabbit
62
- rabbit, rabbit2 = @store.marshalled_mget "rabbit", "rabbit2"
63
- rabbit.should == @rabbit
64
- rabbit2.should == @white_rabbit
65
- end
66
-
67
- if RUBY_VERSION.match /1\.9/
68
- it "should not unmarshal object(s) on multi get if raw option is true" do
69
- @store.marshalled_set "rabbit2", @white_rabbit
70
- rabbit, rabbit2 = @store.marshalled_mget "rabbit", "rabbit2", :raw => true
71
- rabbit.should == "\x04\bU:\x0FOpenStruct{\x06:\tnameI\"\nbunny\x06:\rencoding\"\rUS-ASCII"
72
- rabbit2.should == "\x04\bU:\x0FOpenStruct{\x06:\ncolorI\"\nwhite\x06:\rencoding\"\rUS-ASCII"
73
- end
74
- else
75
- it "should not unmarshal object(s) on multi get if raw option is true" do
76
- @store.marshalled_set "rabbit2", @white_rabbit
77
- rabbit, rabbit2 = @store.marshalled_mget "rabbit", "rabbit2", :raw => true
78
- rabbit.should == "\004\bU:\017OpenStruct{\006:\tname\"\nbunny"
79
- rabbit2.should == "\004\bU:\017OpenStruct{\006:\ncolor\"\nwhite"
80
- end
81
- end
82
- end
83
-