简体   繁体   中英

Two Clients Accessing REDIS Simultaneously using redis-py

I have two redis-py clients that are accessing REDIS at the same time. Both clients are running infinite loops. Both clients are also looking at the same hash. The problem is that it seems when I start the continuous hgetall loop, I can no longer hset that value.

The first client is doing continuous hgetall

while True:
    query = r.hgetall('myHash')
    for result in query:
        #do something with value1, value2

The second client is doing continuous hset. If I remove the second client and just manually hset a new value, I still cannot set a new value.

r.hset('myHash', 'value1', '23')
r.hset('myHash', 'value2', '17')

Is this because REDIS is single threaded and the client that is hgetall never releases the thread to allow an hset?

Precisely, that is why you can't hset and hgetall on the same hash. Here is the official documentation about single threaded nature. Here is a related question explaining the same behavior. Further, if you are looking to implement parllelism on top of redis , here is a guide for that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM