Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redis behavior with multiple concurrent programs doing read/del on the same hash key

I've a program (program_1) (Jedis-based) that writes to a Redis HASH (KEY_1) on a regular basis. I've another program (program_2) (separate JVM process) that executes periodically, and in a Redis transaction does the following:

        Transaction transaction = redis.multi();
        //get the current entity table
        Response<Map<String, String>> currentEntityTableResponse = transaction.hgetAll(KEY_1);
        transaction.del(KEY_1);
        transaction.exec();

My assumption is when program_2 has deleted the HASH (with KEY_1) the next time program_1 runs it will create the HASH again. Is this correct ?

like image 551
Soumya Simanta Avatar asked Jan 14 '23 02:01

Soumya Simanta


1 Answers

Yes. Redis is single threaded and transactions block until they finish, so if program_2 starts, the hash KEY_1 will no longer exist when program1 runs again.

like image 198
Eli Avatar answered Jan 31 '23 09:01

Eli