/// <summary> /// Asynchronously get queue attributes, counter and stats /// </summary> public async Task <QueueAttributes> GetQueueAttributesAsync(GetQueueAttributesOptions options) { Validate(options); var key = $"{_options.Namespace}:{options.QueueName}"; var time = await GetServerTime(); var transaction = RedisClient.CreateTransaction(); var queueAttrTask = transaction.HashGetAllAsync($"{key}:Q"); var msgTask = transaction.SortedSetLengthAsync(key); var hiddemMsgTask = transaction.SortedSetLengthByValueAsync(key, ((DateTimeOffset)time).ToUnixTimeMilliseconds(), "+inf"); if (await transaction.ExecuteAsync()) { var queueAttr = await queueAttrTask; var msg = await msgTask; var hiddemMsg = await hiddemMsgTask; if (queueAttr.Length == 0) { throw new QueueNotFoundException(); } var props = Utils.ExtractPropsFromRedisHashEntries(queueAttr, new string[] { "vt", "delay", "maxsize", "totalrecv", "totalsent", "created", "modified" }); return(new QueueAttributes { VisibilityTimer = int.Parse(props["vt"]), Delay = int.Parse(props["delay"]), MaxSize = int.Parse(props["maxsize"]), TotalReceived = int.Parse(props["totalrecv"] ?? "0"), TotalSent = int.Parse(props["totalsent"] ?? "0"), Created = DateTimeOffset.FromUnixTimeMilliseconds(long.Parse(props["created"])).UtcDateTime, Modified = DateTimeOffset.FromUnixTimeMilliseconds(long.Parse(props["modified"])).UtcDateTime, Messages = (int)msg, HiddenMessages = (int)hiddemMsg }); } return(null); }
/// <summary> /// Synchronously get queue attributes, counter and stats /// </summary> public QueueAttributes GetQueueAttributes(GetQueueAttributesOptions options) { return(GetQueueAttributesAsync(options).ConfigureAwait(false).GetAwaiter().GetResult()); }