Class: RackCAS::RedisStore::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/rack-cas/session_store/redis.rb

Class Method Summary collapse

Class Method Details

.clientObject


6
7
8
9
# File 'lib/rack-cas/session_store/redis.rb', line 6

def self.client
  @client ||= (RackCAS.config.redis_options? ? Redis.new(RackCAS.config.redis_options) : Redis.new)
  return @client
end

.delete(session_id) ⇒ Object


38
39
40
# File 'lib/rack-cas/session_store/redis.rb', line 38

def self.delete(session_id)
  self.client.del("rack_cas_session:#{session_id}")
end

.destroy_by_cas_ticket(cas_ticket) ⇒ Object


29
30
31
32
33
34
35
36
# File 'lib/rack-cas/session_store/redis.rb', line 29

def self.destroy_by_cas_ticket(cas_ticket)
  session_id = self.client.get("rack_cas_ticket:#{cas_ticket}")
  results = self.client.pipelined do
    self.client.del("rack_cas_ticket:#{cas_ticket}")
    self.client.del(session_id)
  end
  return results[1]
end

.find_by_id(session_id) ⇒ Object


11
12
13
14
# File 'lib/rack-cas/session_store/redis.rb', line 11

def self.find_by_id(session_id)
  session = self.client.get("rack_cas_session:#{session_id}")
  session ? {'sid' => session_id, 'data' => session} : session
end

.write(session_id:, data:, cas_ticket:) ⇒ Object


16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rack-cas/session_store/redis.rb', line 16

def self.write(session_id:, data:, cas_ticket: )
  #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.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)
  end

  results == ["OK",true,"OK",true] ? session_id : false
end