Redis缓存数据
vs:
using ServiceStack.Redis;
public class RedisHelper
{
private static RedisClient Redis = null;
static RedisHelper()
{
//服务器和端口
Redis = new RedisClient("127.0.0.1", 6379);
}
//存数据
public static int SetData(string key, string data, int hours = 5)
{
if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(data))
{
return 0;
}
else
{
DateTime expiryTime = DateTime.Now.AddHours(hours);
byte[] byteArray = System.Text.Encoding.Default.GetBytes(data);
Redis.Set(key, byteArray, expiryTime);
return 1;
}
}
//取数据
public static string GetData(string key)
{
if (string.IsNullOrEmpty(key))
{
return null;
}
else