redis2-session-store 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Mathias Meyer
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.
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ A simple Redis-based session store for Redis. But why, you ask,
2
+ when there's [redis-store](http://github.com/jodosha/redis-store/)?
3
+ redis-store is a one-fits-all solution, and I found it not to work
4
+ properly with Rails, mostly due to a problem that seemed to lie in
5
+ Rack's Abstract::ID class. I wanted something that worked, so I
6
+ blatantly stole the code from Rails' MemCacheStore and turned it
7
+ into a Redis version. No support for fancy stuff like distributed
8
+ storage across several Redis instances. Feel free to add what you
9
+ seem fit.
10
+
11
+ This library doesn't offer anything related to caching, and is
12
+ only suitable for Rails applications. For other frameworks or
13
+ drop-in support for caching, check out
14
+ [redis-store](http://github.com/jodosha/redis-store/)
15
+
16
+ Installation
17
+ ============
18
+
19
+ gem install redis-session-store
20
+
21
+ Configuration
22
+ =============
23
+
24
+ See lib/redis-session-store.rb for a list of valid options.
25
+ Set them using:
26
+
27
+ ActionController::Base.session = {
28
+ :db => 2,
29
+ :expire_after => 120.minutes,
30
+ :key_prefix => "myapp:session:"
31
+ }
32
+
33
+
34
+ In your Rails app, throw in an initializer with the following contents
35
+ and the configuration above:
36
+
37
+ ActionController::Base.session_store = RedisSessionStore
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+
3
+ begin
4
+ require 'jeweler'
5
+ Jeweler::Tasks.new do |gemspec|
6
+ gemspec.name = "redis2-session-store"
7
+ gemspec.summary = "Updated redis-session-store for Rails and redis client 2.0.x"
8
+ gemspec.description = "Updated redis-session-store for Rails and redis client 2.0.x"
9
+ gemspec.email = "recluce@gmail.com"
10
+ gemspec.homepage = "http://github.com/chrisrobinson/redis-session-store"
11
+ gemspec.authors = ["Josh Nichols", "Chris Robinson"]
12
+ end
13
+ rescue LoadError
14
+ puts "Jeweler not available. Install it with: gem install jeweler"
15
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,64 @@
1
+ require 'redis'
2
+
3
+ # Redis session storage for Rails, and for Rails only. Derived from
4
+ # the MemCacheStore code, simply dropping in Redis instead.
5
+ #
6
+ # Options:
7
+ # :key => Same as with the other cookie stores, key name
8
+ # :secret => Encryption secret for the key
9
+ # :host => Redis host name, default is localhost
10
+ # :port => Redis port, default is 6379
11
+ # :db => Database number, defaults to 0. Useful to separate your session storage from other data
12
+ # :key_prefix => Prefix for keys used in Redis, e.g. myapp-. Useful to separate session storage keys visibly from others
13
+ # :expire_after => A number in seconds to set the timeout interval for the session. Will map directly to expiry in Redis
14
+
15
+ class RedisSessionStore < ActionController::Session::AbstractStore
16
+
17
+ def initialize(app, options = {})
18
+ # Support old :expires option
19
+ options[:expire_after] ||= options[:expires]
20
+
21
+ super
22
+
23
+ @default_options = {
24
+ :namespace => 'rack:session',
25
+ :host => 'localhost',
26
+ :port => '6379',
27
+ :db => 0,
28
+ :key_prefix => ""
29
+ }.update(options)
30
+
31
+ @pool = Redis.new(@default_options)
32
+ end
33
+
34
+ private
35
+ def prefixed(sid)
36
+ "#{@default_options[:key_prefix]}#{sid}"
37
+ end
38
+
39
+ def get_session(env, sid)
40
+ sid ||= generate_sid
41
+ begin
42
+ data = @pool.get prefixed(sid)
43
+ session = data.nil? ? {} : Marshal.load(data)
44
+ rescue Errno::ECONNREFUSED
45
+ session = {}
46
+ end
47
+ [sid, session]
48
+ end
49
+
50
+ def set_session(env, sid, session_data)
51
+ options = env['rack.session.options']
52
+ expiry = options[:expire_after] || nil
53
+
54
+ @pool.pipelined do |redis|
55
+ redis.set(prefixed(sid), Marshal.dump(session_data))
56
+ redis.expire(prefixed(sid), expiry) if expiry
57
+ end
58
+
59
+ return true
60
+ rescue Errno::ECONNREFUSED
61
+ return false
62
+ end
63
+
64
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: redis2-session-store
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Josh Nichols
14
+ - Chris Robinson
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2010-06-15 00:00:00 -06:00
20
+ default_executable:
21
+ dependencies: []
22
+
23
+ description: Updated redis-session-store for Rails and redis client 2.0.x
24
+ email: recluce@gmail.com
25
+ executables: []
26
+
27
+ extensions: []
28
+
29
+ extra_rdoc_files:
30
+ - LICENSE
31
+ - README.md
32
+ files:
33
+ - .gitignore
34
+ - LICENSE
35
+ - README.md
36
+ - Rakefile
37
+ - VERSION
38
+ - lib/redis-session-store.rb
39
+ has_rdoc: true
40
+ homepage: http://github.com/chrisrobinson/redis-session-store
41
+ licenses: []
42
+
43
+ post_install_message:
44
+ rdoc_options:
45
+ - --charset=UTF-8
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ hash: 3
54
+ segments:
55
+ - 0
56
+ version: "0"
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ hash: 3
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ requirements: []
67
+
68
+ rubyforge_project:
69
+ rubygems_version: 1.3.7
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Updated redis-session-store for Rails and redis client 2.0.x
73
+ test_files: []
74
+