reddiz
This module provides API to store sessions using redis database. There are only two easy methods: get and set. To process user request properly you need firstly read session, then probably change it and finally save changes.
require('reddiz')(optionsᵒᵇʲ)
To use reddiz you need to require a module and call an imported function with options. These options just are passed to redis-client constructor (read more about available settings here). Now you are able to use reddiz.
You may want to use some crutches or hacks, when working with a redis-client. So keep in mind that one is available here:
globalSymbol
returns reddizᵒᵇʲ
get(idˢᵗʳ)
This method returns a promise and calls resolve-function with a session by id. Object of session contains the following fields:
- id - session's identifier;
- timeout - the number of seconds before expiration or null;
- time - the time of the last update;
- data - JSON-compatible object.
If session, having required id, is not found, null is passed to resolve.
returns promiseᴬ⁺
set(idˢᵗʳ, dataᵒᵇʲ, timeoutⁿᵘᵐ, timeⁿᵘᵐ)
This method returns a promise and calls resolve-function with a new session object. It gets the following parameters:
- id - string unique identifier of a new session;
- data - JSON-compatible object;
- timeout - expiration time in redis (by default 7 * 86400 that is one week);
- time - the time of the last update, which you are able to set manually (by default current time).
returns promiseᴬ⁺
Usage example
Let's look at an easy example:
'use strict';let http = reddiz = oneDay = 24 * 3600; http;
Also there is another example, how to use reddiz in a real project.