how to use redis in node js code example
Example 1: redis nodejs
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
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 }