1

i need to give statistic about my publisher app like how many subscribers are there?

i cant seen to get that information from the redis server

i already tried to find in the 'ServiceStack.Redis.RedisSubscription'

i found this:

        var channel = ConfigurationManager.AppSettings["redis_channel"];
        var _redisClient = new RedisClient("localhost", 6379);
        var subscription = _redisClient.CreateSubscription();
        //subscription.SubscribeToChannels(channel);
        var subscription_count = (int)subscription.SubscriptionCount

but it returning 0 every time.

any ideas?

edit: i found this http://redis.io/commands/client-list but steel need some help on how to use it thanks : )

4

1 回答 1

1

我知道了!

如果有人需要,我就是这样做的:

var redis_ip = ConfigurationManager.AppSettings["redis_server_ip"];
        var redis_port = ConfigurationManager.AppSettings["redis_server_port"];
        int redis_port_int = 0;
        if (!int.TryParse(redis_port, out redis_port_int))
        {
            redis_port_int = 6739;
        }
        RedisNativeClient rnClient = new RedisNativeClient(redis_ip, redis_port_int);
        var clientlist_byte = rnClient.ClientList();
        var clientlist_string = Encoding.UTF8.GetString(clientlist_byte);
        var clientamount_double = clientlist_string.Split("\n".ToCharArray()).Length;
        var clientlist_int = (clientamount_double/2) - 1;
        return clientlist_int;

'-1' 是从计数中删除我的 selt,/2 这是因为在拆分后我得到了双倍的数量

于 2014-08-17T19:28:48.997 回答