abstract class
Amber::Adapters::SessionAdapter
- Amber::Adapters::SessionAdapter
- Reference
- Object
Overview
Abstract base class for session storage adapters.
All session storage implementations should inherit from this class and implement the required abstract methods. This allows the Amber framework to work with any backend storage system (Redis, database, memory, etc.) through a unified interface.
Example implementation:
class CustomSessionAdapter < Amber::Adapters::SessionAdapter
def initialize(@connection : MyStorageConnection)
end
def get(session_id : String, key : String) : String?
@connection.fetch("#{session_id}:#{key}")
end
# ... implement other abstract methods
end
Direct Known Subclasses
Defined in:
amber/adapters/session_adapter.crInstance Method Summary
-
#batch(session_id : String, &block : SessionBatchOperations -> ) : Nil
Provides a way to perform multiple operations in a single atomic block.
-
#batch_set(session_id : String, hash : Hash(String, String)) : Nil
Efficiently sets multiple key-value pairs in a single operation.
-
#close : Nil
Called when the adapter is being shut down.
-
#delete(session_id : String, key : String) : Nil
Deletes a specific key from the session.
-
#destroy(session_id : String) : Nil
Completely destroys the session and all its data.
-
#empty?(session_id : String) : Bool
Checks if the session is empty (contains no keys).
-
#exists?(session_id : String, key : String) : Bool
Checks if a specific key exists within the session.
-
#expire(session_id : String, seconds : Int32) : Nil
Sets an expiration time for the session in seconds from now.
-
#get(session_id : String, key : String) : String | Nil
Retrieves a value for the given key within the specified session.
-
#healthy? : Bool
Called to check if the adapter is healthy and ready to handle requests.
-
#keys(session_id : String) : Array(String)
Returns all keys present in the session.
-
#set(session_id : String, key : String, value : String) : Nil
Sets a value for the given key within the specified session.
-
#to_hash(session_id : String) : Hash(String, String)
Returns the entire session as a Hash.
-
#values(session_id : String) : Array(String)
Returns all values present in the session.
Instance Method Detail
Provides a way to perform multiple operations in a single atomic block. This is useful for adapters that support pipelining or transactions.
Efficiently sets multiple key-value pairs in a single operation. This should be atomic where possible to maintain session consistency.
Called when the adapter is being shut down. Override this method to perform cleanup operations like closing connections.
Deletes a specific key from the session. Should be a no-op if the key doesn't exist.
Completely destroys the session and all its data.
Checks if the session is empty (contains no keys). Note: Some implementations may consider a session with only metadata (like session_id) as empty for application purposes.
Checks if a specific key exists within the session.
Sets an expiration time for the session in seconds from now. A value of 0 or negative should remove any existing expiration.
Retrieves a value for the given key within the specified session. Returns the value as a String, or nil if the key doesn't exist.
Called to check if the adapter is healthy and ready to handle requests. Override this method to implement health checks for your storage backend.
Returns all keys present in the session.
Sets a value for the given key within the specified session.
Returns the entire session as a Hash.
Returns all values present in the session.