Hello,everyone,I am a beginner of redis come from China,I have a question about redis hash data structure: condition one: I run redis on a single node on Linux and I used jedis to store a hash of 100000 pieces of data,then I use redis-cli to connect to redis and use hgetall to query all hashes. It takes about 14 seconds,In these 14s, I started a Java application and used jedis to set the value of 10000 of the 100000 pieces of data to another value,Results for the query results displayed in redis-cli, all the keys are the original value。 condition two: I started two Java applications A and B. application A uses the jedis loop to query the hash in the redis node. When the hash length is 0, it takes about 50 milliseconds to query each time. At this time, it takes about 2 seconds to open application B to hmset 100000 pieces of data in the hash. In these two seconds, application A can still hgetall normally and can't perceive the data stored by application B, When the storage of application B ends, application A will get stuck, and then start to query the data stored by application A.
As far as I know, redis is a single thread to execute commands, so why can it still execute storage commands when executing query commands? Or can the query command still be executed when it is stored? Did jedis optimize it for us? Or does redis query and storage not affect each other?
My email: 386126949@qq.com My wechat: linrantop
Thank you!
Comment From: sundb
hi @linranranran , redis is still single-threaded when processing commands. When you execute 10,000 commands, redis does not read all the commands from io buffer at once, so it is possible to execute the query in the middle of processing the 10,000 commands. Are you using pipeline?
Comment From: linranranran
hi @linranranran , redis is still single-threaded when processing commands. When you execute 10,000 commands, redis does not read all the commands from io buffer at once, so it is possible to execute the query in the middle of processing the 10,000 commands. Are you using pipeline?
@sundb Thank you for your reply. I use the most basic hgetall and hmset commands. Forgive me for not making it clear. I insert 100000 pieces of data into a hmset command. This command needs to be executed for 12 seconds, and the query command can be executed in these 12 seconds.
Comment From: sundb
You can confirm the size of your command, I guess your command consumes most of the time on the network io, not the execution of the command, redis reads the whole command takes multiple event cycles, so in these multiple cycles, I can still execute other command.
Comment From: linranranran
You can confirm the size of your command, I guess your command consumes most of the time on the network io, not the execution of the command, redis reads the whole command takes multiple event cycles, so in these multiple cycles, I can still execute other command.
You are right. Network IO takes a lot of time. Thank you for your reminding. I know much better. In other words, when executing a very long command, redis does not wait for the command to be executed before executing other commands. Instead, redis divides the long command into multiple cycles and executes them separately. Am I right?
Comment From: sundb
@linranranran I'm not sure if you've got it wrong, it's not that the command takes longer to execute, it's that the long command is slower to read out of io, and when you're executing the query, the command to write the operation is not yet fully read so it will execute more slowly, even if you send it first.
Comment From: linranranran
@linranranran I'm not sure if you've got it wrong, it's not that the command takes longer to execute, it's that the long command is slower to read out of io, and when you're executing the query, the command to write the operation is not yet fully read so it will execute more slowly, even if you send it first.
OK, thank you. I will continue to learn the underlying principles of redis!
Comment From: sundb
@linranranran Feel free to ask questions, next time you can create in redis discuss, because issue is the place for bugs or features.
Comment From: linranranran
@linranranran Feel free to ask questions, next time you can create in redis discuss, because issue is the place for bugs or features.
got it!