redis_session_storage 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 97091d6bda326c571aa72a2d94c84db84f489203
4
- data.tar.gz: fbaf6cdc8e2dfbfe0012fa733cbc15165debf3a3
3
+ metadata.gz: 18106df05417980ef80b2d22d712e1f1a2d21a2b
4
+ data.tar.gz: 065ebaab27395b25cf6b3fb4a6ab113c1b349187
5
5
  SHA512:
6
- metadata.gz: 9d53568b3f32abbafb21a0464cde5bfba9fe44dbfae3cb9b1933cedf350a62a7612f26edadd4e3c2779550223f033c3693b222da79cba7999e04bace77b4c179
7
- data.tar.gz: bbbda6e39580e839a3e24049a417838defd223248f63228b685efd8d5178d21245e585bd8b9fde284c2459f209042b6df7bbdbfd0caa22634693f0ed829f50f0
6
+ metadata.gz: f48bf7391485ef106c5c4489e8980846e134dc01280a5b710cc564959a10dc43fbfe9d2f5dba65a031098b3a0864dc7d4e0ca60b664b7be7247ab732b97e3790
7
+ data.tar.gz: 3c3b11f51edc1e8b3cf39e481adccfbda362eb7a9e3fa614cdd845ac84e491740e94822b6c7307f5ee2953380dacb56362dab0d533ba1b412c254d8d04d7752e
@@ -0,0 +1,3 @@
1
+ module RedisSessionStorage
2
+ VERSION = "0.0.6"
3
+ end
@@ -1,84 +1,84 @@
1
- require 'redis'
2
- module ActionDispatch
3
- module Session
4
- class RedisSessionStore < AbstractStore
5
-
6
- def initialize(app, options = {})
7
- host = options[:host] || '127.0.0.1'
8
- port = options[:port] || 6379
9
- db = options[:db] || 0
10
- @prefix = options[:key] || ""
11
- @serializer = determine_serializer(options[:serializer])
12
- @redis = Redis.new(:host => host, :port => port, :db => db)
13
- return super
14
- end
15
-
16
- def get_session(env, session_id)
17
- session_id ||= generate_sid()
18
- session_data = get_redis_session(prefixed_key(session_id)) || {}
19
- return [session_id, session_data]
20
- end
21
-
22
- def set_session(env, session_id, session_data, options)
23
- begin
24
- key = prefixed_key(session_id)
25
- if session_data
26
- if(options[:expire_after])
27
- @redis.setex(key, options[:expire_after], @serializer.dump(session_data))
28
- else
29
- @redis.set(key, @serializer.dump(session_data))
30
- end
31
- else
32
- @redis.del(key)
33
- end
34
- return session_id
35
- rescue => e
36
- Rails.logger.error("SessionDispatch::RedisSession - Unable to set redis session.")
37
- return false
38
- end
39
- end
40
-
41
- def destroy_session(env, session_id, options)
42
- @redis.del(prefixed_key(session_id))
43
- return generate_sid()
44
- end
45
-
46
- def determine_serializer(serializer)
47
- if serializer == :json
48
- serial = JsonSerializer
49
- else
50
- serial = Marshal
51
- end
52
- return serial
53
- end
54
-
55
- private
56
-
57
- def prefixed_key(sid)
58
- return "#{@prefix}#{sid}"
59
- end
60
-
61
- def get_redis_session(key)
62
- begin
63
- data = @redis.get(key)
64
- data ? @serializer.load(data) : nil
65
- rescue => e
66
- Rails.logger.error("SessionDispatch::RedisSession - Unable to retrieve redis session.")
67
- return nil
68
- end
69
- end
70
-
71
- class JsonSerializer
72
- def self.load(value)
73
- return JSON.parse(value, quirks_mode: true)
74
- end
75
-
76
- def self.dump(value)
77
- return JSON.generate(value, quirks_mode: true)
78
- end
79
- end
80
-
81
-
82
- end
83
- end
84
- end
1
+ require 'redis'
2
+ module ActionDispatch
3
+ module Session
4
+ class RedisSessionStorage < AbstractStore
5
+
6
+ def initialize(app, options = {})
7
+ host = options[:host] || '127.0.0.1'
8
+ port = options[:port] || 6379
9
+ db = options[:db] || 0
10
+ @prefix = options[:key] || ""
11
+ @serializer = determine_serializer(options[:serializer])
12
+ @redis = Redis.new(:host => host, :port => port, :db => db)
13
+ return super
14
+ end
15
+
16
+ def get_session(env, session_id)
17
+ session_id ||= generate_sid()
18
+ session_data = get_redis_session(prefixed_key(session_id)) || {}
19
+ return [session_id, session_data]
20
+ end
21
+
22
+ def set_session(env, session_id, session_data, options)
23
+ begin
24
+ key = prefixed_key(session_id)
25
+ if session_data
26
+ if(options[:expire_after])
27
+ @redis.setex(key, options[:expire_after], @serializer.dump(session_data))
28
+ else
29
+ @redis.set(key, @serializer.dump(session_data))
30
+ end
31
+ else
32
+ @redis.del(key)
33
+ end
34
+ return session_id
35
+ rescue => e
36
+ Rails.logger.error("SessionDispatch::RedisSession - Unable to set redis session.")
37
+ return false
38
+ end
39
+ end
40
+
41
+ def destroy_session(env, session_id, options)
42
+ @redis.del(prefixed_key(session_id))
43
+ return generate_sid()
44
+ end
45
+
46
+ def determine_serializer(serializer)
47
+ if serializer == :json
48
+ serial = JsonSerializer
49
+ else
50
+ serial = Marshal
51
+ end
52
+ return serial
53
+ end
54
+
55
+ private
56
+
57
+ def prefixed_key(sid)
58
+ return "#{@prefix}#{sid}"
59
+ end
60
+
61
+ def get_redis_session(key)
62
+ begin
63
+ data = @redis.get(key)
64
+ data ? @serializer.load(data) : nil
65
+ rescue => e
66
+ Rails.logger.error("SessionDispatch::RedisSession - Unable to retrieve redis session.")
67
+ return nil
68
+ end
69
+ end
70
+
71
+ class JsonSerializer
72
+ def self.load(value)
73
+ return JSON.parse(value, quirks_mode: true)
74
+ end
75
+
76
+ def self.dump(value)
77
+ return JSON.generate(value, quirks_mode: true)
78
+ end
79
+ end
80
+
81
+
82
+ end
83
+ end
84
+ end
@@ -1,23 +1,22 @@
1
- require File.expand_path('../boot', __FILE__)
2
-
3
- require 'rails/all'
4
-
5
- Bundler.require(*Rails.groups)
6
- require "redis_session_store"
7
-
8
- module Dummy
9
- class Application < Rails::Application
10
- # Settings in config/environments/* take precedence over those specified here.
11
- # Application configuration should go into files in config/initializers
12
- # -- all .rb files in that directory are automatically loaded.
13
-
14
- # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
15
- # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
16
- # config.time_zone = 'Central Time (US & Canada)'
17
-
18
- # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
19
- # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
20
- # config.i18n.default_locale = :de
21
- end
22
- end
23
-
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require 'rails/all'
4
+
5
+ Bundler.require(*Rails.groups)
6
+
7
+ module Dummy
8
+ class Application < Rails::Application
9
+ # Settings in config/environments/* take precedence over those specified here.
10
+ # Application configuration should go into files in config/initializers
11
+ # -- all .rb files in that directory are automatically loaded.
12
+
13
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
14
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
15
+ # config.time_zone = 'Central Time (US & Canada)'
16
+
17
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
18
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
19
+ # config.i18n.default_locale = :de
20
+ end
21
+ end
22
+
@@ -1,3 +1,3 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- Rails.application.config.session_store :redis_session_store, {:key => 'dummy_session_', :expire_after => 5.minutes}
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ Rails.application.config.session_store :redis_session_storage, {:key => 'dummy_session_', :expire_after => 5.minutes}
@@ -28,3 +28,57 @@ Started GET "/assets/users.js?body=1" for 192.168.0.27 at 2014-09-26 18:20:33 -0
28
28
 
29
29
 
30
30
  Started GET "/assets/application.js?body=1" for 192.168.0.27 at 2014-09-26 18:20:33 -0400
31
+
32
+
33
+ Started GET "/users" for 192.168.0.27 at 2014-09-26 19:36:28 -0400
34
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
35
+ Processing by UsersController#index as HTML
36
+ User Load (0.1ms) SELECT "users".* FROM "users"
37
+ Rendered users/index.html.erb within layouts/application (1.7ms)
38
+ Completed 200 OK in 21ms (Views: 19.4ms | ActiveRecord: 0.1ms)
39
+
40
+
41
+ Started GET "/assets/scaffold.css?body=1" for 192.168.0.27 at 2014-09-26 19:36:29 -0400
42
+
43
+
44
+ Started GET "/assets/users.css?body=1" for 192.168.0.27 at 2014-09-26 19:36:29 -0400
45
+
46
+
47
+ Started GET "/assets/users.js?body=1" for 192.168.0.27 at 2014-09-26 19:36:29 -0400
48
+
49
+
50
+ Started GET "/assets/application.css?body=1" for 192.168.0.27 at 2014-09-26 19:36:29 -0400
51
+
52
+
53
+ Started GET "/assets/application.js?body=1" for 192.168.0.27 at 2014-09-26 19:36:29 -0400
54
+
55
+
56
+ Started GET "/assets/scaffold.css?body=1" for 192.168.0.27 at 2014-09-26 19:36:30 -0400
57
+
58
+
59
+ Started GET "/assets/users.css?body=1" for 192.168.0.27 at 2014-09-26 19:36:30 -0400
60
+
61
+
62
+ Started GET "/assets/application.css?body=1" for 192.168.0.27 at 2014-09-26 19:36:30 -0400
63
+
64
+
65
+ Started GET "/users" for 192.168.0.27 at 2014-09-26 19:36:35 -0400
66
+ Processing by UsersController#index as HTML
67
+ User Load (0.1ms) SELECT "users".* FROM "users"
68
+ Rendered users/index.html.erb within layouts/application (0.6ms)
69
+ Completed 200 OK in 4ms (Views: 3.6ms | ActiveRecord: 0.1ms)
70
+
71
+
72
+ Started GET "/assets/scaffold.css?body=1" for 192.168.0.27 at 2014-09-26 19:36:36 -0400
73
+
74
+
75
+ Started GET "/assets/users.js?body=1" for 192.168.0.27 at 2014-09-26 19:36:36 -0400
76
+
77
+
78
+ Started GET "/assets/users.css?body=1" for 192.168.0.27 at 2014-09-26 19:36:36 -0400
79
+
80
+
81
+ Started GET "/assets/application.css?body=1" for 192.168.0.27 at 2014-09-26 19:36:36 -0400
82
+
83
+
84
+ Started GET "/assets/application.js?body=1" for 192.168.0.27 at 2014-09-26 19:36:36 -0400
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis_session_storage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Weston
@@ -62,8 +62,8 @@ files:
62
62
  - MIT-LICENSE
63
63
  - README.rdoc
64
64
  - Rakefile
65
- - lib/redis_session_store.rb
66
- - lib/redis_session_store/version.rb
65
+ - lib/redis_session_storage.rb
66
+ - lib/redis_session_storage/version.rb
67
67
  - lib/tasks/redis_session_store_tasks.rake
68
68
  - test/dummy/README.rdoc
69
69
  - test/dummy/Rakefile
@@ -1,3 +0,0 @@
1
- module RedisSessionStore
2
- VERSION = "0.0.5"
3
- end