I was trying to connect Redis (v4.0.1) to my express server with typescript but having a bit issue. Am learning typescript. It’s showing redlines on host inside redis.createClient() Can anyone help me out?
const host = process.env.REDIS_HOST;
const port = process.env.REDIS_PORT;
const redisClient = redis.createClient({
host,
port,
});
Argument of type '{ host: string | undefined; port: string | undefined; }' is not assignable to parameter of type 'Omit<RedisClientOptions<never, RedisScripts>, "modules">'.
Object literal may only specify known properties, and 'host' does not exist in type 'Omit<RedisClientOptions<never, RedisScripts>, "modules">'.ts(2345)
4
Answers
Options have changed when redis updated to 4.0.1. This should help you.
This works as expected (redis v4.1.0)
what I did in my project was this
file: services/internal/cache.ts
then you just import where you need:
The option to add a host, port in redis.createClient is no longer supported by redis. So it is not inside type createClient. use URL instead.