????>??Redis??????????????????
????>??????游??????Get??Set????÷???
????>????RedisCache?????????Redis??Get??Set????
????>????????湤?????÷???

??????????????????????????
????>??Redis??????????????????
????????????????????????????https://github.com/dmajkic/redis/downloads?????????汾???redis-2.4.5-win32-win64??????32λ??64λ???????????????????????64λ??????????????????????????????

??????????????????????????redis-server.exe?????ó???????????redis?????壨??????????????windows?????????????redis??????????windows??????У??????????ι??redis??????????????????redis?????????????????????

?????к?????????????????????redis????????????????6379???????????????????????????redis.conf?????????????????????????????????http://www.shouce.ren/api/view/a/6231
????????????????????????????????64bit????е????У???????64bit????????????Shift?????????????????????"????????????"??????????????????е?cmd???????У??????????????????????????????windows????????????????????????????????????????о??????????????????????????redis-cli.exe -h localhost -p 6379??????????????Ч?????

???????????·???????????

?????????????????????????????????????????????set??get????

??????????????????????redis????????????localhost?????????ip???????????????????????????????????????????
????>??????游??????Get??Set????÷???
???????????????????
????1 public class BaseCache : IDisposable
????2     {
????3         protected string def_ip = string.Empty;
????4         protected int def_port = 0;
????5         protected string def_password = string.Empty;
????6
????7         public BaseCache()
????8         {
????9
????10         }
????11
????12         public virtual void InitCache(string ip = ""?? int port = 0?? string password = "")
????13         {
????14
????15         }
????16
????17         public virtual bool SetCache<T>(string key?? T t?? int timeOutMinute = 10) where T : class??new()
????18         {
????19
????20             return false;
????21         }
????22
????23         public virtual T GetCache<T>(string key) where T : class??new()
????24         {
????25
????26             return default(T);
????27         }
????28
????29         public virtual bool Remove(string key)
????30         {
????31
????32             return false;
????33         }
????34
????35         public virtual bool FlushAll()
????36         {
????37
????38             return false;
????39         }
????40
????41         public virtual bool Any(string key)
????42         {
????43
????44             return false;
????45         }
????46
????47         public virtual void Dispose(bool isfalse)
????48         {
????49
????50             if (isfalse)
????51             {
????52
????53
????54             }
????55         }
????56
????57         //??????
????58         public void Dispose()
????59         {
????60
????61             this.Dispose(true);
????62             //????????
????63             GC.SuppressFinalize(this);
????64         }
????65     }
???????????????????????????????????????????????????????????????????IDisposable??????Dispose()?????????????????????????????public virtual void Dispose(bool isfalse)???????????????????GC.SuppressFinalize(this);?????????????????????????????????????????????????????????
????>????RedisCache?????????Redis??Get??Set????
??????????????????RedisCache??MemcachedCache????????δ????memcache??????????????????BaseCache????дSet??Get???????′???
????1 /// <summary>
????2     /// Redis????
????3     /// </summary>
????4     public class RedisCache : BaseCache
????5     {
????6         public RedisClient redis = null;
????7
????8         public RedisCache()
????9         {
????10
????11             //??????????????????????
????12             def_ip = "172.0.0.1";
????13             def_port = 6379;
????14             def_password = "";
????15         }
????16
????17         #region Redis????
????18
????19         public override void InitCache(string ip = ""?? int port = 0?? string password = "")
????20         {
????21
????22             if (redis == null)
????23             {
????24                 ip = string.IsNullOrEmpty(ip) ? def_ip : ip;
????25                 port = port == 0 ? def_port : port;
????26                 password = string.IsNullOrEmpty(password) ? def_password : password;
????27
????28                 redis = new RedisClient(ip?? port?? password);
????29             }
????30         }
????31
????32         public override bool SetCache<T>(string key?? T t?? int timeOutMinute = 10)
????33         {
????34
????35             var isfalse = false;
????36
????37             try
????38             {
????39                 if (string.IsNullOrEmpty(key)) { return isfalse; }
????40
????41                 InitCache();
????42                 isfalse = redis.Set<T>(key?? t?? TimeSpan.FromMinutes(timeOutMinute));
????43             }
????44             catch (Exception ex)
????45             {
????46             }
????47             finally { this.Dispose(); }
????48             return isfalse;
????49         }
????50
????51         public override T GetCache<T>(string key)
????52         {
????53             var t = default(T);
????54             try
????55             {
????56                 if (string.IsNullOrEmpty(key)) { return t; }
????57
????58                 InitCache();
????59                 t = redis.Get<T>(key);
????60             }
????61             catch (Exception ex)
????62             {
????63             }
????64             finally { this.Dispose(); }
????65             return t;
????66         }
????67
????68         public override bool Remove(string key)
????69         {
????70             var isfalse = false;
????71             try
????72             {
????73                 if (string.IsNullOrEmpty(key)) { return isfalse; }
????74
????75                 InitCache();
????76                 isfalse = redis.Remove(key);
????77             }
????78             catch (Exception ex)
????79             {
????80             }
????81             finally { this.Dispose(); }
????82             return isfalse;
????83         }
????84
????85         public override void Dispose(bool isfalse)
????86         {
????87
????88             if (isfalse && redis != null)
????89             {
????90
????91                 redis.Dispose();
????92                 redis = null;
????93             }
????94         }
????95
????96         #endregion
????97     }
????98
????99
????100     /// <summary>
????101     /// Memcached????
????102     /// </summary>
????103     public class MemcachedCache : BaseCache
????104     {
????105
????106
????107     }
????View Code