Example #1
0
 private void UpdateSessionState(IRedisClient client, string key, RedisSessionState state)
 {
     using (var tran = client.BeginTransaction())
     {
         tran.On(tran.HMSet(key, state), r => r.ThrowIfFailded());
         tran.Expire(key, TimeSpan.FromMinutes(state.Timeout));
         tran.Commit();
     }
 }
Example #2
0
        /// <summary>
        /// 使用当前请求中的值更新会话状态数据存储区中的会话项信息,并清除对数据的锁定。
        /// </summary>
        /// <param name="context">当前请求的 <see cref="System.Web.HttpContext"/>。</param>
        /// <param name="id">当前请求的会话标识符。</param>
        /// <param name="item">包含要存储的当前会话值的 <see cref="System.Web.SessionState.SessionStateStoreData"/> 对象。</param>
        /// <param name="lockId">当前请求的锁定标识符。</param>
        /// <param name="newItem">如果为 true,则将会话项标识为新项;如果为 false,则将会话项标识为现有的项。</param>
        public override void SetAndReleaseItemExclusive(HttpContext context, string id, SessionStateStoreData item, object lockId, bool newItem)
        {
            this._redisManager.AcquireRelease(client =>
            {
                if (newItem)
                {
                    var state = new RedisSessionState()
                    {
                        Items   = (SessionStateItemCollection)item.Items,
                        Timeout = item.Timeout,
                    };

                    var key = GetRedisKey(id);
                    this.UpdateSessionState(client, key, state);
                }
                else
                {
                    this.UpdateSessionStateIfLocked(client, id, (int)lockId, item.Items, item.Timeout);
                }
            });
        }
Example #3
0
 private void UpdateItem(IRedisClient client, string key, RedisSessionState state)
 {
     client.HMSet(key, state);
 }
        /// <summary>
        /// 使用当前请求中的值更新会话状态数据存储区中的会话项信息,并清除对数据的锁定。
        /// </summary>
        /// <param name="context">当前请求的 <see cref="HttpContext"/>。</param>
        /// <param name="id">当前请求的会话标识符。</param>
        /// <param name="item">包含要存储的当前会话值的 <see cref="SessionStateStoreData"/> 对象。</param>
        /// <param name="lockId">当前请求的锁定标识符。</param>
        /// <param name="newItem">如果为 true,则将会话项标识为新项;如果为 false,则将会话项标识为现有的项。</param>
        public override void SetAndReleaseItemExclusive(HttpContext context, string id, SessionStateStoreData item, object lockId, bool newItem)
        {
            this._redisManager.AcquireRelease(client =>
            {
                if(newItem)
                {
                    var state = new RedisSessionState()
                    {
                        Items = (SessionStateItemCollection)item.Items,
                        Timeout = item.Timeout,
                    };

                    var key = GetRedisKey(id);
                    this.UpdateSessionState(client, key, state);
                }
                else
                {
                    this.UpdateSessionStateIfLocked(client, id, (int)lockId, item.Items, item.Timeout);
                }
            });
        }
 private void UpdateSessionState(IRedisClient client, string key, RedisSessionState state)
 {
     using(var tran = client.BeginTransaction())
     {
         tran.On(tran.HMSet(key, state), r => r.ThrowIfFailded());
         tran.Expire(key, TimeSpan.FromMinutes(state.Timeout));
         tran.Commit();
     }
 }
 private void UpdateItem(IRedisClient client, string key, RedisSessionState state)
 {
     client.HMSet(key, state);
 }
 public static void SetSessionState(this IRedisClient redis, string key, RedisSessionState state)
 {
     redis.HMSet(key, state);
 }