示例#1
0
        protected bool SetInternal(string key, object value, TimeSpan expireTime, bool async = false)
        {
            bool result        = false;
            var  data          = (RedisValue)StateBinarySerializer.Serialize(value);
            var  redisDatabase = GetRedisDatabase();

            if (async)
            {
                redisDatabase.StringSetAsync(key, data, expireTime);
            }
            else
            {
                result = redisDatabase.StringSet(key, data, expireTime);
            }
            return(result);
        }
示例#2
0
        protected object GetInternal(string key, bool slide = true, bool slideAsync = true, bool preferSlave = true)
        {
            var redisDatabase = GetRedisDatabase();
            var flag          = CommandFlags.None;

            if (preferSlave)
            {
                flag = CommandFlags.PreferSlave;
            }
            var data   = redisDatabase.StringGet(key, flag);
            var result = StateBinarySerializer.Deserialize(data);

            if (slide)
            {
                var expire = UnlockedExtensions.GetNextTimeout(configuration.SessionTimeout);
                var prefix = GetSessionItemPrefix();
                SlideInternal(prefix, expire, slideAsync);
            }
            return(result);
        }