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

拥有回忆 提交于 2019-12-06 13:15:44

问题


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 ?


回答1:


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.



来源:https://stackoverflow.com/questions/17274638/redis-behavior-with-multiple-concurrent-programs-doing-read-del-on-the-same-hash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!