Ejemplo n.º 1
0
        protected RedisMessage(int db, RedisLiteral command)
        {
            bool isDbFree = false;

            for (int i = 0; i < dbFree.Length; i++)
            {
                if (dbFree[i] == command)
                {
                    isDbFree = true;
                    break;
                }
            }
            if (isDbFree)
            {
                if (db >= 0)
                {
                    throw new ArgumentOutOfRangeException("db", "A db is not required for " + command);
                }
            }
            else
            {
                if (db < 0)
                {
                    throw new ArgumentOutOfRangeException("db", "A db must be specified for " + command);
                }
            }
            this.db      = db;
            this.command = command;
        }
Ejemplo n.º 2
0
 public RedisMessageTri(int db, RedisLiteral command, RedisParameter arg0, RedisParameter arg1, RedisParameter arg2)
     : base(db, command)
 {
     this.arg0 = arg0;
     this.arg1 = arg1;
     this.arg2 = arg2;
 }
Ejemplo n.º 3
0
        public static RedisMessage Create(int db, RedisLiteral command, params RedisParameter[] args)
        {
            if (args == null)
            {
                return(new RedisMessageNix(db, command));
            }
            switch (args.Length)
            {
            case 0:
                return(new RedisMessageNix(db, command));

            case 1:
                return(new RedisMessageUni(db, command, args[0]));

            case 2:
                return(new RedisMessageBi(db, command, args[0], args[1]));

            case 3:
                return(new RedisMessageTri(db, command, args[0], args[1], args[2]));

            case 4:
                return(new RedisMessageQuad(db, command, args[0], args[1], args[2], args[3]));

            default:
                return(new RedisMessageMulti(db, command, args));
            }
        }
Ejemplo n.º 4
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));
            }
        }
Ejemplo n.º 5
0
 public ScanIterator(RedisConnection connection, int db, RedisLiteral command, string key, string pattern)
 {
     this.connection = connection;
     this.db         = db;
     this.pattern    = pattern;
     this.command    = command;
     this.key        = key;
 }
Ejemplo n.º 6
0
 public RedisMessageQuad(int db, RedisLiteral command, RedisParameter arg0, RedisParameter arg1, RedisParameter arg2, RedisParameter arg3)
     : base(db, command)
 {
     this.arg0 = arg0;
     this.arg1 = arg1;
     this.arg2 = arg2;
     this.arg3 = arg3;
 }
Ejemplo n.º 7
0
 public RedisMessageUniString(int db, RedisLiteral command, string arg0)
     : base(db, command)
 {
     if (arg0 == null)
     {
         throw new ArgumentNullException("arg0");
     }
     this.arg0 = arg0;
 }
Ejemplo n.º 8
0
        Task <string> IStringCommands.GetString(int db, string key, int start, int end, bool queueJump)
        {
            var          features = this.Features;
            RedisLiteral cmd      = features != null && features.Version < RedisFeatures.v2_1_0
                                   ? RedisLiteral.SUBSTR
                                   : RedisLiteral.GETRANGE;

            return(ExecuteString(RedisMessage.Create(db, cmd, key, start, end), queueJump));
        }
Ejemplo n.º 9
0
        private Task <long> ExecMultiAddRemove(int db, RedisLiteral command, string key, string[] values, bool queueJump)
        {
            RedisFeatures features;

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

                ISetCommands sets = tran.Sets;
                for (int i = 0; i < values.Length; i++)
                {
                    tasks[i] = ExecuteBoolean(RedisMessage.Create(db, command, key, values[i]), queueJump);
                }
                var final = new TaskCompletionSource <long>();
                tasks[values.Length - 1].ContinueWith(t =>
                {
                    if (t.IsFaulted)
                    {
                        final.SetException(t.Exception);
                    }
                    try
                    {
                        long count = 0;
                        for (int i = 0; i < tasks.Length; i++)
                        {
                            if (tran.Wait(tasks[i]))
                            {
                                count++;
                            }
                        }
                        final.SetResult(count);
                    }
                    catch (Exception ex)
                    {
                        final.SetException(ex);
                    }
                });
                if (execute)
                {
                    tran.Execute(queueJump);
                }
                return(final.Task);
            }
            else
            {
                return(ExecuteInt64(RedisMessage.Create(db, command, key, values), queueJump));
            }
        }
Ejemplo n.º 10
0
        static RedisMessage GetBlockingPop(int db, RedisLiteral command, string[] keys, int timeoutSeconds)
        {
            var args = new RedisMessage.RedisParameter[keys.Length + 1];

            for (int i = 0; i < keys.Length; i++)
            {
                args[i] = keys[i];
            }
            args[keys.Length] = timeoutSeconds;
            return(RedisMessage.Create(db, command, args));
        }
Ejemplo n.º 11
0
 public RedisMessage Expect(RedisLiteral result)
 {
     if (expected == RedisLiteral.None)
     {
         expected = result;
     }
     else
     {
         throw new InvalidOperationException();
     }
     return(this);
 }
Ejemplo n.º 12
0
 public RedisMessageSub(RedisLiteral command, string[] keys)
     : base(-1, command)
 {
     if (keys == null)
     {
         throw new ArgumentNullException("keys");
     }
     if (keys.Length == 0)
     {
         throw new ArgumentException("keys cannot be empty", "keys");
     }
     this.keys             = keys;
     this.remainingReplies = keys.Length;
 }
Ejemplo n.º 13
0
        public static RedisMessage Create(int db, RedisLiteral command, string arg0, string[] args)
        {
            if (args == null)
            {
                return(Create(db, command, arg0));
            }
            switch (args.Length)
            {
            case 0:
                return(Create(db, command, arg0));

            case 1:
                return(Create(db, command, arg0, args[0]));

            default:
                return(new RedisMessageMultiString(db, command, arg0, args));
            }
        }
Ejemplo n.º 14
0
        private Task <long> BitOp(int db, RedisLiteral operation, string destination, string[] keys, bool queueJump)
        {
            if (keys == null)
            {
                throw new ArgumentNullException("keys");
            }
            if (keys.Length == 0)
            {
                throw new ArgumentException("keys");
            }
            var args = new RedisMessage.RedisParameter[keys.Length + 2];

            args[0] = operation;
            args[1] = destination;
            for (int i = 0; i < keys.Length; i++)
            {
                args[i + 2] = keys[i];
            }
            return(ExecuteInt64(RedisMessage.Create(db, RedisLiteral.BITOP, args), queueJump));
        }
Ejemplo n.º 15
0
 public RedisMessageMultiString(int db, RedisLiteral command, string arg0, string[] args)
     : base(db, command)
 {
     if (arg0 == null)
     {
         throw new ArgumentNullException("arg0");
     }
     if (args == null)
     {
         throw new ArgumentNullException("args");
     }
     for (int i = 0; i < args.Length; i++)
     {
         if (args[i] == null)
         {
             throw new ArgumentNullException("args:" + i);
         }
     }
     this.arg0 = arg0;
     this.args = args;
 }
Ejemplo n.º 16
0
 protected static void WriteUnified(Stream stream, RedisLiteral value)
 {
     WriteUnified(stream, literals[(int)value]);
 }
Ejemplo n.º 17
0
 public static RedisMessage Create(int db, RedisLiteral command, RedisParameter arg0, RedisParameter arg1,
                                   RedisParameter arg2, RedisParameter arg3)
 {
     return(new RedisMessageQuad(db, command, arg0, arg1, arg2, arg3));
 }
Ejemplo n.º 18
0
 public static RedisMessage Create(int db, RedisLiteral command)
 {
     return(new RedisMessageNix(db, command));
 }
Ejemplo n.º 19
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);
            }
        }
Ejemplo n.º 20
0
 internal static RedisMessage CreateMultiSub(RedisLiteral redisLiteral, string[] keys)
 {
     return(keys.Length == 1 ? Create(-1, redisLiteral, keys[0])
         : new RedisMessageSub(redisLiteral, keys));
 }
Ejemplo n.º 21
0
 public RedisMessageUni(int db, RedisLiteral command, RedisParameter arg0)
     : base(db, command)
 {
     this.arg0 = arg0;
 }
Ejemplo n.º 22
0
 public RedisMessageTri(int db, RedisLiteral command, RedisParameter arg0, RedisParameter arg1, RedisParameter arg2)
     : base(db, command)
 {
     this.arg0 = arg0;
     this.arg1 = arg1;
     this.arg2 = arg2;
 }
Ejemplo n.º 23
0
 public RedisMessageSub(RedisLiteral command, string[] keys)
     : base(-1, command)
 {
     if (keys == null) throw new ArgumentNullException("keys");
     if (keys.Length == 0) throw new ArgumentException("keys cannot be empty", "keys");
     this.keys = keys;
     this.remainingReplies = keys.Length;
 }
Ejemplo n.º 24
0
 public RedisMessageQuad(int db, RedisLiteral command, RedisParameter arg0, RedisParameter arg1, RedisParameter arg2, RedisParameter arg3)
     : base(db, command)
 {
     this.arg0 = arg0;
     this.arg1 = arg1;
     this.arg2 = arg2;
     this.arg3 = arg3;
 }
Ejemplo n.º 25
0
 public RedisMessageNix(int db, RedisLiteral command)
     : base(db, command)
 {
 }
Ejemplo n.º 26
0
 public RedisMessageMultiString(int db, RedisLiteral command, string arg0, string[] args)
     : base(db, command)
 {
     if (arg0 == null) throw new ArgumentNullException("arg0");
     if (args == null) throw new ArgumentNullException("args");
     for (int i = 0; i < args.Length; i++)
     {
         if (args[i] == null) throw new ArgumentNullException("args:" + i);
     }
     this.arg0 = arg0;
     this.args = args;
 }
Ejemplo n.º 27
0
 public RedisMessageNix(int db, RedisLiteral command)
     : base(db, command)
 {
 }
Ejemplo n.º 28
0
 private Task<long> BitOp(int db, RedisLiteral operation, string destination, string[] keys, bool queueJump)
 {
     if (keys == null) throw new ArgumentNullException("keys");
     if (keys.Length == 0) throw new ArgumentException("keys");
     var args = new RedisMessage.RedisParameter[keys.Length + 2];
     args[0] = operation;
     args[1] = destination;
     for (int i = 0; i < keys.Length; i++)
     {
         args[i + 2] = keys[i];
     }
     return ExecuteInt64(RedisMessage.Create(db, RedisLiteral.BITOP, args), queueJump);
 }
Ejemplo n.º 29
0
 public RedisMessageUniString(int db, RedisLiteral command, string arg0)
     : base(db, command)
 {
     if (arg0 == null) throw new ArgumentNullException("arg0");
     this.arg0 = arg0;
 }
Ejemplo n.º 30
0
 public RedisMessageMulti(int db, RedisLiteral command, RedisParameter[] args)
     : base(db, command)
 {
     this.args = args;
 }
Ejemplo n.º 31
0
 protected RedisMessage(int db, RedisLiteral command)
 {
     bool isDbFree = false;
     for (int i = 0; i < dbFree.Length; i++)
     {
         if (dbFree[i] == command)
         {
             isDbFree = true;
             break;
         }
     }
     if (isDbFree)
     {
         if (db >= 0) throw new ArgumentOutOfRangeException("db", "A db is not required for " + command);
     }
     else
     {
         if (db < 0) throw new ArgumentOutOfRangeException("db", "A db must be specified for " + command);
     }
     this.db = db;
     this.command = command;
 }
Ejemplo n.º 32
0
 public RedisMessageBiString(int db, RedisLiteral command, string arg0, string arg1)
     : base(db, command)
 {
     this.arg0 = arg0;
     this.arg1 = arg1;
 }
Ejemplo n.º 33
0
 public static RedisMessage Create(int db, RedisLiteral command)
 {
     return new RedisMessageNix(db, command);
 }
Ejemplo n.º 34
0
 public static RedisMessage Create(int db, RedisLiteral command, string arg0, string arg1)
 {
     return(new RedisMessageBiString(db, command, arg0, arg1));
 }
Ejemplo n.º 35
0
 public static RedisMessage Create(int db, RedisLiteral command, string arg0, string arg1)
 {
     return new RedisMessageBiString(db, command, arg0, arg1);
 }
Ejemplo n.º 36
0
 public static RedisMessage Create(int db, RedisLiteral command, RedisParameter arg0, RedisParameter arg1)
 {
     return(new RedisMessageBi(db, command, arg0, arg1));
 }
Ejemplo n.º 37
0
        private Task<long> ExecMultiAddRemove(int db, RedisLiteral command, string key, string[] 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];

                var sets = tran.Sets;
                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 =>
                {
                    if (t.IsFaulted) final.SetException(t.Exception);
                    try
                    {
                        long count = 0;
                        for (int i = 0; i < tasks.Length; i++)
                        {
                            if (tran.Wait(tasks[i]))
                            {
                                count++;
                            }
                        }
                        final.SetResult(count);
                    }
                    catch (Exception ex)
                    {
                        final.SetException(ex);
                    }
                });
                if (execute) tran.Execute(queueJump);
                return final.Task;
            }
            else
            {
                return ExecuteInt64(RedisMessage.Create(db, command, key, values), queueJump);
            }
        }
Ejemplo n.º 38
0
 public RedisMessageUniString(int db, RedisLiteral command, string arg0)
     : base(db, command)
 {
     this.arg0 = arg0;
 }
Ejemplo n.º 39
0
 public static RedisMessage Create(int db, RedisLiteral command, RedisParameter arg0, RedisParameter arg1, RedisParameter arg2, RedisParameter arg3)
 {
     return new RedisMessageQuad(db, command, arg0, arg1, arg2, arg3);
 }
Ejemplo n.º 40
0
 public RedisMessageMulti(int db, RedisLiteral command, RedisParameter[] args)
     : base(db, command)
 {
     this.args = args;
 }
Ejemplo n.º 41
0
 public static RedisMessage Create(int db, RedisLiteral command, params RedisParameter[] args)
 {
     if (args == null) return new RedisMessageNix(db, command);
     switch (args.Length)
     {
         case 0: return new RedisMessageNix(db, command);
         case 1: return new RedisMessageUni(db, command, args[0]);
         case 2: return new RedisMessageBi(db, command, args[0], args[1]);
         case 3: return new RedisMessageTri(db, command, args[0], args[1], args[2]);
         case 4: return new RedisMessageQuad(db, command, args[0], args[1], args[2], args[3]);
         default: return new RedisMessageMulti(db, command, args);
     }
 }
Ejemplo n.º 42
0
 public RedisMessageMultiString(int db, RedisLiteral command, string arg0, string[] args)
     : base(db, command)
 {
     this.arg0 = arg0;
     this.args = args;
 }
Ejemplo n.º 43
0
 public RedisMessage Expect(RedisLiteral result)
 {
     if (expected == RedisLiteral.None)
     {
         expected = result;
     }
     else
     {
         throw new InvalidOperationException();
     }
     return this;
 }
Ejemplo n.º 44
0
 public RedisMessageUni(int db, RedisLiteral command, RedisParameter arg0)
     : base(db, command)
 {
     this.arg0 = arg0;
 }
Ejemplo n.º 45
0
 internal static RedisMessage CreateMultiSub(RedisLiteral redisLiteral, string[] keys)
 {
     return keys.Length == 1 ? Create(-1, redisLiteral, keys[0])
         : new RedisMessageSub(redisLiteral, keys);
 }
Ejemplo n.º 46
0
 public RedisLiteralParameter(RedisLiteral value)
 {
     this.value = value;
 }
Ejemplo n.º 47
0
 protected static void WriteUnified(Stream stream, RedisLiteral value)
 {
     WriteUnified(stream, literals[(int)value]);
 }
Ejemplo n.º 48
0
 public static RedisMessage Create(int db, RedisLiteral command, string arg0, string[] args)
 {
     if (args == null) return Create(db, command, arg0);
     switch (args.Length)
     {
         case 0:
             return Create(db, command, arg0);
         case 1:
             return Create(db, command, arg0, args[0]);
         default:
             return new RedisMessageMultiString(db, command, arg0, args);
     }
 }
Ejemplo n.º 49
0
 public RedisLiteralParameter(RedisLiteral value)
 {
     this.value = value;
 }
Ejemplo n.º 50
0
 static RedisMessage GetBlockingPop(int db, RedisLiteral command, string[] keys, int timeoutSeconds)
 {
     var args = new RedisMessage.RedisParameter[keys.Length + 1];
     for (int i = 0; i < keys.Length; i++)
         args[i] = keys[i];
     args[keys.Length] = timeoutSeconds;
     return RedisMessage.Create(db, command, args);
 }
Ejemplo n.º 51
0
 public static RedisMessage Create(int db, RedisLiteral command, RedisParameter arg0, RedisParameter arg1)
 {
     return new RedisMessageBi(db, command, arg0, arg1);
 }