node-redis | A high performance Node.js Redis client | Runtime Evironment library
kandi X-RAY | node-redis Summary
kandi X-RAY | node-redis Summary
A high performance Node.js Redis client.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of node-redis
node-redis Key Features
node-redis Examples and Code Snippets
client.set('Tm9kZSBSZWRpcw==', 'users:1');
client.sAdd('users:1:tokens', 'Tm9kZSBSZWRpcw==');
await Promise.all([
client.set('Tm9kZSBSZWRpcw==', 'users:1'),
client.sAdd('users:1:tokens', 'Tm9kZSBSZWRpcw==')
]);
await client.sendCommand(['SET', 'key', 'value', 'NX']); // 'OK'
await client.sendCommand(['HGETALL', 'key']); // ['key1', 'field1', 'key2', 'field2']
Community Discussions
Trending Discussions on node-redis
QUESTION
I am unable to set and get key in redis using node-redis. But set and get works well when using redis-cli. This is my code:
...ANSWER
Answered 2021-Apr-21 at 12:48Thanks all for suggestion. I posted the question as issue on the repo https://github.com/NodeRedis/node-redis/issues/1599 and got the answer from leibale:
QUESTION
I am using node-redis. I have a cron job that updates my db and I have redis cache that caches the db response.
The problem I'm having is that my cron job runs everyday at 12am, however I can only set redis cache to expire in x seconds from now. Is there a way to make node-redis cache expire everyday at 12am exactly. Thanks.
Code:
...ANSWER
Answered 2021-Apr-10 at 21:04yes, you can use https://redis.io/commands/expireat command, if you use https://www.npmjs.com/package/redis package as redis driver, code will be like this
QUESTION
I am using Node Redis with this config:
...ANSWER
Answered 2021-Mar-31 at 20:26Setting enable_offline_queue
to false
did the trick. Found lots of similar questions but none mentioned this:
Nodejs set timeout for Redis requests
What's the default timeout of ioredis send command for any redis call
How to set read timeout on node redis client?
Finally got this solution from here: https://github.com/NodeRedis/node-redis/issues/789#issuecomment-373270272
Do keep in mind that, with enable_offline_queue
set to false, the commands that you issue while there's some connection issue with the server will never be executed.
QUESTION
I have a Node.js web application which uses redis as session storage. Some requests receive the following ReplyError while trying to save
the session:
ANSWER
Answered 2020-Dec-08 at 08:20It turned out to be a known issue with manually saving a session in connect-redis
. More info can be found at https://github.com/tj/connect-redis/issues/292.
QUESTION
I am trying to write a timer for a game. I decided to use Redis and Web Sockets to keep the timer consistent across multiple devices. I have a function that works however when I go to call it recursively with either setTimeout or setInterval I get a "Range Error: Maximum call stack size exceeded". I can not figure out how to bypass this error. Does anyone know if it has to do with the blocking nature of the node-redis publish method? I have attached the code below.
...ANSWER
Answered 2020-Oct-15 at 05:31You are executing tick()
before setting an interval which results in an infinite loop:
QUESTION
I am using node (TypeScript) and node-redis library. Since I use TypeScript, I also imported @types/redis.
In addition, I read this article on how to promisify redis methods for TypeScript usage: https://flaviocopes.com/node-promisify/
My problem is that is that it works for some redis methods (like GET, SET, etc) but it does not work with e.g. HSET or HGETALL.
If I look into type suggestions, I see the critical methods are actually not methods at all, but rather properties (hset, HSET):
Why is this so? How can I access those needed methods?
I guess I am doing something obvious wrong. Any ideas?
...ANSWER
Answered 2020-Aug-22 at 18:16I took a look at the source code of the typings and it seems that e.g. get
is defined as a function:
QUESTION
Edit: After thinking about the issue, the real question is what is an example of connecting to digitalocean's managed redis with node-redis using tls?
I'm able to connect just fine with redisinsight GUI client using username / password, but cannot connect with nodejs. It's on the same computer so no firewall issues.
...ANSWER
Answered 2020-Aug-16 at 07:36The AUTH
command, as stated in the docs:
When ACLs are used, the single argument form of the command, where only the password is specified, assumes that the implicit username is "default".
So even if you are using Redis 6, where additional users are supported, your authentication for default
should work.
The error you're seeing is the result of a broken connection, e.g. you somehow lost connection with the Redis server. node-redis
is dealing with one of two scenarios (or both) - the connection has timed out or the the reconnect attempts have exceeded the maximum number specified in a config. I would double check your connection information and how your redis server is configured.
I see you are using TLS, you may find this useful: Securing Node Redis
If you want to authenticate node-redis client with a different user, when using Redis 6, you will have to use send_command
, but before you need to remove the current AUTH
command, as currently node-redis doesn't support the new command AUTH
.
QUESTION
Context: I am building an application that will be accessed concurrently by 1000 users and using Redis as the database. I am using node-redis client. I read that it's recommended to have only one or few connections open from each instance of the application because opening connections is expensive.
Question: Suppose the client sends a command to Redis. This command is in transit to Redis or being executed (essentially, not completed) when the application needs to send another command. Does the client wait for the first command to be completed or does it fire the second command to Redis right then?
This is important because if the client waits, the application is not really able to make full use of async and the network calls will become a big bottleneck when commands from a thousand users are trying to access Redis. It's better that the commands are queued up in Redis already instead of having them wait for an earlier command to complete before going through the network.
Thanks!
...ANSWER
Answered 2020-Aug-14 at 21:15You can run multiple instances of your node application and then balance the load using Nginx (assuming you're using it). The client won't have to wait and the load will be balanced.
Use Redis Pub/Sub to create connections.
Here's documentation for reference.
Update: Found a detailed step by step explanation here
QUESTION
Wondering if anyone could help me out with this, as I'm new to NestJS.
I'm trying to use Redis in my existing NestJS service, rather than creating a separate microservice like Nest documents in their examples. When I import redis from node-redis it comes back as undefined.
token.service.ts
...ANSWER
Answered 2020-Jul-06 at 19:07You're likely having an issue with the import statement.
Try replacing
QUESTION
I have one redis client for pub-sub. I'm using a websocket message handler to dynamically subscribe to a redis channel. The payload of the websocket message contains an ID that I use to create the channel-name. So for example lobby:${lobbyID}:joined
.
Subscribing to this channel works fine, messages are received when publishing to that channel.
But the issue that I'm having is that I want to unsubscribe from this channel at one point. My assumption by reading the redis-documentation is that I would use punsubscribe
so I can unsubscribe from any channels with the pattern lobby:*:joined
, but messages are still received after trying that.
ANSWER
Answered 2020-Apr-27 at 16:04I noticed that there are two different types of subscriptions. On channels and patterns. In my question I was subscribing to a channel, and unsubscribing on a pattern, these two are not 'compatible' so this won't work.
I used nc
to debug this, as redis-cli
won't allow additional commands when entering subscribed state.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install node-redis
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page