From bd1239fbc7614c8c86ff5e1a7a2086642b6980e3 Mon Sep 17 00:00:00 2001 From: "Kevin.Nguyen" Date: Thu, 27 Oct 2022 13:46:25 +0700 Subject: [PATCH 1/2] feat: config redis expired time --- lib/rack-cas/session_store/redis.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/rack-cas/session_store/redis.rb b/lib/rack-cas/session_store/redis.rb index a688b96..a053d7c 100644 --- a/lib/rack-cas/session_store/redis.rb +++ b/lib/rack-cas/session_store/redis.rb @@ -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:, expires_in: 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}",expires_in.present? ? expires_in.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}",expires_in.present? ? expires_in.from_now.to_i : 30.days.from_now.to_i) end results == ["OK",true,"OK",true] ? session_id : false @@ -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, expires_in: options[:expire_after]) success ? sid : false end From cf88fd14e9e64a948ebc69620e82e1e8be42ab05 Mon Sep 17 00:00:00 2001 From: Kevin Date: Fri, 28 Oct 2022 11:13:32 +0700 Subject: [PATCH 2/2] change expires_in naming --- lib/rack-cas/session_store/redis.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/rack-cas/session_store/redis.rb b/lib/rack-cas/session_store/redis.rb index a053d7c..f3d6a15 100644 --- a/lib/rack-cas/session_store/redis.rb +++ b/lib/rack-cas/session_store/redis.rb @@ -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:, expires_in: nil) + 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}",expires_in.present? ? expires_in.from_now.to_i : 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}",expires_in.present? ? expires_in.from_now.to_i : 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 @@ -72,7 +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, expires_in: options[:expire_after]) + success = Session.write(session_id: sid, data: pack(session_data), cas_ticket: cas_ticket, expire_after: options[:expire_after]) success ? sid : false end