rack-redic 0.2.2 → 0.3.0
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.
- checksums.yaml +4 -4
 - data/lib/rack/session/redic.rb +20 -13
 - data/rack-redic.gemspec +1 -1
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 060c56a771cd80ea2e61cb4abbf91406e8766daa
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 4f77b38762b713d241ea93a5daf9a70241f4e1f0
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 21d1c9430203b82f90daabe32fcbd30050468b2f59c693ec454cbbcf2ff62398a580c86486cb60b7631467e0e7b74dca44e67bc317e20b3458e51b39b6cfface
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: c63d41ef4a89ae67783e12d70a0cd27c82a1a3803af6b3b7127575a398f25a8fe413baac3b365e93c36d64011c12457831f87a53d7df2f18f88e89cc176637b5
         
     | 
    
        data/lib/rack/session/redic.rb
    CHANGED
    
    | 
         @@ -28,6 +28,8 @@ module Rack 
     | 
|
| 
       28 
28 
     | 
    
         
             
                # Any other options will get passed to Rack::Session::Abstract::Persisted.
         
     | 
| 
       29 
29 
     | 
    
         
             
                #
         
     | 
| 
       30 
30 
     | 
    
         
             
                class Redic < Abstract::Persisted
         
     | 
| 
      
 31 
     | 
    
         
            +
                  REDIS_URL = 'REDIS_URL'.freeze
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
       31 
33 
     | 
    
         
             
                  def initialize(app, options = {})
         
     | 
| 
       32 
34 
     | 
    
         
             
                    super
         
     | 
| 
       33 
35 
     | 
    
         | 
| 
         @@ -35,7 +37,7 @@ module Rack 
     | 
|
| 
       35 
37 
     | 
    
         
             
                    @storage = Storage.new(
         
     | 
| 
       36 
38 
     | 
    
         
             
                      options[:expire_after],
         
     | 
| 
       37 
39 
     | 
    
         
             
                      options.delete(:marshaller) { Marshal },
         
     | 
| 
       38 
     | 
    
         
            -
                      options.delete(:url) { ENV.fetch( 
     | 
| 
      
 40 
     | 
    
         
            +
                      options.delete(:url) { ENV.fetch(REDIS_URL) }
         
     | 
| 
       39 
41 
     | 
    
         
             
                    )
         
     | 
| 
       40 
42 
     | 
    
         
             
                  end
         
     | 
| 
       41 
43 
     | 
    
         | 
| 
         @@ -48,7 +50,7 @@ module Rack 
     | 
|
| 
       48 
50 
     | 
    
         
             
                  end
         
     | 
| 
       49 
51 
     | 
    
         | 
| 
       50 
52 
     | 
    
         
             
                  # Find the session (or generate a blank one).
         
     | 
| 
       51 
     | 
    
         
            -
                  def find_session( 
     | 
| 
      
 53 
     | 
    
         
            +
                  def find_session(_req, sid)
         
     | 
| 
       52 
54 
     | 
    
         
             
                    @mutex.synchronize do
         
     | 
| 
       53 
55 
     | 
    
         
             
                      unless sid and session = @storage.get(sid)
         
     | 
| 
       54 
56 
     | 
    
         
             
                        sid, session = generate_sid, {}
         
     | 
| 
         @@ -60,7 +62,7 @@ module Rack 
     | 
|
| 
       60 
62 
     | 
    
         
             
                  end
         
     | 
| 
       61 
63 
     | 
    
         | 
| 
       62 
64 
     | 
    
         
             
                  # Write the session.
         
     | 
| 
       63 
     | 
    
         
            -
                  def write_session( 
     | 
| 
      
 65 
     | 
    
         
            +
                  def write_session(_req, session_id, new_session, _options)
         
     | 
| 
       64 
66 
     | 
    
         
             
                    @mutex.synchronize do
         
     | 
| 
       65 
67 
     | 
    
         
             
                      @storage.set(session_id, new_session)
         
     | 
| 
       66 
68 
     | 
    
         | 
| 
         @@ -69,7 +71,7 @@ module Rack 
     | 
|
| 
       69 
71 
     | 
    
         
             
                  end
         
     | 
| 
       70 
72 
     | 
    
         | 
| 
       71 
73 
     | 
    
         
             
                  # Kill the session.
         
     | 
| 
       72 
     | 
    
         
            -
                  def delete_session( 
     | 
| 
      
 74 
     | 
    
         
            +
                  def delete_session(_req, session_id, options)
         
     | 
| 
       73 
75 
     | 
    
         
             
                    @mutex.synchronize do
         
     | 
| 
       74 
76 
     | 
    
         
             
                      @storage.delete(session_id)
         
     | 
| 
       75 
77 
     | 
    
         
             
                      generate_sid unless options[:drop]
         
     | 
| 
         @@ -80,10 +82,16 @@ module Rack 
     | 
|
| 
       80 
82 
     | 
    
         | 
| 
       81 
83 
     | 
    
         
             
                  # A wrapper around Redic to simplify calls.
         
     | 
| 
       82 
84 
     | 
    
         
             
                  class Storage
         
     | 
| 
       83 
     | 
    
         
            -
                     
     | 
| 
       84 
     | 
    
         
            -
                     
     | 
| 
       85 
     | 
    
         
            -
                     
     | 
| 
       86 
     | 
    
         
            -
                     
     | 
| 
      
 85 
     | 
    
         
            +
                    # Redis commands.
         
     | 
| 
      
 86 
     | 
    
         
            +
                    DELETE = 'DEL'.freeze
         
     | 
| 
      
 87 
     | 
    
         
            +
                    EX = 'EX'.freeze
         
     | 
| 
      
 88 
     | 
    
         
            +
                    EXISTS = 'EXISTS'.freeze
         
     | 
| 
      
 89 
     | 
    
         
            +
                    GET = 'GET'.freeze
         
     | 
| 
      
 90 
     | 
    
         
            +
                    SET = 'SET'.freeze
         
     | 
| 
      
 91 
     | 
    
         
            +
             
     | 
| 
      
 92 
     | 
    
         
            +
                    # Assorted.
         
     | 
| 
      
 93 
     | 
    
         
            +
                    PACK = 'm'.freeze
         
     | 
| 
      
 94 
     | 
    
         
            +
                    ZERO = 0
         
     | 
| 
       87 
95 
     | 
    
         | 
| 
       88 
96 
     | 
    
         
             
                    def initialize(expires, marshaller, url)
         
     | 
| 
       89 
97 
     | 
    
         
             
                      @expires = expires
         
     | 
| 
         @@ -92,7 +100,7 @@ module Rack 
     | 
|
| 
       92 
100 
     | 
    
         
             
                    end
         
     | 
| 
       93 
101 
     | 
    
         | 
| 
       94 
102 
     | 
    
         
             
                    def exists?(id)
         
     | 
| 
       95 
     | 
    
         
            -
                      @storage.call(EXISTS, id) !=  
     | 
| 
      
 103 
     | 
    
         
            +
                      @storage.call(EXISTS, id) != ZERO
         
     | 
| 
       96 
104 
     | 
    
         
             
                    end
         
     | 
| 
       97 
105 
     | 
    
         | 
| 
       98 
106 
     | 
    
         
             
                    def get(id)
         
     | 
| 
         @@ -101,7 +109,7 @@ module Rack 
     | 
|
| 
       101 
109 
     | 
    
         | 
| 
       102 
110 
     | 
    
         
             
                    def set(id, object)
         
     | 
| 
       103 
111 
     | 
    
         
             
                      arguments = [SET, id, serialize(object)]
         
     | 
| 
       104 
     | 
    
         
            -
                      arguments = arguments + [ 
     | 
| 
      
 112 
     | 
    
         
            +
                      arguments = arguments + [EX, @expires] if @expires
         
     | 
| 
       105 
113 
     | 
    
         | 
| 
       106 
114 
     | 
    
         
             
                      @storage.call(*arguments)
         
     | 
| 
       107 
115 
     | 
    
         
             
                    end
         
     | 
| 
         @@ -114,13 +122,12 @@ module Rack 
     | 
|
| 
       114 
122 
     | 
    
         | 
| 
       115 
123 
     | 
    
         
             
                    # Should always return a string.
         
     | 
| 
       116 
124 
     | 
    
         
             
                    def serialize(object)
         
     | 
| 
       117 
     | 
    
         
            -
                      [Zlib::Deflate.deflate(@marshaller.dump(object))].pack( 
     | 
| 
      
 125 
     | 
    
         
            +
                      [Zlib::Deflate.deflate(@marshaller.dump(object))].pack(PACK)
         
     | 
| 
       118 
126 
     | 
    
         
             
                    end
         
     | 
| 
       119 
127 
     | 
    
         | 
| 
       120 
128 
     | 
    
         
             
                    # Should always return the session object.
         
     | 
| 
       121 
129 
     | 
    
         
             
                    def deserialize(string)
         
     | 
| 
       122 
     | 
    
         
            -
                       
     | 
| 
       123 
     | 
    
         
            -
                      @marshaller.load(Zlib::Inflate.inflate(string.unpack('m').first))
         
     | 
| 
      
 130 
     | 
    
         
            +
                      @marshaller.load(Zlib::Inflate.inflate(string.unpack(PACK).first))
         
     | 
| 
       124 
131 
     | 
    
         
             
                    end
         
     | 
| 
       125 
132 
     | 
    
         
             
                  end
         
     | 
| 
       126 
133 
     | 
    
         
             
                end
         
     | 
    
        data/rack-redic.gemspec
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: rack-redic
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.3.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Evan Lecklider
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2016- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2016-10-03 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: rack
         
     |