/// <summary>
        /// Gets a hash from Redis and passes it to the constructor of RedisSessionStateItemCollection
        /// </summary>
        /// <param name="redisKey">The key of the Redis hash</param>
        /// <param name="context">The HttpContext of the current web request</param>
        /// <returns>An instance of RedisSessionStateItemCollection, may be empty if Redis call fails</returns>
        public static RedisSessionStateItemCollection GetItemFromRedis(
            string redisKey,
            HttpContextBase context,
            TimeSpan expirationTimeout)
        {
            RedisConnectionWrapper rConnWrap = RedisSessionStateStoreProvider.RedisConnWrapperFromContext(
                context);

            IDatabase redisConn = rConnWrap.GetConnection();

            try
            {
                HashEntry[] redisData = redisConn.HashGetAll(redisKey);

                redisConn.KeyExpire(redisKey, expirationTimeout, CommandFlags.FireAndForget);

                return(new RedisSessionStateItemCollection(
                           redisData,
                           rConnWrap.ConnectionID,
                           0));
            }
            catch (Exception e)
            {
                if (RedisSessionConfig.SessionExceptionLoggingDel != null)
                {
                    RedisSessionConfig.SessionExceptionLoggingDel(e);
                }
            }

            return(new RedisSessionStateItemCollection());
        }
        /// <summary>
        /// Deletes an entire Session from Redis by removing the key.
        /// </summary>
        /// <param name="context">The HttpContext of the current request</param>
        /// <param name="id">The Session Id</param>
        /// <param name="lockId">The object used to lock the Session</param>
        /// <param name="item">The Session's properties</param>
        public override void RemoveItem(HttpContext context, string id, object lockId, SessionStateStoreData item)
        {
            RedisConnectionWrapper rConnWrap = RedisSessionStateStoreProvider.RedisConnWrapperFromContext(
                new HttpContextWrapper(context));

            IDatabase redisConn = rConnWrap.GetConnection();

            redisConn.KeyDelete(
                RedisSessionStateStoreProvider.RedisHashIdFromSessionId(
                    new HttpContextWrapper(context),
                    id),
                CommandFlags.FireAndForget);
        }
        /// <summary>
        /// Helper method for serializing objects to Redis
        /// </summary>
        /// <param name="confirmedChangedObjects">keys and values that have definitely changed</param>
        /// <param name="allObjects">keys and values that have been accessed during the current HttpContext</param>
        /// <param name="allObjectsOriginalState">keys and serialized values before we tampered with them</param>
        /// <param name="deletedObjects">keys that were deleted during the current HttpContext</param>
        /// <param name="currentRedisHashId">The current Redis key name</param>
        /// <param name="redisConn">A connection to Redis</param>
        public static void SerializeToRedis(
            HttpContextBase context,
            RedisSessionStateItemCollection redisItems,
            string currentRedisHashId,
            TimeSpan expirationTimeout)
        {
            List <HashEntry>  setItems = new List <HashEntry>();
            List <RedisValue> delItems = new List <RedisValue>();

            RedisConnectionWrapper rConnWrap = RedisSessionStateStoreProvider.RedisConnWrapperFromContext(
                context);

            foreach (KeyValuePair <string, string> changedObj in
                     redisItems.GetChangedObjectsEnumerator())
            {
                if (changedObj.Value != null)
                {
                    setItems.Add(
                        new HashEntry(
                            changedObj.Key,
                            changedObj.Value));
                }
                else
                {
                    delItems.Add(changedObj.Key);
                }
            }

            IDatabase redisConn = rConnWrap.GetConnection();

            redisConn.KeyExpire(
                currentRedisHashId,
                expirationTimeout,
                CommandFlags.FireAndForget);

            if (setItems.Count > 0)
            {
                redisConn.HashSet(
                    currentRedisHashId,
                    setItems.ToArray(),
                    CommandFlags.FireAndForget);
            }
            if (delItems != null && delItems.Count > 0)
            {
                redisConn.HashDelete(
                    currentRedisHashId,
                    delItems.ToArray(),
                    CommandFlags.FireAndForget);
            }
        }