Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redis redis.createClient() in Typescript

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)
like image 620
Robbi Avatar asked Dec 14 '25 17:12

Robbi


2 Answers

Options have changed when redis updated to 4.0.1. This should help you.

like image 52
Tytrox Avatar answered Dec 17 '25 09:12

Tytrox


This works as expected (redis v4.1.0)

const url = process.env.REDIS_URL || 'redis://localhost:6379';
const redisClient = redis.createClient({
    url
});
like image 36
Archer Avatar answered Dec 17 '25 11:12

Archer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!