Gathering detailed insights and metrics for koa2-session-ioredis
Gathering detailed insights and metrics for koa2-session-ioredis
Gathering detailed insights and metrics for koa2-session-ioredis
Gathering detailed insights and metrics for koa2-session-ioredis
npm install koa2-session-ioredis
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
83 Commits
1 Watchers
5 Branches
1 Contributors
Updated on Oct 14, 2024
Latest Version
1.2.1
Package Id
koa2-session-ioredis@1.2.1
Unpacked Size
15.41 kB
Size
5.42 kB
File Count
5
NPM Version
8.19.4
Node Version
16.20.2
Published on
Oct 14, 2024
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Redis storage for koa session middleware/cache using ioredis.
npm i koa2-session-ioredis ioredis --save
koa2-session-ioredis
works with koa-session (a session middleware for koa v2).
1const session = require('koa-session'); 2const RedisStore = require('koa2-session-ioredis'); 3const Koa = require('koa'); 4 5const app = new Koa(); 6app.keys = ['keys', 'keykeys']; 7app.use(session({ 8 key: 'koa:sess', /** (string) cookie key (default is koa:sess) */ 9 /** (number || 'session') maxAge in ms (default is 1 days) */ 10 /** 'session' will result in a cookie that expires when session/browser is closed */ 11 /** Warning: If a session cookie is stolen, this cookie will never expire */ 12 maxAge: 86400000, 13 overwrite: true, /** (boolean) can overwrite or not (default true) */ 14 httpOnly: true, /** (boolean) httpOnly or not (default true) */ 15 signed: true, /** (boolean) signed or not (default true) */ 16 rolling: false, /** (boolean) Force a session identifier cookie to be set on every response. The expiration is reset to the original maxAge, resetting the expiration countdown. (default is false) */ 17 renew: false, /** (boolean) renew session when session is nearly expired, so we can always keep user logged in. (default is false)*/ 18 store: new RedisStore({ 19 // Options specified here 20 // all `ioredis` options 21 }) 22}, app)); 23 24app.use(async ctx => { 25 switch (ctx.path) { 26 case '/get': 27 get.call(this); 28 break; 29 case '/remove': 30 remove.call(this); 31 break; 32 case '/regenerate': 33 await regenerate.call(this); 34 break; 35 } 36}); 37 38function get() { 39 var session = this.session; 40 session.count = session.count || 0; 41 session.count++; 42 this.body = session.count; 43} 44 45function remove() { 46 this.session = null; 47 this.body = 0; 48} 49 50async function regenerate() { 51 get.call(this); 52 await this.regenerateSession(); 53 get.call(this); 54} 55 56app.listen(8080);
For more examples, please see the examples folder of koa-session
.
ioredis
optionshost
, port
, and path
to the server. Defaults to 127.0.0.1:6379
client
(object) - supply your own client, all other options are ignored unless duplicate
is also suppliedduplicate
(boolean) - When true, it will run client.duplicate(options)
on the supplied client
and use all other options supplied. This is useful if you want to select a different DB for sessions but also want to base from the same client object.See the ioredis
docs for more info.
ready
connect
reconnecting
error
end
close
idle
These are some the funcitons that koa-session
uses that you can use manually. You will need to inintialize differently than the example above:
1const session = require('koa-session'); 2const redisStore = require('koa2-session-ioredis')({ 3 // Options specified here 4}); 5const app = require('koa')(); 6 7app.keys = ['keys', 'keykeys']; 8app.use(session({ 9 //... other options 10 store: new redisStore() 11}, app));
Initialize the Redis connection with the optionally provided options (see above). The variable session
below references this.
Generator that gets a session by ID. Returns parsed JSON is exists, null
if it does not exist, and nothing upon error.
Generator that sets a JSON session by ID with an optional time-to-live (ttl) in milliseconds. Yields ioredis
's client.set()
or client.setex()
.
Generator that destroys a session (removes it from Redis) by ID. Yields ioredis
's client.del()
.
Generator that stops a Redis session after everything in the queue has completed. Yields ioredis
's client.quit()
.
Alias to session.quit()
. It is not safe to use the real end function, as it cuts of the queue.
String giving the connection status updated using client.status
after any of the events above is fired.
connecting
connect
ready
reconnecting
end
monitoring
Direct access to the ioredis
client.
Server | Transaction rate | Response time |
---|---|---|
connect without session | 6763.56 trans/sec | 0.01 secs |
koa without session | 5684.75 trans/sec | 0.01 secs |
connect with session | 2759.70 trans/sec | 0.02 secs |
koa with session | 2355.38 trans/sec | 0.02 secs |
Detailed benchmark report here
localhost:6379
. You can use redis-windows
if you are on Windows or just want a quick VM-based server.npm i
in it (Windows should work fine).DEBUG
flag.npm test
to run the tests and generate coverage. To run the tests without generating coverage, run npm run-script test-only
.See the contributing tab
(The MIT License)
Copyright (c) 2015 dead-horse and other contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
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.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More