redis with node code example
Example 1: redis nodejs
/* npm install redis */
const redis = require("redis");
const client = redis.createClient();
client.on("error", function(error) {
console.error(error);
});
client.set("key", "value", redis.print);
client.get("key", redis.print);
Example 2: node-redis
// node-redis to promise, because node-redis not support promise
import bluebird from 'bluebird'
import { Commands, createClient } from 'redis'
const client = createClient({
host: process.env.REDIS_HOST,
port: parseInt(process.env.REDIS_PORT),
password: process.env.REDIS_PASSWORD
})
let redisCon: Commands<any>
;(async (redis) => {
const redisPromise = await bluebird.resolve<Commands<any>>(redis)
redisCon = redisPromise
})(client)
export { redisCon }