redis-session-store 0.1

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.
Files changed (5) hide show
  1. data/LICENSE +20 -0
  2. data/README +0 -0
  3. data/Rakefile +24 -0
  4. data/lib/redis_session_store.rb +61 -0
  5. metadata +67 -0
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 ADDED
File without changes
@@ -0,0 +1,24 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+ require 'rubygems/specification'
4
+
5
+ spec = Gem::Specification.new do |s|
6
+ s.name = 'redis-session-store'
7
+ s.version = '0.1'
8
+ s.platform = Gem::Platform::RUBY
9
+ s.has_rdoc = true
10
+ s.extra_rdoc_files = ["LICENSE"]
11
+ s.summary = "A drop-in replacement for e.g. MemCacheStore to store Rails sessions (and Rails sessions only) in Redis."
12
+ s.description = s.summary
13
+ s.authors = "Mathias Meyer"
14
+ s.email = "meyer@paperplanes.de"
15
+ s.homepage = ""
16
+ s.add_dependency "redis"
17
+ s.require_path = 'lib'
18
+ s.autorequire = 'redis_session_store'
19
+ s.files = %w(README Rakefile) + Dir.glob("{lib}/**/*")
20
+ end
21
+
22
+ Rake::GemPackageTask.new(spec) do |pkg|
23
+ pkg.gem_spec = spec
24
+ end
@@ -0,0 +1,61 @@
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 6370
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
+
14
+ class RedisSessionStore < ActionController::Session::AbstractStore
15
+
16
+ def initialize(app, options = {})
17
+ # Support old :expires option
18
+ options[:expire_after] ||= options[:expires]
19
+
20
+ super
21
+
22
+ @default_options = {
23
+ :namespace => 'rack:session',
24
+ :server => 'localhost',
25
+ :port => '6379',
26
+ :db => 0,
27
+ :key_prefix => ""
28
+ }.update(options)
29
+
30
+ @pool = Redis.new(@default_options)
31
+ @mutex = Mutex.new
32
+
33
+ super
34
+ end
35
+
36
+ private
37
+ def prefixed(sid)
38
+ "#{@default_options[:key_prefix]}#{sid}"
39
+ end
40
+
41
+ def get_session(env, sid)
42
+ sid ||= generate_sid
43
+ begin
44
+ data = @pool.call_command([:get, prefixed(sid)])
45
+ session = data.nil? ? {} : Marshal.load(data)
46
+ rescue Errno::ECONNREFUSED
47
+ session = {}
48
+ end
49
+ [sid, session]
50
+ end
51
+
52
+ def set_session(env, sid, session_data)
53
+ options = env['rack.session.options']
54
+ expiry = options[:expire_after] || nil
55
+ @pool.set(prefixed(sid), Marshal.dump(session_data), expiry)
56
+ return true
57
+ rescue Errno::ECONNREFUSED
58
+ return false
59
+ end
60
+
61
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: redis-session-store
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.1"
5
+ platform: ruby
6
+ authors:
7
+ - Mathias Meyer
8
+ autorequire: redis_session_store
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-12-31 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: redis
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: A drop-in replacement for e.g. MemCacheStore to store Rails sessions (and Rails sessions only) in Redis.
26
+ email: meyer@paperplanes.de
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ files:
34
+ - README
35
+ - Rakefile
36
+ - lib/redis_session_store.rb
37
+ - LICENSE
38
+ has_rdoc: true
39
+ homepage: ""
40
+ licenses: []
41
+
42
+ post_install_message:
43
+ rdoc_options: []
44
+
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: "0"
52
+ version:
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ version:
59
+ requirements: []
60
+
61
+ rubyforge_project:
62
+ rubygems_version: 1.3.5
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: A drop-in replacement for e.g. MemCacheStore to store Rails sessions (and Rails sessions only) in Redis.
66
+ test_files: []
67
+