Home  >  Q&A  >  body text

多进程 - 多个进程去读取redis消息队列是否会发生冲突?

问题

我创建多个进程去同时读取redis做的消息队列 请问这个会发生读取冲突么? 原因是什么呢?

PHP中文网PHP中文网2733 days ago983

reply all(3)I'll reply

  • 黄舟

    黄舟2017-04-27 09:05:23

    No conflicts, each element in the queue will only be read once.

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-04-27 09:05:23

    No problem just reading. . .

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-27 09:05:23

    Redis itself guarantees mutual exclusion of queue reading and writing. Redis is single-threaded and works roughly like this. Your multi-process reading can actually send multiple read request packets in parallel. These request packets arrive in the socket buffer of redis. The processing of redis is to respond to your request serially without locks. If redis is changed to multi-threading one day, you can also lock the mutex to ensure that nothing happens when reading the queue.

    reply
    0
  • Cancelreply