Module resty.session.mysql
MySQL / MariaDB backend for session library
Configuration
configuration | Postgres storage backend configuration |
Constructors
module.new ([configuration]) | Create a MySQL / MariaDB 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. |
Database
sessions | Sessions table. |
metadata | Sessions metadata table. |
Configuration
- configuration
-
Postgres storage backend configuration
Fields:
- host
The host to connect (defaults to
"127.0.0.1"
). - port
The port to connect (defaults to
3306
). - socket
The socket file to connect to (defaults to
nil
). - username
The database username to authenticate (defaults to
nil
). - password Password for authentication, may be required depending on server configuration.
- charset
The character set used on the MySQL connection (defaults to
"ascii"
). - database The database name to connect.
- table_name
Name of database table to which to store session data (defaults to
"sessions"
). - table_name_meta
Name of database meta data table to which to store session meta data (defaults to
"sessions_meta"
). - max_packet_size The upper limit for the reply packets sent from the MySQL server (defaults to 1 MB).
- connect_timeout
Controls the default timeout value used in TCP/unix-domain socket object’s
connect
method. - send_timeout
Controls the default timeout value used in TCP/unix-domain socket object’s
send
method. - read_timeout
Controls the default timeout value used in TCP/unix-domain socket object’s
receive
method. - keepalive_timeout Controls the default maximal idle time of the connections in the connection pool.
- pool A custom name for the connection pool being used.
- pool_size The size of the connection pool.
- backlog A queue size to use when the connection pool is full (configured with @pool_size).
- ssl
Enable SSL (defaults to
false
). - ssl_verify
Verify server certificate (defaults to
nil
).
- host
The host to connect (defaults to
Constructors
- module.new ([configuration])
-
Create a MySQL / MariaDB storage.
This creates a new MySQL / MariaDB storage instance.
Parameters:
- configuration table mysql/mariadb storage configuration (optional)
Returns:
-
table
mysql/mariadb 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:
- true or nil ok
- string error message
- instance:get (name, key)
-
Retrieve session data.
Parameters:
Returns:
- instance:delete (name, key[, metadata])
-
Delete session data.
Parameters:
Returns:
- boolean or nil session data
- 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:
Database
- sessions
-
Sessions table.
Database table that stores session data.
Usage:
CREATE TABLE IF NOT EXISTS sessions ( sid CHAR(43) PRIMARY KEY, name VARCHAR(255), data MEDIUMTEXT, exp DATETIME, INDEX (exp) ) CHARACTER SET ascii;
- metadata
-
Sessions metadata table.
This is only needed if you want to store session metadata.
Usage:
CREATE TABLE IF NOT EXISTS sessions_meta ( aud VARCHAR(255), sub VARCHAR(255), sid CHAR(43), PRIMARY KEY (aud, sub, sid), CONSTRAINT FOREIGN KEY (sid) REFERENCES sessions(sid) ON DELETE CASCADE ON UPDATE CASCADE ) CHARACTER SET ascii;