Stackexchange.redis Use-Publish Subscription (II)

Source: Internet
Author: User

Using the Publish subscription feature of Redis

Another common use of redis is the ability to publish subscriptions. It is very simple and connectionmultiplexer will automatically re-subscribe when the connection fails.

Isubscriber sub = Redis. Getsubscriber ();

The Getsubscriber method returns an instance of the Isubscriber type. The Publish subscription feature does not have a database concept, and we can provide a async-state for it. All subscriptions are global:
Isubscriber instances are not their lifecycle, and the features of the publish subscription are defined in Redis as "channels", and channels do not need to be pre-defined in the database. Subscription operation requires a channel
Name and a callback function to process the published message.

Sub. Subscribe ("Messages", (channel, message) + = {
Console.WriteLine ((string) message);
});

You can post a message to the specified channel:

Sub. Publish ("Messages", "Hello");

He will publish the message "Hello" to all clients subscribed to the messages channel (almost in real time). As before, the name and message of the channel can be binary as well.


Specify the order in which messages are published (Message order)

When using the Pub/sub API, you can specify whether the message is parallel or sequential.
Orderly means you don't have to think about thread safety, but it also means that messages are passed through the queue exactly in the order you publish them, which inevitably leads to a delay in the message.
Parallel processing, there is no guarantee that the message is processed in the order of publication, and your code must also ensure that the program runs normally when there is concurrency.
The order of messages is usually irrelevant, and parallel processing can achieve better performance and scalability.

To ensure security, message delivery is ordered by default. For better performance, it is strongly recommended that you use parallel operations. This is very simple.

Multiplexer. Preserveasyncorder = false;

The recommendation is not the reason you are configuring this option, and whether it is suitable depends entirely on the code that you subscribe to the message.

Stackexchange.redis Use-Publish Subscription (II)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.