koa-simple-redis
v1.0.2
Published
koa session with redis using koa-simple-session
Downloads
8
Readme
koa-simple-redis
Redis storage for koa session middleware/cache, based on koa-redis.
Installation
$ npm install koa-simple-redis
Examples
View the ./examples directory for working examples.
API
Constructor
options
redis options
const Redis = require('koa-simple-redis');
const client = new Redis({
url: 'redis://127.0.0.1:6379/2',
});
set
id
data's iddata
data for cachettl
ttl for data, optional
Set data to the redis or with ttl.
const Redis = require('koa-simple-redis');
const client = new Redis({
url: 'redis://127.0.0.1:6379/2',
});
client.set('vicanso', {
a: 1
}).then(() => {
console.info('success');
});
client.set('jenny', {
a: 1
}, 10 * 1000).then(() => {
console.info('success');
});
get
id
data's id
Get data from redis.
const Redis = require('koa-simple-redis');
const client = new Redis({
url: 'redis://127.0.0.1:6379/2',
});
client.set('vicanso', {
a: 1
}).then(() => {
return client.get('vicanso')
}).then(data => {
console.info(data);
console.info('success');
});
destroy
id
data's id
Delete data for redis.
const Redis = require('koa-simple-redis');
const client = new Redis({
url: 'redis://127.0.0.1:6379/2',
});
client.set('vicanso', {
a: 1
}).then(() => {
return client.get('vicanso')
}).then(() => {
console.info('success');
});
ttl
id
data's idttl
the data's ttl
Get/Set the data's ttl
const Redis = require('koa-simple-redis');
const client = new Redis({
url: 'redis://127.0.0.1:6379/2',
});
client.set('vicanso', {
a: 1
}, 10 * 1000).then(() => {
return client.ttl('vicanso')
}).then((ttl) => {
console.info('success');
return client.ttl('vicanso', 30 * 1000);
});
quid
Quit to connect reids.
const Redis = require('koa-simple-redis');
const client = new Redis({
url: 'redis://127.0.0.1:6379/2',
});
client.quit().then(() => {
console.info('success');
});
License
MIT