当前位置:网站首页>Redis publishing and subscription

Redis publishing and subscription

2022-07-07 18:48:00 Gravel under Mount Everest

What is publish and subscribe

Generally speaking , Publish and subscribe ( also called pub/sub) Is characterized by subscribers (listener) Subscribe to the channel (channel), Publisher (publisher) Responsible for sending binary string messages to channels (binary string message). Whenever a message is sent to a given channel , All subscribers to the channel will receive messages . We can also think of channels as radio stations , Subscribers can listen to multiple stations at the same time , The sender can send messages on any radio station .

Common publish and subscribe commands

command meaning
subscribesubscribe channel [channel …]---- Subscribe to a given channel or channels
unsubscribeunsubscribe channel [channel…]---- Unsubscribe from a given channel or channels , If no channel is given at the time of execution , Then unsubscribe all channels
publishpushlish channel [channel …]— Send a message to a given channel
psubscribepsubscribe pattern [pattern…]— Subscribe to all channels that match the given pattern
punsubscribepunsubscribe pattern [pattern …]— Unsubscribe from the given mode , If no mode is given at the time of execution , Then unsubscribe from all modes

Rarely used Redis The reason for publishing and subscribing to

  • Reason one and redis The stability of the system . For the old version Redis Come on , If a client subscribes to one or more channels , But it doesn't read messages fast enough , Then the continuous backlog of information will make Redis The volume of the output buffer becomes larger and larger , This may lead to Redis It's slowing down , Even the immediate collapse . It can also lead to Redis Killed by the operating system , Even the operating system itself is not available . new edition Redis There won't be such a problem , Because it will automatically disconnect the nonconformity client-output-buffer-limitpubsub Subscription clients required by configuration options .
  • The second reason is related to the reliability of data transmission . Any network system may encounter disconnection during operation , The continuous error caused by disconnection usually causes one end of the two ends of the network connection to reconnect . however , If the client is disconnected during the subscription operation , Then the client will lose all messages sent during the disconnection .
原网站

版权声明
本文为[Gravel under Mount Everest]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207071637121604.html

随机推荐