コード例 #1
0
ファイル: RsmqCsharp.cs プロジェクト: tontonrally/rsmqCsharp
        // <summary>
        /// Asynchronously sets queue parameters.
        /// </summary>
        public async Task <QueueAttributes> SetQueueAttributesAsync(SetQueueAttributesOptions options)
        {
            if (!options.VisibilityTimer.HasValue && !options.MaxSize.HasValue && !options.Delay.HasValue)
            {
                throw new NoAttributeSuppliedException();
            }

            var validateOptions = new List <string> {
                "QueueName"
            };

            if (options.VisibilityTimer.HasValue)
            {
                validateOptions.Add("VisibilityTimer");
            }
            if (options.MaxSize.HasValue)
            {
                validateOptions.Add("MaxSize");
            }
            if (options.Delay.HasValue)
            {
                validateOptions.Add("Delay");
            }

            Validate(options, validateOptions.ToArray());

            var key = $"{this._options.Namespace}:{options.QueueName}";

            var q = await this.GetQueue(options.QueueName);

            var time = await this.GetServerTime();

            var transaction = RedisClient.CreateTransaction();

            var tasks = new Task[] {
                transaction.HashSetAsync($"{key}:Q", "modified", ((DateTimeOffset)time).ToUnixTimeSeconds())
            };

            if (options.VisibilityTimer.HasValue)
            {
                tasks.Append(transaction.HashSetAsync($"{key}:Q", "vt", options.VisibilityTimer));
            }

            if (options.MaxSize.HasValue)
            {
                tasks.Append(transaction.HashSetAsync($"{key}:Q", "maxsize", options.MaxSize));
            }

            if (options.Delay.HasValue)
            {
                tasks.Append(transaction.HashSetAsync($"{key}:Q", "delay", options.Delay));
            }

            if (await transaction.ExecuteAsync())
            {
                Task.WaitAll(tasks);

                return(await this.GetQueueAttributesAsync(new GetQueueAttributesOptions { QueueName = options.QueueName }));
            }

            return(null);
        }
コード例 #2
0
ファイル: RsmqCsharp.cs プロジェクト: tontonrally/rsmqCsharp
 /// <summary>
 /// Synchronously sets queue parameters.
 /// </summary>
 public QueueAttributes SetQueueAttributes(SetQueueAttributesOptions options)
 {
     return(SetQueueAttributesAsync(options).ConfigureAwait(false).GetAwaiter().GetResult());
 }