if (OpenPooledRedis)
{
prcm = CreateManager(new string[] { "127.0.0.1:6379" }, new string[] { "127.0.0.1:6379" });
Redis = prcm.GetClient() as RedisClient;
}
}
/// <summary>
/// 距离过期时间还有多少秒
/// </summary>
/// <param></param>
/// <returns></returns>
public long TTL(string key)
{
return Redis.Ttl(key);
}
/// <summary>
/// 设置过期时间
/// </summary>
/// <param></param>
/// <param></param>
public void Expire(string key,int timeout = 0)
{
if (timeout >= 0)
{
if (timeout > 0)
{
secondsTimeOut = timeout;
}
Redis.Expire(key, secondsTimeOut);
}
}
#region Key/Value存储
/// <summary>
/// 设置缓存
/// </summary>
/// <typeparam></typeparam>
/// <param>缓存建</param>
/// <param>缓存值</param>
/// <param>过期时间,单位秒,-1:不过期,0:默认过期时间</param>
/// <returns></returns>
public bool Set<T>(string key, T t, int timeout = 0)
{
Redis.Set<T>(key, t);
if (timeout >= 0)
{
if (timeout > 0)
{
secondsTimeOut = timeout;
}
Redis.Expire(key, secondsTimeOut);
}
return true;
}
/// <summary>
/// 获取
/// </summary>
/// <typeparam></typeparam>
/// <param></param>
/// <returns></returns>
public T Get<T>(string key)
{
return Redis.Get<T>(key);
}
/// <summary>
/// 删除
/// </summary>
/// <param></param>
/// <returns></returns>
public bool Remove(string key)
{
return Redis.Remove(key);
}
#endregion