Exemplo n.º 1
0
 internal static InstanceState ReadOnly(ConnectionMultiplexer Redis, InstanceDescriptor instanceDescriptor)
 {
     string lockId;
     return Read(Redis, instanceDescriptor, false, out lockId);
 }
Exemplo n.º 2
0
 internal static InstanceState LockAndRead(ConnectionMultiplexer Redis, InstanceDescriptor instanceDescriptor, out string lockId)
 {
     return Read(Redis, instanceDescriptor, true, out lockId);
 }
Exemplo n.º 3
0
 public void Read (TProtocol iprot)
 {
   iprot.IncrementRecursionDepth();
   try
   {
     TField field;
     iprot.ReadStructBegin();
     while (true)
     {
       field = iprot.ReadFieldBegin();
       if (field.Type == TType.Stop) { 
         break;
       }
       switch (field.ID)
       {
         case 1:
           if (field.Type == TType.Struct) {
             Instance = new InstanceDescriptor();
             Instance.Read(iprot);
           } else { 
             TProtocolUtil.Skip(iprot, field.Type);
           }
           break;
         case 2:
           if (field.Type == TType.I32) {
             OpCode = (Operation)iprot.ReadI32();
           } else { 
             TProtocolUtil.Skip(iprot, field.Type);
           }
           break;
         case 3:
           if (field.Type == TType.Struct) {
             Input = new InputData();
             Input.Read(iprot);
           } else { 
             TProtocolUtil.Skip(iprot, field.Type);
           }
           break;
         default: 
           TProtocolUtil.Skip(iprot, field.Type);
           break;
       }
       iprot.ReadFieldEnd();
     }
     iprot.ReadStructEnd();
   }
   finally
   {
     iprot.DecrementRecursionDepth();
   }
 }
Exemplo n.º 4
0
        private static InstanceState Read(ConnectionMultiplexer Redis, InstanceDescriptor instanceDescriptor, bool forChange, out string lockId)
        {
            var db = Redis.GetDatabase();
            RedisKey keyLock = Tools.MakeLockKey(instanceDescriptor.Id);
            RedisKey keyData = Tools.MakeDataKey(instanceDescriptor.Id);

            lockId = String.Empty;
            if (forChange)
            {
                while (!LockSession(db, instanceDescriptor.Id, LOCK_TTL_MSEC, out lockId))
                {
                    Console.Write(instanceDescriptor.Id);  // waiting for this lock
                    Thread.Sleep(0);
                }
            }

            if (db.KeyExists(keyData))
            {
                RedisValue data = db.StringGet(keyData);
                return Tools.DeSerialize<InstanceState>((byte[])data);
            }
            else
            {
                return new InstanceState()
                {
                    Id = instanceDescriptor.Id,
                    LastResult = 0,
                    Revision = 0
                };
            }
        }
Exemplo n.º 5
0
        public void Read(TProtocol iprot)
        {
            iprot.IncrementRecursionDepth();
            try
            {
                TField field;
                iprot.ReadStructBegin();
                while (true)
                {
                    field = iprot.ReadFieldBegin();
                    if (field.Type == TType.Stop)
                    {
                        break;
                    }
                    switch (field.ID)
                    {
                    case 1:
                        if (field.Type == TType.Struct)
                        {
                            Instance = new InstanceDescriptor();
                            Instance.Read(iprot);
                        }
                        else
                        {
                            TProtocolUtil.Skip(iprot, field.Type);
                        }
                        break;

                    case 2:
                        if (field.Type == TType.I32)
                        {
                            OpCode = (Operation)iprot.ReadI32();
                        }
                        else
                        {
                            TProtocolUtil.Skip(iprot, field.Type);
                        }
                        break;

                    case 3:
                        if (field.Type == TType.Struct)
                        {
                            Input = new InputData();
                            Input.Read(iprot);
                        }
                        else
                        {
                            TProtocolUtil.Skip(iprot, field.Type);
                        }
                        break;

                    default:
                        TProtocolUtil.Skip(iprot, field.Type);
                        break;
                    }
                    iprot.ReadFieldEnd();
                }
                iprot.ReadStructEnd();
            }
            finally
            {
                iprot.DecrementRecursionDepth();
            }
        }