Closed jinq0123 closed 7 years ago
Hi, Let me describe me why it's completely thread safe.
redisContext is not thread safe i know. But this does not mean that you can't use one redisContext instance in several threads. You can, but carefuly - If the only one thread executes commands on particular redisContext instance in time - it's ok! Trust me, I've inspected the sources of hiredis library.
How thread safety is achived? - there is the class ThreadedPool which purpose is to ensure that only one thread can execute commands on particular redisContext instance in particular moment. Thread initially gets one redisContext from pool (at this time connection is deleted from pool), executes the command, and lets it back to the pool. So there's no threading error. Thank you for your post.
ThreadedPool can not make Cluster thread-safe because neither redisContext nor redisAsyncContext is thread-safe.
From hiredis readme:
So threadedpool example is wrong. It executes 1000 commandThread() which calls
redisAppendFormattedCommand()
without mutex lock.