Leo
Leo

Reputation: 417

Unable to set up Redis in a Node.js project

when using client.set('hi', 'there') , I was getting Uncaught ClientClosedError: The client is closed redis , so I had to use:

client.connect()

It worked but then I was getting an unresolved promise, so I had to use await:

await client.set('hi', 'there')

It then worked, but now when I am using client.hset('german', 'red', 'rot') , I am getting:

Uncaught TypeError: client.hset is not a function

I am following a tutorial that did not mention the use of client.connect() nor await when using client.set('hi', 'there')

Not sure if I installed the wrong version of Redis. I installed it using yarn because I was having issues with npm.

Upvotes: 1

Views: 1000

Answers (2)

miloss
miloss

Reputation: 1768

In newer versions, Node-redis provides built-in support for all of the out-of-the-box Redis commands. They are exposed using the raw Redis command names (HSET, HGETALL, etc.) and a friendlier camel-cased version (hSet, hGetAll, etc.):

// raw Redis commands
await client.HSET('key', 'field', 'value');
await client.HGETALL('key');

// friendly JavaScript commands
await client.hSet('key', 'field', 'value');
await client.hGetAll('key');

More about this here

Upvotes: 1

Leo
Leo

Reputation: 417

Solved. I was using different versions of redis

Upvotes: 0

Related Questions