Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hazelcast-store

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hazelcast-store

Hazelcast implementation of expressjs session store

  • 0.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
18
decreased by-35.71%
Maintainers
1
Weekly downloads
 
Created
Source

npm Dependencies Downloads

hazelcast-store is a Hazelcast session store backed by hazelcast-client.

NOTE: This is a first pass, use at your own risk. I will be glad to accept pull requests to fix bugs or add new features.

Setup

npm install hazelcast-store express-session

Pass the express-session store into hazelcast-store to create a HazelcastStore constructor, which then creates a new Store instance to pass to express sessions. Note: since the Hazelcast Client generation is asynchronous it's a little tricky to add early in the app.use() chain. See below for a method to add the HazelcastClient to the HazelcastStore after creation.

var session = require('express-session');
var HazecastStore = require('hazelcast-store')(session);

const hzStore = new HazelcastStore({ ttl: 15*60*1000, debugPrefix: 'oc' });
app.use(session({
  store: hzStore,
  secret: 'argle bargle'
}));

Example implementation of Hazelcast Client and setting it on the HazelcastStore

const HazelcastClient = require('hazelcast-client').Client;
const HazelcastConfig = require('hazelcast-client').Config;

var clientConfig = new HazelcastConfig.ClientConfig();
clientConfig.networkConfig.addresses = [{host: '127.0.0.1', 5701}];

HazelcastClient
  .newHazelcastClient(clientConfig)       
  .then(function (hzInstance) {  
    debug("HazelCast Client successfully created!");
    if (hazelcastStore && config.hazelcast.sessions) 
    hazelcastStore.setClient(hzInstance);
    app.hzClient = hzInstance;
});

Options

A full initialized Hazelcast Client is required. This client is either passed directly using the client param or can be added after creating the HazelcastStore using the store.addClient() method. This method is probably the easiest because the code that creates an instance of the Hazelcast client is asynchronous.

The following additional params are optional:

  • ttl Hazelcast session TTL (expiration) in milli-seconds
  • debugPrefix prefix to use with debug module so this module's output can be seen with your app's debug output
  • disableTTL Disables setting TTL, keys will stay in Hazelcast until evicted by other means (overides ttl)
  • prefix Key prefix defaulting to "sess:"
  • logErrors Whether or not to log client errors. (default: false)
    • If true, a default logging function (console.error) is provided.
    • If a function, it is called anytime an error occurs (useful for custom logging)
    • If false, no logging occurs.

TODO

  1. Custom serialization
  2. Possily implement touch() method. Is express-sessions even using it any more? Doesn't seem like it
  3. Implement clear(), all() and length()
  4. Handle hazelcast down/unreachable? (Most likely node will just throw an error)

License

MIT

Keywords

FAQs

Package last updated on 24 Aug 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc