>筆記1:如果需要調用遠程的Redis,那么您需要2步
步驟1:
在項目的web.config文件中配置
<!-- Cache.Redis連接配置 --> <add key="Cache_Redis_Configuration" value="127.0.0.1:6379" /> <!--Cache.Redis連接配置--> <add key="Cache_Memcached_Configuration" value="Memcached配置" />
步驟2:
1 //先注冊Redis配置,不立即啟用(add) 2 Register.SetConfigurationOption(ConfigHelper.AppSettings("Cache_Redis_Configuration")); 3 4 //如需立即改用某種緩存策略,只需要這樣做(注意:是全局立即生效): 5 CacheStrategyFactory.RegisterObjectCacheStrategy(() => RedisObjectCacheStrategy.Instance); 6 7 var cache = CacheStrategyFactory.GetObjectCacheStrategyInstance(); 8 var count = cache.Get<int>("Hello",true); 9 count++; 10 cache.Set("Hello", count,null,true); 11 12 StringBuilder strRes = new StringBuilder(); 13 strRes.Append("Hello的值為:" + count.ToString() + ","); 14 strRes.Append("CacheType的值為:" + cache.GetType().ToString());
然后就可以隨便玩兒了.
以上親測,有疑問歡迎關注我的微信公眾號進行提問
公眾號:sxmljx