Git Product home page Git Product logo

aerospike-session-store-expressjs's Introduction

aerospike-session-store

aerospike-session-store is an implementation of the ExpressJS session store that uses Aerospike as the persistence layer for sessions.

Installation

via npm:

$ npm install aerospike-session-store

Options

  • ttl Aerospike record ttl in seconds.
  • hosts The collection of hosts on which Aerospike is deployed.
  • prefix The optional prefix for each session key, in case the Aerospike servers are shared with something generating its own keys. Default 'sess:' is used if no value is provided.
  • ns The optional Aerospike namespace to be used for session storage. The 'test' namespace is used if no value is provided.
  • st The name of the Aerospike set used to create the session store. A set named 'store' is used if no value is provided.

Usage

Initialization

var session = require('express-session');
var aerospikeStore = require('aerospike-session-store')(session);

var AeroSpikeStore = new aerospikeStore({
  ttl: 86400,
  hosts: ['127.0.0.1:3000'],
  prefix: 'sess:',
  ns: 'test'
});

var app = express();
app.use(session({
  secret: '123456789QWERTY',
  store: AeroSpikeStore,
  resave: false,
  saveUninitialized: false
}));

Set session

Stores the session into the Aerospike session store. Session values are serialized into a string and saved in the Aerospike session store as a string.

set(<sessionID>, {cookie:{maxAge:<n seconds>}, <session value>}, <callback_function(err,res)>)

Options

  • sessionID The unique session id.
  • maxAge The ttl value for session. This value is in seconds.
  • session value e.g., email: '[email protected]'.
  • callback_function(err,res) Returns error codes. err = returns error, if any. res contains session key.

Example

AeroSpikeStore.set('session1',{cookie:{maxAge:2000},name:'firstname lastname'}, function(err, ok){
          if(err) throw err;
      });

Get session

Retrieves session based on the given sessionID. Returns error if the requested session is not found.

get(<sessionID>, <callback_function(err,res)>)

Options

  • sessionID The ID of the session id to be retrieved.
  • callback_function(err,res) Returns error codes or session object in JSON. err holds error. res holds session object.

Example

AeroSpikeStore.get('session1', function(err, ok){
        assert.ok(err.code === 0, 'get error!!!!');
        assert.ok(ok.cookie.maxAge===2000,'get maxAge error!!!!');
        assert.ok(ok.name ==='y.p','get name error!!!!'); 
      });

Session length

Returns the number of sessions stored in the session store.

length(<callback_function(err,res)>)

Options

  • callback_function(err,res) Returns error codes or length as integer (0 or >0. err holds error. res holds length as integer.

Example

AeroSpikeStore.length(function(length){
        console.log(length);
      });

Destroy particular user session

Destroys the requested session

destroy(<sessionID>,<callback_function(err,res)>)

Options

  • sessionID The ID of the session to be destroyed.
  • callback_function(err,res) Returns error if the requested session cannot be destroyed.

Example

AeroSpikeStore.destroy('session1', function(err){
        if(err) throw err;
      });

Session length

Returns the number of sessions stored in the session store.

length(<callback_function(err,res)>)

Options

  • callback_function(err,res) Returns error codes or length as integer (0 or >0. err holds error. res holds length as integer.

Example

AeroSpikeStore.length(function(length){
        console.log(length);
      });

Destroy particular user session

Destroys the requested session

destroy(<sessionID>,<callback_function(err,res)>)

Options

  • sessionID The ID of the session to be destroyed.
  • callback_function(err,res) Returns error if the requested session cannot be destroyed.

Example

AeroSpikeStore.destroy('session1', function(err){
  			if(err) throw err;
  		});

Tests

You need mocha.

make test

OR

mocha test

Benchmark

You need benchmark.

node ./benchmark/benchmark.js

License

Copyright (c) 2011-2015

{Licence and copyright notice to go here}

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

aerospike-session-store-expressjs's People

Contributors

nilesh-gawde avatar sunilvirus avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.