using System;
using System.Configuration;
using Newtonsoft.Json;
using StackExchange.Redis;
namespace BLL
{
///
///
///
public class Redis : ICache
{
int Default_Timeout = 600;//默认超时时间(单位秒)
string address;
JsonSerializerSettings jsonConfig = new JsonSerializerSettings() { ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore, NullValueHandling = NullValueHandling.Ignore };
ConnectionMultiplexer connectionMultiplexer;
IDatabase database;
class CacheObject
{
public int ExpireTime { get; set; }
public bool ForceOutofDate { get; set; }
public T Value { get; set; }
}
///
///
///
///
public Redis(int dbbase = 0)
{
this.address = this.address = ConfigurationManager.AppSettings["RedisHosts"];
if (this.address == null || string.IsNullOrWhiteSpace(this.address.ToString()))
throw new ApplicationException("配置文件中未找到RedisServer的有效配置");
connectionMultiplexer = ConnectionMultiplexer.Connect(address);
database = connectionMultiplexer.GetDatabase(dbbase);
}
///
/// 连接超时设置
///
public int TimeOut
{
get
{
return Default_Timeout;
}
set
{
Default_Timeout = value;
}
}
///
///
///
///
///
public object Get(string key)
{
return Get