This module acts as a plugin for library(http/http_session), storing
session information on a Redis server. This has several consequences:
- The Prolog server may be restarted without loosing session data.
This is notably useful when long session timeouts are used.
- Multiple Prolog servers can act as a cluster while session
management is used.
- Associating Prolog data with sessions is relatively slow. The
assert/retract is replaced by managing a Redis list. Data in
this list is matched sequentially, where each term needs to be
parsed before it can be matched.
- Associated data is currently limited to ground terms.
The library is activated by loading it in addition to
library(http/http_session) and using http_set_session_options/1 to
configure the Redis database as below. The redis_server/2 predicate from
library(redis) can be used to specify the parameters for the redis
server such as host, port or authentication.
Redis key usage
All Redis keys reside under a prefix specified by the option
redis_prefix(Prefix), which defaults to
'swipl:http:session'. Here we
- An ordered set at <prefix>:expire that contains the session ids,
ordered by the time the session expires. Session enumeration and
garbage collection is based on this set.
- A hash at <prefix>:session:<id> which contains the peer address,
the last used time and optionally session specific settings.
- If there is session data, a list at <prefix>:data:<id> of Prolog
terms, represented as strings that contain the session data.