Esempio n. 1
0
 protected void _addTrackedKey(String key, TimeSpan?slidingExpiration = null)
 {
     if (slidingExpiration != null)
     {
         long expiresUtc = RedisDataFormatUtil.ToUnixTimestamp(DateTime.UtcNow.Add(slidingExpiration.Value));
         _client.SortedSetAdd(Model.CreateKey(Constants.RootKey, RedisCache.Constants.EphemeralKeysKey), expiresUtc, key);
     }
     else
     {
         _client.SetAdd(Model.CreateKey(Constants.RootKey, RedisCache.Constants.KeysKey), key);
     }
 }
Esempio n. 2
0
        public Boolean ExpireAt(String key, DateTime time)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            var unixTimestamp = RedisDataFormatUtil.ToUnixTimestamp(time);

            _connection.Send(cmd.EXPIREAT, key, unixTimestamp);
            return(_connection.ReadReply().IsSuccess);
        }
Esempio n. 3
0
        public void UpdateSerializedObjectValue <T, F>(T instance, Expression <Func <T, F> > expression, F value)
        {
            if (value == null)
            {
                throw new ArgumentException("Cannot be null.", "value");
            }

            var prefix    = Model.GetKey(instance);
            var memberKey = Model.GetKeyForMemberExpression(expression.Body as MemberExpression);
            var key       = Model.CreateKey(prefix, memberKey);

            Set(key, RedisDataFormatUtil.FormatForStorage(value));
        }
Esempio n. 4
0
        public void SerializeObject(Object instance, String keyPrefix = null, TimeSpan?slidingExpiration = null)
        {
            var type = instance.GetType();

            var instanceKey = Model.GetKey(instance);
            var fullPrefix  = instanceKey;

            if (!String.IsNullOrEmpty(keyPrefix))
            {
                fullPrefix = Model.CreateKey(keyPrefix, instanceKey);
            }

            var members = new Dictionary <Member, Object>();

            ReflectionUtil.MapToDictionary(instance, members);

            foreach (var member in members)
            {
                var fullKey = Model.CreateKey(fullPrefix, member.Key.FullyQualifiedName);

                var value = member.Value;

                if (member.Key.IsBinarySerialized)
                {
                    BinarySerializeObject(fullKey, value);
                    ExpireByTimespan(fullKey, slidingExpiration);
                }
                else
                {
                    if (value != null)
                    {
                        Set(fullKey, RedisDataFormatUtil.FormatForStorage(value));
                        ExpireByTimespan(fullKey, slidingExpiration);
                    }
                }
            }
        }
Esempio n. 5
0
 protected void _purgeExpiredKeysAsync()
 {
     Task.Factory.StartNew(() =>
     {
         try
         {
             using (var rc = new RedisClient(_client.AsRedisHostInfo()))
             {
                 rc.SortedSetRemoveRangeByScore(Model.CreateKey(Constants.RootKey, Constants.EphemeralKeysKey), 0, RedisDataFormatUtil.ToUnixTimestamp(DateTime.UtcNow));
             }
         }
         catch { }
     });
 }
Esempio n. 6
0
 protected void _purgeExpiredKeys()
 {
     _client.SortedSetRemoveRangeByScore(Model.CreateKey(Constants.RootKey, Constants.EphemeralKeysKey), 0, RedisDataFormatUtil.ToUnixTimestamp(DateTime.UtcNow));
 }