Exemple #1
0
 /// <summary>
 /// Execute pipeline commands
 /// </summary>
 /// <returns>Array of batched command results</returns>
 public object[] EndPipe()
 {
     if (_transaction.Active)
         return _transaction.Execute();
     else
         return _connector.EndPipe();
 }
Exemple #2
0
 /// <summary>
 /// Execute pipeline commands
 /// </summary>
 /// <returns>Array of batched command results</returns>
 public object[] EndPipe()
 {
     if (_transaction.Active)
     {
         return(_transaction.Execute());
     }
     else
     {
         return(_connector.EndPipe());
     }
 }
Exemple #3
0
        private Task <bool> ExecuteTransaction(RedisTransaction transaction, long?oldId, IList <Message> messages)
        {
            _trace.TraceVerbose("ExecuteTransaction({0})", oldId);

            // New target id
            long newId = (oldId ?? 0) + 1;

            // TODO: Don't do this everytime
            byte[] data = RedisMessage.ToBytes(newId, messages);

            // These don't need to be observed
            transaction.AddCondition(Condition.KeyEquals(_db, _key, oldId));
            transaction.Strings.Increment(_db, _key);
            transaction.Publish(_key, data);

            // Execute the transaction
            return(transaction.Execute());
        }
        public override SessionStateStoreData GetItemExclusive(HttpContext context, string id, out bool locked, out TimeSpan lockAge, out object lockId, out SessionStateActions actions)
        {
            RedisConnection redisConnection = this.GetRedisConnection();
            Task <byte[]>   task1           = redisConnection.Hashes.Get(0, this.lockHashKey, id, false);

            actions = SessionStateActions.None;
            locked  = false;
            lockId  = (object)null;
            lockAge = TimeSpan.MinValue;
            task1.Wait();
            byte[] result1 = task1.Result;
            if (result1 == null)
            {
                RedisSessionStateStore.LockData data = RedisSessionStateStore.LockData.New();
                using (RedisTransaction transaction = redisConnection.CreateTransaction())
                {
                    Task <bool> task2 = transaction.Hashes.SetIfNotExists(0, this.lockHashKey, id, data.ToByteArray(), false);
                    Task <Dictionary <string, byte[]> > all = transaction.Hashes.GetAll(0, this.GetKeyForSessionId(id), false);
                    transaction.Execute(false, (object)null);
                    task2.Wait();
                    if (task2.Result)
                    {
                        locked  = true;
                        lockAge = new TimeSpan(0L);
                        lockId  = (object)data.LockId;
                        SessionStateItemCollection  stateItemCollection = new SessionStateItemCollection();
                        Dictionary <string, byte[]> dictionary          = redisConnection.Wait <Dictionary <string, byte[]> >(all);
                        if (dictionary.Count == 3)
                        {
                            actions = (int)dictionary["initialize"][0] == 1 ? SessionStateActions.InitializeItem : SessionStateActions.None;
                            MemoryStream memoryStream = new MemoryStream(dictionary["data"]);
                            if (memoryStream.Length > 0L)
                            {
                                stateItemCollection = SessionStateItemCollection.Deserialize(new BinaryReader((Stream)memoryStream));
                            }
                            int int32 = BitConverter.ToInt32(dictionary["timeoutMinutes"], 0);
                            redisConnection.Keys.Expire(0, this.GetKeyForSessionId(id), int32 * 60, false);
                        }
                        return(new SessionStateStoreData((ISessionStateItemCollection)stateItemCollection, SessionStateUtility.GetSessionStaticObjects(context), this.redisConfig.SessionTimeout));
                    }
                    byte[] result2 = redisConnection.Hashes.Get(0, this.lockHashKey, id, false).Result;
                    if (result2 != null && RedisSessionStateStore.LockData.TryParse(result2, out data))
                    {
                        locked  = true;
                        lockId  = (object)data.LockId;
                        lockAge = DateTime.UtcNow - data.LockUtcTime;
                    }
                    return((SessionStateStoreData)null);
                }
            }
            else
            {
                RedisSessionStateStore.LockData data;
                if (RedisSessionStateStore.LockData.TryParse(result1, out data))
                {
                    locked  = true;
                    lockId  = (object)data.LockId;
                    lockAge = DateTime.UtcNow - data.LockUtcTime;
                }
                return((SessionStateStoreData)null);
            }
        }