多个并发程序在同一哈希键上执行读/删除操作时的Redis行为 [英] Redis behavior with multiple concurrent programs doing read/del on the same hash key

查看:94
本文介绍了多个并发程序在同一哈希键上执行读/删除操作时的Redis行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序( program_1 )(基于Jedis),可写入Redis HASH( KEY_1 )。我有另一个定期执行的程序( program_2 )(独立的JVM进程),在Redis事务中执行以下操作:

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();

我的假设是在program_2下一次运行program_1时,它会创建散列(使用KEY_1删除)。再次哈希。这样对吗 ?

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 ?

推荐答案

是。 Redis是单线程的交易会一直阻塞直到完成,因此,如果program_2启动,则当program1再次运行时,哈希KEY_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.

这篇关于多个并发程序在同一哈希键上执行读/删除操作时的Redis行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆