Пример #1
0
        static void Main(string[] args)
        {
            RedisHelper.Initialization(RedisUtil.RedisClient);
            Console.WriteLine("here is log service ...");
            Logger logger = new Logger();

            while (true)
            {
                var order = RedisHelper.BRPop <Order>(1, "Order:Log");
                if (order != null)
                {
                    //Console.WriteLine("1:{0}",order);
                    logger.WriteLog(order);
                }
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            RedisHelper.Initialization(RedisUtil.RedisClient);
            var a1 = RedisHelper.SubscribeListBroadcast("Order:Add", "sms", BroadcastSms);

            Console.WriteLine("here is sms service ...");
            SmsService smsService = new SmsService();

            while (true)
            {
                var order = RedisHelper.BRPop <Order>(1, "Order:Sms");
                if (order != null)
                {
                    //Console.WriteLine("1:{0}",order);
                    smsService.SendSms(order);
                }
            }
        }
Пример #3
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            _logger.LogInformation("Service starting");
            if (_cSRedisClients == null)
            {
                _cSRedisClients = new CSRedisClient(_conf.GetConnectionString("redis") + ",defaultDatabase=" + 0);
            }
            RedisHelper.Initialization(_cSRedisClients);

            while (!stoppingToken.IsCancellationRequested)
            {
                var key      = $"{DateTime.Now.ToString("yyyyMMdd")}";
                var eqidpair = RedisHelper.BRPop(5, key);
                if (eqidpair != null)
                {
                    _logger.LogInformation(eqidpair);
                }
                //await _eqidPairHandler.AcceptEqidParamAsync(JsonConvert.DeserializeObject<EqidPair>(eqidpair));
                // 强烈建议无论如何休眠一段时间,防止突发大流量导致webApp进程CPU满载,自行根据场景设置合理休眠时间
                await Task.Delay(10, stoppingToken);
            }
            _logger.LogInformation("Service stopping");
        }
Пример #4
0
 /// <summary>
 /// 移出并获取列表的最后一个元素, 如果列表没有元素会阻塞列表直到等待超时或发现可弹出元素为止。
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="timeout">超时(秒)</param>
 /// <param name="keys">不含prefix前缀</param>
 /// <returns>如果列表为空,返回一个 nil 。 否则,返回被弹出元素的值。</returns>
 public T BRPop <T>(int timeout, params string[] keys) => RedisHelper.BRPop <T>(timeout, keys);
Пример #5
0
 /// <summary>
 /// 移出并获取列表的最后一个元素, 如果列表没有元素会阻塞列表直到等待超时或发现可弹出元素为止。
 /// </summary>
 /// <param name="timeout">超时(秒)</param>
 /// <param name="keys">不含prefix前缀</param>
 /// <returns>如果列表为空,返回一个 nil 。 否则,返回被弹出元素的值。 </returns>
 public string BRPop(int timeout, params string[] keys) => RedisHelper.BRPop(timeout, keys);