redis簡單幫助類

代碼很簡單,根據它的操作自己封裝就好了

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(); 

        }
    }

}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章