npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

reddiz

v0.0.9

Published

The simplest sessions in redis.

Downloads

5

Readme

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:

global[Symbol.for('__reddiz-client__')]

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 = require('http'),
    reddiz = require('reddiz')(),
    oneDay = 24 * 3600;

http.createServer((request, response) => {
    let sessionId = request.url;

    function onError (error) {
        response.write('Something has gone wrong!\n');
        response.write(error + '');
        response.end();
    };

    function onSuccess (session) {
        response.write(session.data.counter + '');
        session.data.counter++;

        reddiz
            .set(session.id, session.data, oneDay)
            .then(session => {
                response.end();
            })
            .catch(onError);
    };

    reddiz
        .get(sessionId)
        .then(session => {
            if (session) {
                onSuccess(session);
            } else {
                reddiz
                    .set(sessionId, {counter: 0}, oneDay)
                    .then(onSuccess)
                    .catch(onError);
            }
        })
        .catch(onError);
}).listen(80);

Also there is another example, how to use reddiz in a real project.