1async function upsert(table, data) {
2 let key = table;
3 if (data && data.id) {
4 key = key + '_' + data.id;
5 }
6
7 client.setex(key, 10, JSON.stringify(data));
8 return true;
9}
10
1/* npm install redis */
2
3const redis = require("redis");
4const client = redis.createClient();
5
6client.on("error", function(error) {
7 console.error(error);
8});
9
10client.set("key", "value", redis.print);
11client.get("key", redis.print);
1// node-redis to promise, because node-redis not support promise
2
3import bluebird from 'bluebird'
4import { Commands, createClient } from 'redis'
5
6const client = createClient({
7 host: process.env.REDIS_HOST,
8 port: parseInt(process.env.REDIS_PORT),
9 password: process.env.REDIS_PASSWORD
10})
11
12let redisCon: Commands<any>
13;(async (redis) => {
14 const redisPromise = await bluebird.resolve<Commands<any>>(redis)
15 redisCon = redisPromise
16})(client)
17
18export { redisCon }