Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请问有支持sharded pub sub的计划吗? #156

Open
caoyang1024 opened this issue Sep 1, 2023 · 13 comments
Open

请问有支持sharded pub sub的计划吗? #156

caoyang1024 opened this issue Sep 1, 2023 · 13 comments

Comments

@caoyang1024
Copy link

caoyang1024 commented Sep 1, 2023

Sharded Pub/Sub

From Redis 7.0, sharded Pub/Sub is introduced in which shard channels are assigned to slots by the same algorithm used to assign keys to slots. A shard message must be sent to a node that owns the slot the shard channel is hashed to. The cluster makes sure the published shard messages are forwarded to all nodes in the shard, so clients can subscribe to a shard channel by connecting to either the master responsible for the slot, or to any of its replicas. SSUBSCRIBE, SUNSUBSCRIBE and SPUBLISH are used to implement sharded Pub/Sub.

Sharded Pub/Sub helps to scale the usage of Pub/Sub in cluster mode. It restricts the propagation of messages to be within the shard of a cluster. Hence, the amount of data passing through the cluster bus is limited in comparison to global Pub/Sub where each message propagates to each node in the cluster. This allows users to horizontally scale the Pub/Sub usage by adding more shards.

请问有支持此功能的计划吗?
感谢

@2881099
Copy link
Owner

2881099 commented Sep 1, 2023

可以,这几天增加命令

2881099 added a commit that referenced this issue Sep 1, 2023
@2881099
Copy link
Owner

2881099 commented Sep 1, 2023

v1.1.8 尝试一下吧,记得反馈

@2881099
Copy link
Owner

2881099 commented Sep 1, 2023

  • .SPublish
  • .PubSubShardChannels
  • .PubSubShardNumSub
  • .SSubscribe
  • .SUnSubscribe

上述方法,记得都尝试一下后反馈

@caoyang1024
Copy link
Author

我看到docs里面提到:
public static RedisClient cli = new RedisClient(
new ConnectionStringBuilder[] { "192.168.0.2:7001", "192.168.0.2:7002", "192.168.0.2:7003" }
); // assume 3 masters + 3 slaves
连接cluster要提供3个master的地址。

请问假如我只提供一个master node 地址,也是可行的吗?
谢谢

@2881099
Copy link
Owner

2881099 commented Sep 5, 2023

可行

@caoyang1024
Copy link
Author

caoyang1024 commented Sep 6, 2023

9/6/2023 2:37:16 AM +00:00
Unhandled exception. System.ArgumentOutOfRangeException: Non-negative number required. (Parameter 'maxValue')
at System.Random.ThrowMaxValueMustBeNonNegative()
at System.Random.ThreadSafeRandom.Next(Int32 )
at FreeRedisTest.Program.Main(String[] args) in D:\Work\FreeRedisTest\Program.cs:line 44
at FreeRedisTest.Program.

(String[] args)

有遇到这个问题。

sample test code:

public class Program
{
    private static async Task Main(string[] args)
    {
        RedisClient cli = new(new ConnectionStringBuilder[]
        {
            "xxxxxxxx.amazonaws.com:6379,password=xxxxxxxxxxxxx"
        });

        List<string> priceList = new();

        for (int i = 0; i < 100; i++)
        {
            var price = new Price
            {
                Id = Guid.NewGuid(),
                Symbol = $"test{i}",
                Bid = 131323.32m,
                Ask = 131323.35m,
                BidVolume = 24242,
                AskVolume = 24432,
                Source = "fake",
            };

            priceList.Add(JsonSerializer.Serialize(price));
        }

        while (true)
        {
            for (int i = 0; i < 100; i++)
            {
                foreach (var price in priceList)
                {
                    await cli.PublishAsync("Price", price);

                    Console.WriteLine($"Price: {DateTimeOffset.UtcNow}");

                    await Task.Delay(Random.Shared.Next(400 - 600));
                }

                Console.WriteLine($"now: {DateTimeOffset.UtcNow}");
            }
            break;
        }
    }
}

public record Price
{
    public Guid Id { get; set; }
    public string Symbol { get; set; }
    public decimal Bid { get; set; }
    public decimal Ask { get; set; }
    public decimal BidVolume { get; set; }
    public decimal AskVolume { get; set; }
    public string Source { get; set; }
}

@2881099
Copy link
Owner

2881099 commented Sep 6, 2023

Unhandled exception. System.ArgumentOutOfRangeException: Non-negative number required. (Parameter 'maxValue')
at System.Random.ThrowMaxValueMustBeNonNegative()
at System.Random.ThreadSafeRandom.Next(Int32 )

@2881099
Copy link
Owner

2881099 commented Sep 6, 2023

是你的 Random.Shared.Next(400 - 600) 报错?

@caoyang1024
Copy link
Author

await _cli.SPublishAsync("Price", price);

FreeRedis.RedisServerException: 'MOVED 7599 127.0.0.1:7001'

这个是expected的吗

@2881099
Copy link
Owner

2881099 commented Sep 8, 2023

'MOVED 7599 127.0.0.1:7001'

集群报的错,你那边方便引用源码吗

@2881099
Copy link
Owner

2881099 commented Sep 8, 2023

方便进群,加我的QQ,提供一下测试服务器吗

我测一下几个方法。

@caoyang1024
Copy link
Author

caoyang1024 commented Sep 8, 2023

'MOVED 7599 127.0.0.1:7001'

集群报的错,你那边方便引用源码吗

可以 我尽快测一下 (QQ没有了...)

@2881099
Copy link
Owner

2881099 commented Sep 9, 2023

weinxin: q2881099

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants