using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using CSRedis;
namespace BLWWS.PMS.Common
{
///
/// Redis缓存辅助类
///
public class CSRedisCacheHelper
{
public static CSRedisClient redis;
private static int SessionExpireMinutes = 60 * 24 * 60;
public static string pwd = ConfigurationManager.AppSettings["redis_pwd"];
static CSRedisCacheHelper()
{
//var redisHostStr = "127.0.0.1:7555,poolsize=20";
var redisHostStr = "127.0.0.1:6379,poolsize=20";
if (!string.IsNullOrEmpty(redisHostStr))
{
//redis = new CSRedisClient(redisHostStr + ",password=cw_oy_lsh,defaultDatabase=1");
string str = string.Format(",password={0},defaultDatabase=1", pwd);
redis = new CSRedisClient(redisHostStr + str);
}
}
///
/// 添加缓存
///
///
///
///
public static void Set(string key, T value)
{
redis.Set(key, value, SessionExpireMinutes * 60);
}
public static T Get(string key)
{
return redis.Get(key);
}
public static void Forever(string key, T value)
{
redis.Set(key, value, -1);
}
public static void Del(string key)
{
redis.Del(key);
}
///
/// 判断是否存在
///
///
///
///
public static bool Contains(string key, string mac)
{
bool result = redis.Exists(mac);
if (!result)
{
result = redis.Exists(key);
}
return result;
}
public static bool Contains(string key)
{
bool result = redis.Exists(key);
return result;
}
///
/// 添加Hash缓存
///
///
///
///
public static void HMSet(string key, T value)
{
redis.HMSet(key, value);
}
///
/// 获取Hash缓存
///
///
///
///
public static T[] HMGet(string key)
{
return redis.HMGet(key);
}
///
/// 删除Hash缓存
///
///
///
///
public static long HDel(string key)
{
return redis.HDel(key);
}
}
}