經過NuGet管理控制檯輸入github
Install-Package StackExchange.Redis或
Install-Package StackExchange.Redis.StrongNameredis
下載地址數據庫
經常使用命令windows
更多命令參考redis doc數據結構
獲取鏈接對象異步
/// <summary> /// 延時加載主 /// </summary> private static Lazy<ConnectionMultiplexer> lazyMaster = new Lazy<ConnectionMultiplexer>(() => { return ConnectionMultiplexer.Connect(ConfigurationManager.AppSettings["MasterRedis"]); }); /// <summary> /// 主寫 /// </summary> public static ConnectionMultiplexer writeConn { get { return lazyMaster.Value; } }
操做redisasync
/// <summary> /// 設置鍵值 /// </summary> /// <param name="key">鍵</param> /// <param name="value">值</param> /// <param name="db">數據庫編號</param> /// <param name="ts">過時時間</param> /// <param name="conn">鏈接器</param> /// <returns></returns> public static async Task<bool> Set(string key, string value, int db = 0, TimeSpan? ts = null, ConnectionMultiplexer conn = null) { return await GetWriteDb(db, conn).StringSetAsync(key, value, ts); }
github地址性能