Exemple #1
0
 /// <summary>
 ///  阻塞命令:从list中keys的尾部移除一个值,并返回移除的值,阻塞时间为sp
 /// </summary>
 public string BlockingDequeueItemFromList(string key, TimeSpan?sp)
 {
     using (IRedisClient Core = CreateRedisClient())
     {
         return(Core.BlockingDequeueItemFromList(key, sp));
     }
 }
        /// <summary>
        /// 阻塞命令:从list中一个fromkey的尾部移除一个值,添加到另外一个tokey的头部,并返回移除的值,阻塞时间为sp
        /// </summary>
        public string BlockingPopAndPushItemBetweenLists(string fromkey, string tokey, TimeSpan?sp)
        {
            using (IRedisClient rc = RedisCacheStrategy.redisClient)
            {
                var toValue = rc.BlockingDequeueItemFromList(fromkey, sp);
                rc.PushItemToList(tokey, toValue);
                return(toValue);
            }

            //return BaseRedis.redisClient.BlockingPopAndPushItemBetweenLists(fromkey, tokey, sp);
        }
        private string ReadMessage(IRedisClient client, int timeoutInMilliseconds)
        {
            var msg      = string.Empty;
            var latestId = client.BlockingDequeueItemFromList(_queueName, TimeSpan.FromMilliseconds(timeoutInMilliseconds));

            if (latestId != null)
            {
                var key = _topic + "." + latestId;
                msg = client.GetValue(key);
                _logger.Value.InfoFormat(
                    "Redis: Received message from queue {0} with routing key {0}, message: {1}",
                    _queueName, _topic, JsonConvert.SerializeObject(msg), Environment.NewLine);
            }
            else
            {
                _logger.Value.DebugFormat(
                    "RmqMessageConsumer: Time out without receiving message from queue {0} with routing key {1}",
                    _queueName, _topic);
            }
            return(msg);
        }