Exemple #1
0
        private Task <long> ExecMultiAddRemove(int db, RedisLiteral command, string key, byte[][] values, bool queueJump)
        {
            RedisFeatures features;

            if (values.Length > 1 && ((features = Features) == null || !features.SetVaradicAddRemove))
            {
                RedisTransaction tran    = this as RedisTransaction;
                bool             execute = false;
                if (tran == null)
                {
                    tran    = CreateTransaction();
                    execute = true;
                }
                Task <bool>[] tasks = new Task <bool> [values.Length];

                for (int i = 0; i < values.Length; i++)
                {
                    tasks[i] = ExecuteBoolean(RedisMessage.Create(db, command, key, values[i]), queueJump);
                }
                TaskCompletionSource <long> final = new TaskCompletionSource <long>();
                tasks[values.Length - 1].ContinueWith(t =>
                {
                    try
                    {
                        if (t.ShouldSetResult(final))
                        {
                            long count = 0;
                            for (int i = 0; i < tasks.Length; i++)
                            {
                                if (tran.Wait(tasks[i]))
                                {
                                    count++;
                                }
                            }
                            final.TrySetResult(count);
                        }
                    }
                    catch (Exception ex)
                    {
                        final.SafeSetException(ex);
                    }
                });
                if (execute)
                {
                    tran.Execute(queueJump);
                }
                return(final.Task);
            }
            else
            {
                var args = new RedisMessage.RedisParameter[values.Length + 1];
                args[0] = key;
                for (int i = 0; i < values.Length; i++)
                {
                    args[i + 1] = values[i];
                }
                return(ExecuteInt64(RedisMessage.Create(db, command, args), queueJump));
            }
        }
        Task <long> IHashCommands.Remove(int db, string key, string[] fields, bool queueJump)
        {
            RedisFeatures features;

            if (fields.Length > 1 && ((features = Features) == null || !features.HashVaradicDelete))
            {
                RedisTransaction tran    = this as RedisTransaction;
                bool             execute = false;
                if (tran == null)
                {
                    tran    = CreateTransaction();
                    execute = true;
                }
                Task <bool>[] tasks = new Task <bool> [fields.Length];

                var hashes = tran.Hashes;
                for (int i = 0; i < fields.Length; i++)
                {
                    tasks[i] = hashes.Remove(db, key, fields[i], queueJump);
                }
                TaskCompletionSource <long> final = new TaskCompletionSource <long>();
                tasks[fields.Length - 1].ContinueWith(t =>
                {
                    try
                    {
                        if (t.ShouldSetResult(final))
                        {
                            long count = 0;
                            for (int i = 0; i < tasks.Length; i++)
                            {
                                if (tran.Wait(tasks[i]))
                                {
                                    count++;
                                }
                            }
                            final.TrySetResult(count);
                        }
                    }
                    catch (Exception ex)
                    {
                        final.SafeSetException(ex);
                    }
                });
                if (execute)
                {
                    tran.Execute(queueJump);
                }
                return(final.Task);
            }
            else
            {
                return(ExecuteInt64(RedisMessage.Create(db, RedisLiteral.HDEL, key, fields), queueJump));
            }
        }