Skip to content

Commit

Permalink
Merge pull request #2 from paladinsoftware/feat/expired-time-config-f…
Browse files Browse the repository at this point in the history
…or-redis

Feat/expired time config for redis
  • Loading branch information
comictvn authored Oct 28, 2022
2 parents ee92b75 + cf88fd1 commit 15004da
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions lib/rack-cas/session_store/redis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ def self.find_by_id(session_id)
session ? {'sid' => session_id, 'data' => session} : session
end

def self.write(session_id:, data:, cas_ticket: )
def self.write(session_id:, data:, cas_ticket:, expire_after: nil)
#create a row with the session_id and the data
#create a row with the cas_ticket acting as a reverse index
results = self.client.pipelined do
self.client.set("rack_cas_session:#{session_id}",data)
self.client.expireat("rack_cas_session:#{session_id}",30.days.from_now.to_i)
self.client.expireat("rack_cas_session:#{session_id}",expire_after.present? ? expire_after.from_now.to_i : 30.days.from_now.to_i)
self.client.set("rack_cas_ticket:#{cas_ticket}","rack_cas_session:#{session_id}")
self.client.expireat("rack_cas_ticket:#{cas_ticket}",30.days.from_now.to_i)
self.client.expireat("rack_cas_ticket:#{cas_ticket}",expire_after.present? ? expire_after.from_now.to_i : 30.days.from_now.to_i)
end

results == ["OK",true,"OK",true] ? session_id : false
Expand Down Expand Up @@ -72,8 +72,7 @@ def find_session(env, sid)
# Rack 2.0 method
def write_session(env, sid, session_data, options)
cas_ticket = (session_data['cas']['ticket'] unless session_data['cas'].nil?)

success = Session.write(session_id: sid, data: pack(session_data), cas_ticket: cas_ticket)
success = Session.write(session_id: sid, data: pack(session_data), cas_ticket: cas_ticket, expire_after: options[:expire_after])

success ? sid : false
end
Expand Down

0 comments on commit 15004da

Please sign in to comment.