在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:koajs/koa-redis开源软件地址:https://github.com/koajs/koa-redis开源编程语言:JavaScript 100.0%开源软件介绍:koa-redis
v4.0.0+ now uses Table of ContentsInstallnpm: npm install koa-redis yarn: yarn add koa-redis Usage
For more examples, please see the examples folder of Basicconst session = require('koa-generic-session');
const redisStore = require('koa-redis');
const koa = require('koa');
const app = koa();
app.keys = ['keys', 'keykeys'];
app.use(session({
store: redisStore({
// Options specified here
})
}));
app.use(function *() {
switch (this.path) {
case '/get':
get.call(this);
break;
case '/remove':
remove.call(this);
break;
case '/regenerate':
yield regenerate.call(this);
break;
}
});
function get() {
const session = this.session;
session.count = session.count || 0;
session.count++;
this.body = session.count;
}
function remove() {
this.session = null;
this.body = 0;
}
function *regenerate() {
get.call(this);
yield this.regenerateSession();
get.call(this);
}
app.listen(8080); Sentinelconst session = require('koa-generic-session');
const redisStore = require('koa-redis');
const koa = require('koa');
const app = koa();
app.keys = ['keys', 'keykeys'];
app.use(session({
store: redisStore({
// Options specified here
// <https://github.com/luin/ioredis#sentinel>
sentinels: [
{ host: 'localhost', port: 26379 },
{ host: 'localhost', port: 26380 }
// ...
],
name: 'mymaster'
})
}));
// ... Clusterconst session = require('koa-generic-session');
const redisStore = require('koa-redis');
const koa = require('koa');
const app = koa();
app.keys = ['keys', 'keykeys'];
app.use(session({
store: redisStore({
// Options specified here
// <https://github.com/luin/ioredis#cluster>
isRedisCluster: true,
nodes: [
{
port: 6380,
host: '127.0.0.1'
},
{
port: 6381,
host: '127.0.0.1'
}
// ...
],
// <https://github.com/luin/ioredis/blob/master/API.md#new-clusterstartupnodes-options>
clusterOptions: {
// ...
redisOptions: {
// ...
}
}
})
}));
// ... Options
EventsSee the Note that as of v4.0.0 the APIThese are some the functions that const session = require('koa-generic-session');
const redisStore = require('koa-redis')({
// Options specified here
});
const app = require('koa')();
app.keys = ['keys', 'keykeys'];
app.use(session({
store: redisStore
})); options)module(Initialize the Redis connection with the optionally provided options (see above). The variable session.get(sid)Generator that gets a session by ID. Returns parsed JSON is exists, session.set(sid, sess, ttl)Generator that sets a JSON session by ID with an optional time-to-live (ttl) in milliseconds. Yields session.destroy(sid)Generator that destroys a session (removes it from Redis) by ID. Tields session.quit()Generator that stops a Redis session after everything in the queue has completed. Yields session.end()Alias to session.statusString giving the connection status updated using session.connectedBoolean giving the connection status updated using session.clientDirect access to the Benchmark
Detailed benchmark report here Testing
LicenseMIT © dead_horse Contributors
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论