redis-actionpack 0.0.0 → 3.1.3.rc

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,2 +1,5 @@
1
1
  source "http://rubygems.org"
2
2
  gemspec
3
+
4
+ gem 'redis-store', '1.1.0.rc', :path => File.expand_path('../../redis-store', __FILE__)
5
+ gem 'redis-rack-cache', '1.1.rc', :path => File.expand_path('../../redis-rack-cache', __FILE__)
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 - 2011 Luca Guidi
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,63 @@
1
+ # Redis stores for ActionPack
2
+
3
+ __`redis-actionpack`__ provides a full set of stores (*Session*, *HTTP Cache*) for __ActionPack__. It natively supports object marshalling, timeouts, single or multiple nodes and namespaces.
4
+
5
+ ## Redis Installation
6
+
7
+ ### Option 1: Homebrew
8
+
9
+ MacOS X users should use [Homebrew](https://github.com/mxcl/homebrew) to install Redis:
10
+
11
+ brew install redis
12
+
13
+ ### Option 2: From Source
14
+
15
+ Download and install Redis from [http://redis.io](http://redis.io/)
16
+
17
+ wget http://redis.googlecode.com/files/redis-2.4.5.tar.gz
18
+ tar -zxf redis-2.4.5.tar.gz
19
+ mv redis-2.4.5 redis
20
+ cd redis
21
+ make
22
+
23
+ ## Usage
24
+
25
+ # Gemfile
26
+ gem 'redis-actionpack'
27
+
28
+ ### Session Store: Ruby on Rails
29
+
30
+ # config/initializers/session_store.rb
31
+ MyApplication::Application.config.session_store :redis_store
32
+
33
+ ### Session Store: Standalone
34
+
35
+ ActionController::Base.cache_store = ActionDispatch::Session::RedisSessionStore.new
36
+
37
+ ### HTTP Cache
38
+
39
+ # config.ru
40
+ require 'rack'
41
+ require 'rack/cache'
42
+ require 'redis-rack-cache'
43
+
44
+ use Rack::Cache,
45
+ :metastore => 'redis://localhost:6379/0/metastore',
46
+ :entitystore => 'redis://localhost:6380/0/entitystore'
47
+
48
+ #### Configuration
49
+
50
+ For advanced configuration options, please check the [Redis Store Wiki](https://github.com/jodosha/redis-store/wiki).
51
+
52
+ ## Running tests
53
+
54
+ git clone git://github.com/jodosha/redis-store.git
55
+ cd redis-store/redis-actionpack
56
+ gem install bundler --pre # required version: 1.1.rc
57
+ bundle exec rake
58
+
59
+ If you are on **Snow Leopard** you have to run `env ARCHFLAGS="-arch x86_64" bundle exec rake`
60
+
61
+ ## Copyright
62
+
63
+ (c) 2009 - 2011 Luca Guidi - [http://lucaguidi.com](http://lucaguidi.com), released under the MIT license
data/Rakefile CHANGED
@@ -1 +1,14 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler'
2
+ Bundler.setup
3
+ require 'rake'
4
+ require 'bundler/gem_tasks'
5
+
6
+ begin
7
+ require 'rdoc/task'
8
+ rescue LoadError
9
+ require 'rake/rdoctask'
10
+ end
11
+
12
+ load 'tasks/redis.tasks.rb'
13
+ task :default => 'redis:test:suite'
14
+
@@ -0,0 +1,64 @@
1
+ require 'redis-store'
2
+ require 'action_dispatch/middleware/session/abstract_store'
3
+
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 ActionDispatch
16
+ module Session
17
+ class RedisSessionStore < AbstractStore
18
+ def initialize(app, options = {})
19
+ # Support old :expires option
20
+ options[:expire_after] ||= options[:expires]
21
+
22
+ super
23
+
24
+ options = options.dup
25
+ servers = [ options.delete(:servers) ].flatten.compact
26
+ servers = [ "redis://localhost:6379/0" ] if servers.empty?
27
+ servers.map! do |server|
28
+ server = Redis::Factory.resolve(server)
29
+ server.merge(options)
30
+ end
31
+
32
+ @pool = Redis::Factory.create(*servers)
33
+ end
34
+
35
+ private
36
+ def get_session(env, sid)
37
+ sid ||= generate_sid
38
+ begin
39
+ session = @pool.get(sid) || {}
40
+ rescue Errno::ECONNREFUSED
41
+ session = {}
42
+ end
43
+ [sid, session]
44
+ end
45
+
46
+ def set_session(env, sid, session_data, opts=nil)
47
+ options = env['rack.session.options']
48
+ @pool.set(sid, session_data, options)
49
+ sid
50
+ rescue Errno::ECONNREFUSED
51
+ return false
52
+ end
53
+
54
+ def destroy(env)
55
+ if sid = current_session_id(env)
56
+ @pool.del(sid)
57
+ sid
58
+ end
59
+ rescue Errno::ECONNREFUSED
60
+ false
61
+ end
62
+ end
63
+ end
64
+ end
@@ -1,7 +1,5 @@
1
- require "redis-actionpack/version"
2
-
3
- module Redis
4
- module Actionpack
5
- # Your code goes here...
6
- end
7
- end
1
+ require 'redis-store'
2
+ require 'redis-rack-cache'
3
+ require 'action_pack'
4
+ require 'redis/actionpack/version'
5
+ require 'action_dispatch/middleware/session/redis_store'
@@ -0,0 +1,5 @@
1
+ class Redis
2
+ module ActionPack
3
+ VERSION = '3.1.3.rc'
4
+ end
5
+ end
@@ -1,15 +1,15 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  $:.push File.expand_path("../lib", __FILE__)
3
- require "redis-actionpack/version"
3
+ require "redis/actionpack/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "redis-actionpack"
7
- s.version = Redis::Actionpack::VERSION
7
+ s.version = Redis::ActionPack::VERSION
8
8
  s.authors = ["Luca Guidi"]
9
9
  s.email = ["guidi.luca@gmail.com"]
10
10
  s.homepage = "http://jodosha.github.com/redis-store"
11
- s.summary = %q{Redis for ActionPack}
12
- s.description = %q{Redis for ActionPack}
11
+ s.summary = %q{Redis session store for ActionPack}
12
+ s.description = %q{Redis session store for ActionPack}
13
13
 
14
14
  s.rubyforge_project = "redis-actionpack"
15
15
 
@@ -18,7 +18,14 @@ Gem::Specification.new do |s|
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.require_paths = ["lib"]
20
20
 
21
- # specify any dependencies here; for example:
22
- # s.add_development_dependency "rspec"
23
- # s.add_runtime_dependency "rest-client"
21
+ s.add_runtime_dependency 'redis-store', '1.1.0.rc'
22
+ s.add_runtime_dependency 'actionpack', '3.1.3'
23
+ s.add_runtime_dependency 'redis-rack-cache', '1.1.rc'
24
+
25
+ s.add_development_dependency 'rake', '~> 0.9.2.2'
26
+ s.add_development_dependency 'bundler', '~> 1.1.rc'
27
+ s.add_development_dependency 'mocha', '~> 0.10.0'
28
+ s.add_development_dependency 'minitest', '~> 2.8.0'
29
+ s.add_development_dependency 'purdytest', '~> 1.0.0'
24
30
  end
31
+
@@ -0,0 +1,77 @@
1
+ require 'test_helper'
2
+
3
+ describe ActionDispatch::Session::RedisSessionStore do
4
+ attr_reader :app
5
+
6
+ before do
7
+ @app = Object.new
8
+ @store = ActionDispatch::Session::RedisSessionStore.new(app)
9
+ @dstore = ActionDispatch::Session::RedisSessionStore.new app, :servers => ["redis://127.0.0.1:6380/1", "redis://127.0.0.1:6381/1"]
10
+ @rabbit = OpenStruct.new :name => "bunny"
11
+ @white_rabbit = OpenStruct.new :color => "white"
12
+ @sid = "rabbit"
13
+ @env = {'rack.session.options' => {:id => @sid}}
14
+ with_store_management do |store|
15
+ class << store
16
+ attr_reader :pool
17
+ public :get_session, :set_session, :destroy
18
+ end
19
+ store.set_session(@env, @sid, @rabbit)
20
+ store.pool.del "counter"
21
+ store.pool.del "rub-a-dub"
22
+ end
23
+ end
24
+
25
+ it "reads the data" do
26
+ with_store_management do |store|
27
+ store.get_session(@env, @sid).must_equal([@sid, @rabbit])
28
+ end
29
+ end
30
+
31
+ it "should write the data" do
32
+ with_store_management do |store|
33
+ store.set_session(@env, @sid, @white_rabbit)
34
+ store.get_session(@env, @sid).must_equal([@sid, @white_rabbit])
35
+ end
36
+ end
37
+
38
+ it "should delete the data" do
39
+ with_store_management do |store|
40
+ store.destroy(@env)
41
+ store.get_session(@env, @sid).must_equal([@sid, {}])
42
+ end
43
+ end
44
+
45
+ it "should write the data with expiration time" do
46
+ with_store_management do |store|
47
+ @env['rack.session.options'].merge!(:expires_in => 1.second)
48
+ store.set_session(@env, @sid, @white_rabbit); sleep 2
49
+ store.get_session(@env, @sid).must_equal([@sid, {}])
50
+ end
51
+ end
52
+
53
+ describe "namespace" do
54
+ before do
55
+ @namespace = "theplaylist"
56
+ @store = ActionDispatch::Session::RedisSessionStore.new(lambda {|| }, :servers => [{ :namespace => @namespace }])
57
+ @pool = @store.instance_variable_get(:@pool)
58
+ @client = @pool.instance_variable_get(:@client)
59
+ end
60
+
61
+ it "should read the data" do
62
+ @client.expects(:call).with([:get, "#{@namespace}:#{@sid}"])
63
+ @store.send :get_session, @env, @sid
64
+ end
65
+
66
+ it "should write the data" do
67
+ @client.expects(:call).with([:set, "#{@namespace}:#{@sid}", Marshal.dump(@white_rabbit)])
68
+ @store.send :set_session, @env, @sid, @white_rabbit
69
+ end
70
+ end
71
+
72
+ private
73
+ def with_store_management
74
+ yield @store
75
+ yield @dstore
76
+ end
77
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ describe Redis::ActionPack::VERSION do
4
+ it "must be equal to 3.1.3.rc" do
5
+ Redis::ActionPack::VERSION.must_equal '3.1.3.rc'
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ Bundler.setup
2
+ gem 'minitest'
3
+ require 'minitest/spec'
4
+ require 'minitest/autorun'
5
+ require 'mocha'
6
+ require 'active_support/core_ext/numeric/time'
7
+ require 'action_dispatch'
8
+ require 'action_dispatch/middleware/session/redis_store'
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-actionpack
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
5
- prerelease:
4
+ hash: 7712046
5
+ prerelease: 6
6
6
  segments:
7
- - 0
8
- - 0
9
- - 0
10
- version: 0.0.0
7
+ - 3
8
+ - 1
9
+ - 3
10
+ - rc
11
+ version: 3.1.3.rc
11
12
  platform: ruby
12
13
  authors:
13
14
  - Luca Guidi
@@ -15,10 +16,139 @@ autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
18
 
18
- date: 2011-09-08 00:00:00 Z
19
- dependencies: []
20
-
21
- description: Redis for ActionPack
19
+ date: 2011-12-30 00:00:00 Z
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: redis-store
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - "="
28
+ - !ruby/object:Gem::Version
29
+ hash: 7712002
30
+ segments:
31
+ - 1
32
+ - 1
33
+ - 0
34
+ - rc
35
+ version: 1.1.0.rc
36
+ type: :runtime
37
+ version_requirements: *id001
38
+ - !ruby/object:Gem::Dependency
39
+ name: actionpack
40
+ prerelease: false
41
+ requirement: &id002 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - "="
45
+ - !ruby/object:Gem::Version
46
+ hash: 5
47
+ segments:
48
+ - 3
49
+ - 1
50
+ - 3
51
+ version: 3.1.3
52
+ type: :runtime
53
+ version_requirements: *id002
54
+ - !ruby/object:Gem::Dependency
55
+ name: redis-rack-cache
56
+ prerelease: false
57
+ requirement: &id003 !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - "="
61
+ - !ruby/object:Gem::Version
62
+ hash: 7712070
63
+ segments:
64
+ - 1
65
+ - 1
66
+ - rc
67
+ version: 1.1.rc
68
+ type: :runtime
69
+ version_requirements: *id003
70
+ - !ruby/object:Gem::Dependency
71
+ name: rake
72
+ prerelease: false
73
+ requirement: &id004 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ~>
77
+ - !ruby/object:Gem::Version
78
+ hash: 11
79
+ segments:
80
+ - 0
81
+ - 9
82
+ - 2
83
+ - 2
84
+ version: 0.9.2.2
85
+ type: :development
86
+ version_requirements: *id004
87
+ - !ruby/object:Gem::Dependency
88
+ name: bundler
89
+ prerelease: false
90
+ requirement: &id005 !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ~>
94
+ - !ruby/object:Gem::Version
95
+ hash: 7712070
96
+ segments:
97
+ - 1
98
+ - 1
99
+ - rc
100
+ version: 1.1.rc
101
+ type: :development
102
+ version_requirements: *id005
103
+ - !ruby/object:Gem::Dependency
104
+ name: mocha
105
+ prerelease: false
106
+ requirement: &id006 !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ~>
110
+ - !ruby/object:Gem::Version
111
+ hash: 55
112
+ segments:
113
+ - 0
114
+ - 10
115
+ - 0
116
+ version: 0.10.0
117
+ type: :development
118
+ version_requirements: *id006
119
+ - !ruby/object:Gem::Dependency
120
+ name: minitest
121
+ prerelease: false
122
+ requirement: &id007 !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ~>
126
+ - !ruby/object:Gem::Version
127
+ hash: 47
128
+ segments:
129
+ - 2
130
+ - 8
131
+ - 0
132
+ version: 2.8.0
133
+ type: :development
134
+ version_requirements: *id007
135
+ - !ruby/object:Gem::Dependency
136
+ name: purdytest
137
+ prerelease: false
138
+ requirement: &id008 !ruby/object:Gem::Requirement
139
+ none: false
140
+ requirements:
141
+ - - ~>
142
+ - !ruby/object:Gem::Version
143
+ hash: 23
144
+ segments:
145
+ - 1
146
+ - 0
147
+ - 0
148
+ version: 1.0.0
149
+ type: :development
150
+ version_requirements: *id008
151
+ description: Redis session store for ActionPack
22
152
  email:
23
153
  - guidi.luca@gmail.com
24
154
  executables: []
@@ -30,10 +160,16 @@ extra_rdoc_files: []
30
160
  files:
31
161
  - .gitignore
32
162
  - Gemfile
163
+ - MIT-LICENSE
164
+ - README.md
33
165
  - Rakefile
166
+ - lib/action_dispatch/middleware/session/redis_store.rb
34
167
  - lib/redis-actionpack.rb
35
- - lib/redis-actionpack/version.rb
168
+ - lib/redis/actionpack/version.rb
36
169
  - redis-actionpack.gemspec
170
+ - test/action_dispatch/middleware/session/redis_store_test.rb
171
+ - test/redis/actionpack/version_test.rb
172
+ - test/test_helper.rb
37
173
  homepage: http://jodosha.github.com/redis-store
38
174
  licenses: []
39
175
 
@@ -54,18 +190,23 @@ required_ruby_version: !ruby/object:Gem::Requirement
54
190
  required_rubygems_version: !ruby/object:Gem::Requirement
55
191
  none: false
56
192
  requirements:
57
- - - ">="
193
+ - - ">"
58
194
  - !ruby/object:Gem::Version
59
- hash: 3
195
+ hash: 25
60
196
  segments:
61
- - 0
62
- version: "0"
197
+ - 1
198
+ - 3
199
+ - 1
200
+ version: 1.3.1
63
201
  requirements: []
64
202
 
65
203
  rubyforge_project: redis-actionpack
66
204
  rubygems_version: 1.8.6
67
205
  signing_key:
68
206
  specification_version: 3
69
- summary: Redis for ActionPack
70
- test_files: []
71
-
207
+ summary: Redis session store for ActionPack
208
+ test_files:
209
+ - test/action_dispatch/middleware/session/redis_store_test.rb
210
+ - test/redis/actionpack/version_test.rb
211
+ - test/test_helper.rb
212
+ has_rdoc:
@@ -1,5 +0,0 @@
1
- module Redis
2
- module Actionpack
3
- VERSION = "0.0.0"
4
- end
5
- end