redis / hiredis

Minimalistic C client for Redis >= 1.2
BSD 3-Clause "New" or "Revised" License
6.15k stars 1.8k forks source link

set cmd failed and get cmd value wrong #1222

Closed BenjaminBBr closed 2 months ago

BenjaminBBr commented 10 months ago

My application has a thread and a hireis handle. In some cases, the set command fails, and the reply handle is available, but it does not establish a new connection to continue to use. There are still a large number of set command failures and get command value errors. 1. What circumstances will cause the set command to fail. 2. Is it due to the subsequent value error caused by the continued use of the wrong connection?

michael-grunder commented 10 months ago

Over the years we have had dozens of similar questions related to using hiredis in a multithreaded environment.

In every case, the issue was due to improper sharing of the redisContext between threads. Keep in mind that redisContext is not thread-safe, so you must take great care when using it in a multi-threaded environment.

The only real suggestion I can give you is to use the standard tools to debug such issues such as valgrind, rr, or the various compiler sanitizers at your disposal (-fsanitize=thread, -fsanitize=address, etc).

michael-grunder commented 2 months ago

Going to close this issue since it's unlikely an issue in hiredis.

If you can provide a reproducer I'm happy to take a look.