# Module `resty.session.shm`

Shared Memory (SHM) backend for session library

## Configuration

configuration | Shared memory storage backend configuration

## Constructors

module.new ([configuration]) | Create a SHM storage.

## Storage

instance:set (name, key, value, ttl, current_time[, old_key], stale_ttl[, metadata], remember) | Store session data.
instance:get (name, key) | Retrieve session data.
instance:delete (name, key[, metadata]) | Delete session data.
instance:read_metadata (name, audience, subject, current_time) | Read session metadata.

## Configuration

configuration
  Shared memory storage backend configuration

  ### Fields:

  - prefix Prefix for the keys stored in SHM.
  - suffix Suffix for the keys stored in SHM.
  - zone A name of shared memory zone (defaults to `sessions`).

## Constructors

module.new ([configuration])
  Create a SHM storage.

  This creates a new shared memory storage instance.

  ### Parameters:

  - configuration table shm storage configuration (optional)

  ### Returns:

  table shm storage instance

## Storage

instance:set (name, key, value, ttl, current_time[, old_key], stale_ttl[, metadata], remember)
  Store session data.

  ### Parameters:

  - name string cookie name
  - key string session key
  - value string session value
  - ttl number session ttl
  - current_time number current time
  - old_key string old session id (optional)
  - stale_ttl string stale ttl
  - metadata table table of metadata (optional)
  - remember boolean whether storing persistent session or not

  ### Returns:

  1. true or nil ok
  2. string error message
instance:get (name, key)
  Retrieve session data.

  ### Parameters:

  - name string cookie name
  - key string session key

  ### Returns:

  1. string or nil session data
  2. string error message
instance:delete (name, key[, metadata])
  Delete session data.

  ### Parameters:

  - name string cookie name
  - key string session key
  - metadata table session meta data (optional)

  ### Returns:

  1. boolean or nil session data
  2. string error message
instance:read_metadata (name, audience, subject, current_time)
  Read session metadata.

  ### Parameters:

  - name string cookie name
  - audience string session key
  - subject string session key
  - current_time number current time

  ### Returns:

  1. table or nil session metadata
  2. string error message

generated by LDoc 1.5.0 Last updated 2025-07-29 12:02:00