Module: Hsdq::Session
- Included in:
- Hsdq
- Defined in:
- lib/hsdq/session.rb
Instance Method Summary collapse
-
#hsdq_session(session_id, *keys) ⇒ Array, Hash
Retrieve the session hash from the session layer and return the data (see below).
-
#hsdq_session_del(session_id, *keys) ⇒ Object
delete all keys from the session.
-
#hsdq_session_destroy(session_id) ⇒ Object
delete the whole session hash.
-
#hsdq_session_expire(session_id, in_seconds) ⇒ Object
reset the expiration time for the session.
-
#hsdq_session_expire_in(session_id) ⇒ Object
return the expiration time remaining before expiration.
-
#hsdq_session_key?(session_id, key) ⇒ Boolean
check if a key exist in the session hash.
-
#hsdq_session_set(session_id, *key_values) ⇒ Object
Store in the session layer in the session hash one or an array of key values (string or json) Create the session hash if it do not exist.
Instance Method Details
#hsdq_session(session_id, *keys) ⇒ Array, Hash
Retrieve the session hash from the session layer and return the data (see below)
23 24 25 26 27 28 29 30 31 |
# File 'lib/hsdq/session.rb', line 23 def hsdq_session(session_id, *keys) if keys.any? #get only the provided keys cx_session.hmget session_key(session_id), *keys else # get all keys return a hash cx_session.hgetall session_key(session_id) end end |
#hsdq_session_del(session_id, *keys) ⇒ Object
delete all keys from the session
34 35 36 |
# File 'lib/hsdq/session.rb', line 34 def hsdq_session_del(session_id, *keys) cx_session.hdel session_key(session_id), *keys.flatten end |
#hsdq_session_destroy(session_id) ⇒ Object
delete the whole session hash
39 40 41 |
# File 'lib/hsdq/session.rb', line 39 def hsdq_session_destroy(session_id) cx_session.del session_key(session_id) end |
#hsdq_session_expire(session_id, in_seconds) ⇒ Object
reset the expiration time for the session
44 45 46 |
# File 'lib/hsdq/session.rb', line 44 def hsdq_session_expire(session_id, in_seconds) cx_session.expire session_key(session_id), in_seconds end |
#hsdq_session_expire_in(session_id) ⇒ Object
return the expiration time remaining before expiration
49 50 51 |
# File 'lib/hsdq/session.rb', line 49 def hsdq_session_expire_in(session_id) cx_session.ttl session_key(session_id) end |
#hsdq_session_key?(session_id, key) ⇒ Boolean
check if a key exist in the session hash
54 55 56 |
# File 'lib/hsdq/session.rb', line 54 def hsdq_session_key?(session_id, key) cx_session.hexists session_key(session_id), key end |
#hsdq_session_set(session_id, *key_values) ⇒ Object
Store in the session layer in the session hash one or an array of key values (string or json) Create the session hash if it do not exist.
8 9 10 11 12 13 14 15 16 |
# File 'lib/hsdq/session.rb', line 8 def hsdq_session_set(session_id, *key_values) key_values = key_values[0].to_a if 1 == key_values.flatten.size && key_values[0].is_a?(Hash) hkey = session_key(session_id) cx_session.multi do cx_session.hmset hkey, *key_values.flatten cx_session.expire hkey, 259200 #3 days todo set by options end end |