private void _SetCache(string key, object value, TimeSpan?timeout, ExpireType?expireType) { string jsonStr = string.Empty; if (value is string) { jsonStr = value as string; } else { jsonStr = value.ToJson(); } ValueInfoEntry entry = new ValueInfoEntry { Value = jsonStr, TypeName = value.GetType().AssemblyQualifiedName, ExpireTime = timeout, ExpireType = expireType }; string theValue = entry.ToJson(); if (timeout == null) { _redisCLient.Set(key, theValue); } else { _redisCLient.Set(key, theValue, (int)timeout.Value.TotalSeconds); } }
public object GetCache(string key) { object value = null; var redisValue = _redisCLient.Get(key); if (redisValue.IsNullOrEmpty()) { return(null); } ValueInfoEntry valueEntry = redisValue.ToString().ToObject <ValueInfoEntry>(); if (valueEntry.TypeName == typeof(string).AssemblyQualifiedName) { value = valueEntry.Value; } else { value = valueEntry.Value.ToObject(Type.GetType(valueEntry.TypeName)); } if (valueEntry.ExpireTime != null && valueEntry.ExpireType == ExpireType.Relative) { SetKeyExpire(key, valueEntry.ExpireTime.Value); } return(value); }