using Learun.Cache.Base;
using System;
using System.Collections.Generic;
using System.Configuration;
namespace Learun.Cache.Redis
{
///
/// 版 本 V2018.3.28
/// Copyright (c) 2013-2050 上海力软信息技术有限公司
/// 创建人:力软-系统开发组
/// 日 期:2017.03.06
/// 描 述:定义缓存接口
/// 2018.4.6 bertchen 增加Redis 前缀
///
public class CacheByRedis : ICache
{
#region Key-Value
///
/// 读取缓存
///
/// 键
///
public T Read(string cacheKey, int dbId = 0) where T : class
{
return new RedisCache(dbId, null).StringGet(cacheKey);
}
///
/// 写入缓存
///
/// 对象数据
/// 键
public void Write(string cacheKey, T value, int dbId = 0) where T : class
{
new RedisCache(dbId, null).StringSet(cacheKey, value);
}
///
/// 写入缓存
///
/// 对象数据
/// 键
/// 到期时间
public void Write(string cacheKey, T value, TimeSpan expireTime, int dbId = 0) where T : class
{
new RedisCache(dbId, null).StringSet(cacheKey, value, expireTime);
}
///
/// 移除指定数据缓存
///
/// 键
public void Remove(string cacheKey, int dbId = 0)
{
new RedisCache(dbId, null).KeyDelete(cacheKey);
}
///
/// 移除全部缓存
///
public void RemoveAll(int dbId = 0)
{
new RedisCache().FlushDatabase(dbId);
}
#endregion
#region List
#region 同步方法
///
/// 移除指定ListId的内部List的值
///
///
///
public void ListRemove(string cacheKey, T value, int dbId = 0) where T : class
{
new RedisCache(dbId, null).ListRemove(cacheKey, value);
}
///
/// 获取指定key的List
///
///
///
public List ListRange(string cacheKey, int dbId = 0) where T : class
{
return new RedisCache(dbId, null).ListRange(cacheKey);
}
///
/// 入队
///
///
///
public void ListRightPush(string cacheKey, T value, int dbId = 0) where T : class
{
new RedisCache(dbId, null).ListRightPush(cacheKey, value);
}
///
/// 出队
///
///
///
///
public T ListRightPop(string cacheKey, int dbId = 0) where T : class
{
return new RedisCache(dbId, null).ListRightPop(cacheKey);
}
///
/// 入栈
///
///
///
///
public void ListLeftPush(string cacheKey, T value, int dbId = 0) where T : class
{
new RedisCache(dbId, null).ListLeftPush(cacheKey, value);
}
///
/// 出栈
///
///
///
///
public T ListLeftPop(string cacheKey, int dbId = 0) where T : class
{
return new RedisCache(dbId, null).ListLeftPop(cacheKey);
}
///
/// 获取集合中的数量
///
///
///
public long ListLength(string cacheKey, int dbId = 0)
{
return new RedisCache(dbId, null).ListLength(cacheKey);
}
#endregion 同步方法
#endregion List
}
}