Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

typescript error in redis - on event

import * as redis from 'redis'
import config from '../../config/config'
const client = redis.createClient(config.redis.port, host, config.redis.options);
client.on('ready', () => {
  console.log('redis is ready.')
});

getting below error in typescript

[ts] Property 'on' does not exist on type '{ address: any; connection_options: { [x: string]: any; }; connection_id: number; connected: bool...'. any

like image 231
Thavaprakash Swaminathan Avatar asked Oct 19 '25 15:10

Thavaprakash Swaminathan


1 Answers

First of all, have you installed the type module for the redis module? I highly recommend doing that as it helps TypeScript compiler and potentially your IDE to know what commands and interfaces are available in the redis module. To do so:

npm i --save-dev @types/redis

Second, try adding the .on('error', console.error) to see if your client is emitting any meaningful connection errors. There could be a problem with you client credentials, which fails the connections.

Lastly, you can completely skip the .on('ready', ...) event handler as it's not necessary. The redis module queues all the commands sent before the connection is established, and will automatically send them once it's successfully connected. You can just start testing the client with simple set and get commands.

like image 58
Behrooz Avatar answered Oct 22 '25 04:10

Behrooz



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!