代碼很簡單,根據它的操作自己封裝就好了
using ServiceStack.Redis;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace SHB.TOPS.WebApi.FMS.Common
{
public class RedisHelp
{
RedisClient redisClient = null;
public RedisHelp()
{
redisClient = new RedisClient(
ConfirmHelp.GetStringBykey("RedisHost"), //IP
int.Parse(ConfirmHelp.GetStringBykey("RedisPort")), //端口
ConfirmHelp.GetStringBykey("RedisPwd"), 2); //三號庫
}
public bool Set<T>(string key, T obj) where T : class
{
return redisClient.Set(key, obj);
}
public bool Set(string key, string str)
{
return redisClient.Set(key, str, DateTime.Now.AddSeconds(60));
}
public long Del(string key)
{
return redisClient.Del(key);
}
public long Del(params string[] keys)
{
return redisClient.Del(keys);
}
public List<string> GetAllKey()
{
return redisClient.GetAllKeys();
}
}
}