honkster-redis-store 0.3.12 → 0.3.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/VERSION +1 -1
  2. data/lib/rack/session/redis.rb +33 -18
  3. metadata +4 -4
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.12
1
+ 0.3.13
@@ -1,5 +1,15 @@
1
1
  module Rack
2
2
  module Session
3
+ # Redis session storage for Rack applications.
4
+ #
5
+ # Options:
6
+ # :key => Same as with the other cookie stores, key name
7
+ # :secret => Encryption secret for the key
8
+ # :host => Redis host name, default is localhost
9
+ # :port => Redis port, default is 6379
10
+ # :db => Database number, defaults to 0. Useful to separate your session storage from other data
11
+ # :key_prefix => Prefix for keys used in Redis, e.g. myapp-. Useful to separate session storage keys visibly from others
12
+ # :expire_after => A number in seconds to set the timeout interval for the session. Will map directly to expiry in Redis
3
13
  class Redis < Abstract::ID
4
14
  attr_reader :mutex, :pool
5
15
  DEFAULT_OPTIONS = Abstract::ID::DEFAULT_OPTIONS.merge :redis_server => "localhost:6379"
@@ -7,6 +17,7 @@ module Rack
7
17
  def initialize(app, options = {})
8
18
  super
9
19
  @mutex = Mutex.new
20
+ @key_prefix = options[:key_prefix] || ""
10
21
  servers = [options[:servers]].flatten.compact.map do |server_options|
11
22
  {
12
23
  :namespace => 'rack:session',
@@ -26,14 +37,14 @@ module Rack
26
37
  end
27
38
 
28
39
  def get_session(env, sid)
29
- session = @pool.marshalled_get(sid) if sid
40
+ session = @pool.marshalled_get(prefixed(sid)) if sid
30
41
  @mutex.lock if env['rack.multithread']
31
42
  unless sid and session
32
- env['rack.errors'].puts("Session '#{sid.inspect}' not found, initializing...") if $VERBOSE and not sid.nil?
43
+ env['rack.errors'].puts("Session '#{prefixed(sid).inspect}' not found, initializing...") if $VERBOSE and not sid.nil?
33
44
  session = {}
34
45
  sid = generate_sid
35
- ret = @pool.marshalled_set sid, session
36
- raise "Session collision on '#{sid.inspect}'" unless ret
46
+ ret = @pool.marshalled_set prefixed(sid), session
47
+ raise "Session collision on '#{prefixed(sid).inspect}'" unless ret
37
48
  end
38
49
  session.instance_variable_set('@old', {}.merge(session))
39
50
  return [sid, session]
@@ -67,23 +78,27 @@ module Rack
67
78
  end
68
79
 
69
80
  private
70
- def merge_sessions(sid, old, new, cur=nil)
71
- cur ||= {}
72
- unless Hash === old and Hash === new
73
- warn 'Bad old or new sessions provided.'
74
- return cur
75
- end
81
+ def prefixed(sid)
82
+ "#{@key_prefix}#{sid}"
83
+ end
76
84
 
77
- delete = old.keys - new.keys
78
- warn "//@#{sid}: dropping #{delete*','}" if $DEBUG and not delete.empty?
79
- delete.each{|k| cur.del k }
85
+ def merge_sessions(sid, old, new, cur=nil)
86
+ cur ||= {}
87
+ unless Hash === old and Hash === new
88
+ warn 'Bad old or new sessions provided.'
89
+ return cur
90
+ end
80
91
 
81
- update = new.keys.select{|k| new[k] != old[k] }
82
- warn "//@#{sid}: updating #{update*','}" if $DEBUG and not update.empty?
83
- update.each{|k| cur[k] = new[k] }
92
+ delete = old.keys - new.keys
93
+ warn "//@#{sid}: dropping #{delete*','}" if $DEBUG and not delete.empty?
94
+ delete.each{|k| cur.del k }
84
95
 
85
- cur
86
- end
96
+ update = new.keys.select{|k| new[k] != old[k] }
97
+ warn "//@#{sid}: updating #{update*','}" if $DEBUG and not update.empty?
98
+ update.each{|k| cur[k] = new[k] }
99
+
100
+ cur
101
+ end
87
102
  end
88
103
  end
89
104
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: honkster-redis-store
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 9
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 12
10
- version: 0.3.12
9
+ - 13
10
+ version: 0.3.13
11
11
  platform: ruby
12
12
  authors:
13
13
  - Luca Guidi
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-03 00:00:00 -07:00
18
+ date: 2010-07-04 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies: []
21
21