ioredis-koa
Redis storage for koa application or session middleware/cache,which supports cluster.
Usage
- koa middleware: redis middleware for Koa
- redis client:
ioredis-koa
is same as ioredis (A robust, performance-focused and full-featured Redis client for Node.js) - session:
ioredis-koa
works with koa-generic-session (a generic session middleware for koa) and supports cluster mode.
Quick Start
Install
npm install ioredis-koa
Example
as koa middleware
var Koa = ;var redisMid = middleware;var app = ; appappapp
as a redis client
- init a single node
var Redis = ;var redis = port: 6379 // Redis port host: '127.0.0.1' // Redis host family: 4 // 4 (IPv4) or 6 (IPv6) password: 'auth' db: 0;
- init a redis cluser
var Redis = ;var redis = port: 6380 host: '127.0.0.1' port: 6381 host: '127.0.0.1' redisOptions: password: 'your-cluster-password' ;
- useage example:
redis;redis; // Or using a promise if the last argument isn't a functionredis; // Arguments to commands are flattened, so the following are the same:redis;redis; // All arguments are passed directly to the redis server:redis;
See more examples of ioredis
.
as a session middleware
These are some the funcitons that koa-generic-session uses that you can use manually. You will need to inintialize differently than the example above:
var session = ;var redisStore = port: 6380 host: '127.0.0.1' port: 6381 host: '127.0.0.1' redisOptions: password: 'your-cluster-password' ;var app = ; appkeys = 'keys' 'keykeys';app;
For more examples, please see the examples folder of koa-generic-session
.
Options
- all
ioredis
options
Testing
- Start a Redis server on
localhost:6379
. You can useredis-windows
if you are on Windows or just want a quick VM-based server. - Clone the repository and run
npm i
in it (Windows should work fine). - If you want to see debug output, turn on the prompt's
DEBUG
flag.
Authors
See the Author
Licences
(The MIT License)
Copyright (c) 2019 godky 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.