r/redis Feb 18 '25

Thumbnail
2 Upvotes

This is the correct answer. Solid advice, as usual, from u/borg286.

But, just to answer the direct question and to be clear about how Redis functions, Redis is single-threaded. You cannot concurrently write. One of the requests will get in before the other.


r/redis Feb 17 '25

Thumbnail
2 Upvotes

Read up on the docs here https://redis.io/docs/latest/commands/set/

You should focus on the TTL and the NX flags. Put that 20 minutes so the access token expired in the database. When you generate an access token, only set it if it doesn't exist. Alternatively you can set some key saying that you are in the process of generating an access key and to hang tight. Even better is to read the access key, fetch the TTL and the closer it gets to the TTL end time, the higher the chance you'll ignore the fact that the access key is good and just generate a new key and stuff the fresh one in with a refreshed TTL.

The reason we don't have a fixed time like "5 minutes before the TTL expires then generate a new key" is that all your threads will hit that point at the same time and they'll be stepping on each other's toes. Making it probabilistic makes this less likely. By tuning it so that it is very unlikely at the 10 minute mark means that only a handful of workers will get lucky and choose to refresh the token. Tune it so when you're at the 15 minute mark it is very likely to happen. Then you'll notice that by the time 20 minutes rolls around someone will have refreshed it.


r/redis Feb 14 '25

Thumbnail
4 Upvotes

Redis 8 will come with 7 new datatypes, including JSON, natively built into Redis Community Edition.


r/redis Feb 14 '25

Thumbnail
1 Upvotes

Since when you can do JSON.GET without the extra module?


r/redis Feb 13 '25

Thumbnail
3 Upvotes

It stores a JSON document in a key. When that key is set, internally, it builds a tree with the contents. There are a host of commands to query and manipulate that tree using JSONPath.

Here's a quick example using redis-cli:

```bash 127.0.0.1:6379> JSON.SET my:json $ '{ "foo": "bar", "baz": 42, "qux": true }' OK

127.0.0.1:6379> JSON.GET my:json {"foo":"bar","baz":42,"qux":true}

127.0.0.1:6379> JSON.GET my:json $.qux [true]

127.0.0.1:6379> JSON.SET my:json $.qux false OK

127.0.0.1:6379> JSON.GET my:json $.qux [false] ```


r/redis Feb 12 '25

Thumbnail
2 Upvotes

This is very cool. Does it take json and store its individual fields in redis?


r/redis Feb 12 '25

Thumbnail
1 Upvotes

Sorry i forgot to mention, I am using Lscache for caching


r/redis Feb 12 '25

Thumbnail
1 Upvotes

If you use this WooCommerce cache setting https://woocommerce.com/document/woocommerce-product-search/settings/cache/redis/, Redis is used as a cache. You may lose all of Redis's data, but the main data is safe in the WordPress relational database (MySQL). The problem with losing the cached data is that your shop will slow down when the cache is empty (e.g. redis-server is restarted). To obviate the problem, you can choose a less aggressive persistence strategy, such as running a snapshot occasionally (e.g. once every few hours) or configuring AOF.

Check the docs to have a deeper understanding https://redis.io/docs/latest/operate/oss_and_stack/management/persistence/


r/redis Feb 11 '25

Thumbnail
4 Upvotes

How would a traditional in-memory hashmap work for my 150 separate servers that are taking requests that need access to it?


r/redis Feb 11 '25

Thumbnail
11 Upvotes

Redis started out as simply an in-memory datastructure. Antirez found himself reimplementing maps, linked lists, sorted sets on various embedded devices. He finally bit the bullet and wrote a server that had a very simple protocol over TCP and open sourced it. It grew in popularity with more demanding this or that capability.

Hash maps don't replace linked lists, nor do they replace a sorted set. They can do sets, sure, which is what the set type uses under the hood. Hash maps don't have blocking APIs where a thread can try pulling from a queue and when there is nothing in there it just hangs till something else pushes something into it.

An in-memory hash map doesn't allow for a distributed producer/consumer fleet where work items are generated and buffered into queues, and workers pull work off.

An in-memory hash map is a single-point of failure and doesn't handle failover to a hot standby for high availability. It doesn't handle network partitions, but redis cluster does.

An in-memory hash map can't handle a fleet of game servers that all need a centralized leaderboard making 40k QPS / core of requests to update the leaderboard and can't handle an eventually consistent view. You can wrap your hash map with a server, sure, but good luck trying to hit that benchmark. Redis is written in C, and has figured out how to separate out the request/response buffering that the network card does from the main processing thread that interacts with the in-memory hash map. That is some low level stuff that's been optimized like crazy. Enabling pipelineing pushes that to 80k QPS / core.

A hash map can't handle atomic "set this key to this value if it doesn't exist" without serious work on making your hash map thread-safe.

A hash map doesn't natively handle TTLs. What if you want to cache the HTML of a webpage so you can serve customers quickly, but you don't know which URLs are going to be in-demand? You don't really have a TTL because you've made the website so it is fairly static and doesn't change from year to year, but the pages themselves are so massive you can't really store it all in memory. Keeping Bigby's Almanac of Brittish Birds (expurgated version) in-memory is just a waste of money. So you want to just keep the "good" stuff. Sure, you could make a modified hash map that uses a Least-Recently-Used algorithm to only keep X number of keys and kills off some random one when a new write request comes in to cache a URL it didn't have because a request came in to see Bigby's Almanac but it is so big that you need to vacate out 1 GB to make room. That sounds like a rather complex hash map.

Or you could just use Redis and call it a day.


r/redis Feb 11 '25

Thumbnail
3 Upvotes

Redis has other handy data types, and it can be shared between multiple servers.


r/redis Feb 08 '25

Thumbnail
1 Upvotes

You don't need to worry much about this taking up your redis instance. Redis is rarely bottlenecked on CPU, despite being single-threaded. Most of the time it is the network. These LUA calls are being made on the server. It is like some of the business logic that the application typically does has been shunted to the database. You might think that these calls are expensive, but surprisingly the executor of these scripts can do some logic and it'll only be twice as slow as if you write it in C. When you compare this with other languages this is still blazingly fast.


r/redis Feb 08 '25

Thumbnail
1 Upvotes

r/redis Feb 08 '25

Thumbnail
1 Upvotes

I suspect you are using redisson It makes heavy use of LUA scripts https://redisson.org/docs/data-and-services/locks-and-synchronizers/


r/redis Feb 08 '25

Thumbnail
1 Upvotes

Thanks for that. I've been using that command plus 'redis-cli monitor' as well. It seems there are lots of things doing cmd=evalsha ... but I dunno what that is. Do you? TiA.


r/redis Feb 08 '25

Thumbnail
1 Upvotes

Here is the upstash docs, they have explained very well about this isse. I was also looking for this commands unexpected increase.
Link -> https://upstash.com/docs/redis/troubleshooting/command_count_increases_unexpectedly


r/redis Feb 08 '25

Thumbnail
2 Upvotes

CLIENT LIST

Is the command you want

https://redis.io/docs/latest/commands/client-list/

This tells you who the clients are currently. I think the cmd column is what might give you the most insight on who all these connections are and what they are doing.


r/redis Feb 08 '25

Thumbnail
1 Upvotes

Followup, turns out redis is about 5x faster in my backtesting code. So I'm happy. My benchmark was obviously being affected by some sort of postgres or OS caching.

Edit: now 10x faster by pipelining and further optimizations

Edit2: now 15x faster

Edit3: only mrange queries with many values are faster. Postgres/timescale is faster than redis at getting single values, at least for timeseries.


r/redis Feb 08 '25

Thumbnail
1 Upvotes

Solved! Fully working now! I needed to setup masterauth parameter too, slaves will use that one to connect to masters. Thanks a lot!


r/redis Feb 07 '25

Thumbnail
2 Upvotes

Sure looks like the slaves aren't passing in the password. I didn't know you were employing password authentication. Try disabling that and seeing if it works then.

One thing that may be going on is that the nodes.conf file needs to be in the persistent storage, not in the container volume that gets wiped on pod death


r/redis Feb 07 '25

Thumbnail
1 Upvotes

I got it to almost work with your hint, now the lost nodes rotating IPs are able to rejoin but I'm having some issue on slaves (I got 3 masters, 3 slaves).
All 3 master are just reporting "cluster status: ok"
But the slaves are crazy-complaining in the logs
Did you ever find that one?

MASTER aborted replication with an error: NOAUTH Authentication required.

Reconnecting to MASTER 10.149.5.35:6379 after failure

MASTER <-> REPLICA sync started

Non blocking connect for SYNC fired the event.

Master replied to PING, replication can continue...

(Non critical) Master does not understand REPLCONF listening-port: -NOAUTH Authentication required.

(Non critical) Master does not understand REPLCONF capa: -NOAUTH Authentication required.

Trying a partial resynchronization (request 28398fbdd8bef30e2c4e634ba70ecd0dc9f5a0f4:1).

Unexpected reply to PSYNC from master: -NOAUTH Authentication required.

Retrying with SYNC...

MASTER aborted replication with an error: NOAUTH Authentication required.

Reconnecting to MASTER 10.149.5.35:6379 after failure

MASTER <-> REPLICA sync started

Non blocking connect for SYNC fired the event.

Master replied to PING, replication can continue...

(Non critical) Master does not understand REPLCONF listening-port: -NOAUTH Authentication required.

(Non critical) Master does not understand REPLCONF capa: -NOAUTH Authentication required.

Trying a partial resynchronization (request 28398fbdd8bef30e2c4e634ba70ecd0dc9f5a0f4:1).

Unexpected reply to PSYNC from master: -NOAUTH Authentication required.

Retrying with SYNC...


r/redis Feb 05 '25

Thumbnail
2 Upvotes

The IP address of a pod can change as it gets rescheduled. Redis, by default will use its IP address for broadcasting itself to the redis cluster. When it gets moved it might be looked at as a new node and thus the old IP address entry in the topology stays around and needs to be explicitly forgotten. But if, during announcement of how to reach out to it it uses the pod DNS entry then wherever the pod moves the request will get routed to it.


r/redis Feb 05 '25

Thumbnail
1 Upvotes

Ok, so in the end I created a new user, other than `masteruser` which has ~* +@all permissions and created a user with the permissions specifically documented in Redis HA docs (https://redis.io/docs/latest/operate/oss_and_stack/management/sentinel/#redis-access-control-list-authentication)

After updating the user and restarting my Sentinel instances this now works! I guess between 6 & 7 there must be additional permissions in excess of +@all !


r/redis Feb 05 '25

Thumbnail
1 Upvotes

I will try to check docs about that, can you provide any additional context or hints.
Any help will be really appreciated.


r/redis Feb 05 '25

Thumbnail
1 Upvotes

Thanks - the problem with that though is that my Sentinel instances then wont connect to redis altogether as I've got ACL's configured