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

redis3x-session

v1.2.2

Published

redis(base on redis 3.x version and support cluster mode) session middleware for express(NodeJs).

Downloads

19

Readme

redis3x-session

基于redis缓存的Express服务端session中间件, 使用它可以在单机或多集群部署服务的条件下,使用session建立与客户端的联系,并为客户端用户存储重要数据,保证各节点session数据一致。

该中间件使用分布式集群的redis(基于redis3.x版本)客户端(使用ioredis),数据在某redis节点挂掉后其它redis节点仍能正常服务,并选举出新的主节点,有效保证session数据正常存取。

示例

##使用自定义redis cluster对象

var express = require('express'),
    app = express(),
    redis3xSession = require('redis3x-session');

// 这里使用基础redis插件为例。(使用默认选项创建实例,具体可参考redis插件)
// 也可以使用支持多集群的redis客户端插件ioredis创建实例,这里不作举例,请参考ioredis)
var redis = require("redis"),
    redisCluster = redis.createClient();

// redis session缓存服务开启
app.use(redis3xSession({
    redisCluster: redisCluster,
    expires: 30 * 60
}));

##使用中间件内置分布式集群redis客户端(具体使用请参考ioredis)创建cluster

var express = require('express'),
    app = express(),
    redis3xSession = require('redis3x-session');

// redis session缓存服务开启
app.use(redis3xSession({
    redisConf: {
        redisStore: '192.168.1.1:6479,192.168.1.1:6480,192.168.1.1:6481,192.168.1.1:6482,192.168.1.1:6483,192.168.1.1:6484,192.168.1.1:6485,192.168.1.1:6486,192.168.1.1:6487'
    },
    expires: 30 * 60
}));

#使用session存取数据 ##存数据

req.rSession.userid = '124242876';
req.rSession.user = {name: 'fisher', id: '22222'};

##取数据

var userid = req.rSession.userid;

##设置客户session过期时间(若不设置,则以中间件配置的expires为过期时间,单位s(秒))

req.rSession.expires = 10 * 60;

##配置项options

###options.expires 过期时间,单位秒(s), 默认值为30 * 60(半小时)。 也可使用req.expires设置当前连接的客户端session过期时间。

###options.redisCluster redis存储实例,由用户决定使用哪种redis客户端插件,如redis, ioredis。 该选项配置时,options.redisConf配置失效.

###options.redisConf 内置redisCluster实例创建配置项,通过该选项配置的实例仅支持无需登录验证的redis节点,若需要创建含登录验证的redis,请使用redisCluster创建自定义的redis cluster。目前可选配置有: #####options.redisConf.redisStore redis各节点地址及端口配置字符串, 以','分隔,如:'192.168.1.1:6479,192.168.1.1:6480'