Is the hiredis c client thread thread safe

2,113 views
Skip to first unread message

Ramprasad Padmanabhan

unread,
Jun 24, 2015, 6:54:26 AM6/24/15
to redi...@googlegroups.com
I am using the hiredis client to enqueue jobs in a milter process.
Milters are multithreaded running concurrent threads and all threads may be connecting to redis at the same time


李代立

unread,
Jun 24, 2015, 8:36:14 AM6/24/15
to redi...@googlegroups.com

Yes, It’s thread safe. Basically, it depends on how you use it. Each thread should own a “redisContext “ for itself. If your multithread owns one global “redisContext”, it’s not safe.

 

Thanks,

David Li

 

发件人: redi...@googlegroups.com [mailto:redi...@googlegroups.com] 代表 Ramprasad Padmanabhan
发送时间: 2015624 18:54
收件人: redi...@googlegroups.com
主题: [redis-db] Is the hiredis c client thread thread safe

 

I am using the hiredis client to enqueue jobs in a milter process.
Milters are multithreaded running concurrent threads and all threads may be connecting to redis at the same time

--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+u...@googlegroups.com.
To post to this group, send email to redi...@googlegroups.com.
Visit this group at http://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.

Jan-Erik Rediger

unread,
Jun 24, 2015, 9:02:11 AM6/24/15
to redi...@googlegroups.com
Well, that's then usually called "not thread-safe" ;)
You can't share a single context between multiple threads.

Ramprasad Padmanabhan

unread,
Jun 25, 2015, 3:25:19 AM6/25/15
to redi...@googlegroups.com, jan...@fnordig.de
In that case should I create a new redis connection for every thread in my C program

Is that a good coding practice

Eigenfield Aparicio

unread,
Sep 22, 2016, 12:24:56 PM9/22/16
to Redis DB
You must in each thread keep a separate redis context or else, the 'select db' command of one thread influences the writes of the other thread. For example, in thread1 you 'select 0' and then thread switches to thread2 just about to a set x " apple" so then the x="apple" key-value pair gets written to db0, even though thread2 did a "select 1" intention to write the key there.
Reply all
Reply to author
Forward
0 new messages