我正在应用程序中使用 Redis PubSub 作为通知系统。我通常有大约 1000 个并发用户。对于每个用户,我都有一个包含用户 ID 的个人频道,通过该频道发送多个个人通知。而且,每个用户都与多个“个人任务”相关(它们对于每个用户来说都是个人的,平均每个用户大约 15 个),所以我有两个选择:
只要您使用一次 SUBSCRIBE 调用,我认为这并不重要。
如果您使用单个通道,则必须在消息中放置某种类型的标记(用户、任务等),然后编写代码来处理该标记并将消息路由到正确的位置。
如果您有多个频道,这将在频道名称中表示,但您仍然需要编写代码来读取该频道并路由消息。
您应该不做的事情是使用多个通道——每个通道都有自己的与Redis的连接,订阅一个单个通道。这将导致大约 15,000 个与 Redis 的同时连接,这是很多。
以下是 redis.conf 文件中与此相关的有关 maxclients 的一些信息:
# Set the max number of connected clients at the same time. By default
# this limit is set to 10000 clients, however if the Redis server is not
# able to configure the process file limit to allow for the specified limit
# the max number of allowed clients is set to the current file limit
# minus 32 (as Redis reserves a few file descriptors for internal uses).
#
# Once the limit is reached Redis will close all the new connections sending
# an error 'max number of clients reached'.
#
# IMPORTANT: When Redis Cluster is used, the max number of connections is also
# shared with the cluster bus: every node in the cluster will use two
# connections, one incoming and another outgoing. It is important to size the
# limit accordingly in case of very large clusters.
#
# maxclients 10000
希望这有帮助,祝你好运!