public static async Task <T> ExecuteWithKeyExpire <T>(this RedisStructure redisStructure, Func <IDatabaseAsync, Task <T> > command, RedisKey key, RedisExpiry expiry, CommandFlags commandFlags)
        {
            if (expiry == null)
            {
                return(await command(redisStructure.Command).ForAwait());
            }
            else
            {
                var tx     = redisStructure.CreateTransaction();
                var future = command(tx);
                var expire = expiry.KeyExpire(tx, key, commandFlags);
                await tx.ExecuteAsync(commandFlags).ForAwait();

                return(await future.ForAwait());
            }
        }
Exemple #2
0
        // additional commands

        /// <summary>
        /// Simulate fixed size list includes LPUSH, TRIM.
        /// </summary>
        public Task <long> LeftPushAndFixLength(T value, long fixLength, RedisExpiry expiry = null, When when = When.Always, CommandFlags commandFlags = CommandFlags.None)
        {
            return(TraceHelper.RecordSendAndReceive(Settings, Key, CallType, async() =>
            {
                long sentSize;
                var v = Settings.ValueConverter.Serialize(value, out sentSize);
                var tx = CreateTransaction();
                var leftpush = tx.ListLeftPushAsync(Key, v, when, commandFlags);
                var trim = tx.ListTrimAsync(Key, 0, fixLength - 1, commandFlags);
                if (expiry != null)
                {
                    var expire = expiry.KeyExpire(tx, Key, commandFlags);
                }
                await tx.ExecuteAsync(commandFlags).ForAwait();
                var r = await leftpush.ForAwait();

                return Tracing.CreateSentAndReceived(new { value, fixLength, expiry = expiry?.Value, when }, sentSize, r, sizeof(long));
            }));
        }