使用函式庫: StackExchange.Redis
//設定連線字串 using ( ConnectionMultiplexer conn = ConnectionMultiplexer.Connect("127.0.0.1:10001")) { // 取得操作介面 IDatabase cache = conn.GetDatabase(); RedisKey custKey1 = "Key1"; RedisValue newTest1 = "first"; // 設定Script 字串 string tEval = @"local res = redis.call('get', KEYS[1]) if res == ""value1"" then return ARGV[1] else return res end"; // 設定 custKey1 的值為 "value1" cache.StringSet(custKey1, "value1"); // 呼叫執行Script (Eval) RedisResult tResult = cache.ScriptEvaluate(tEval , new RedisKey[] { custKey1 }, new RedisValue[] { newTest1 }); if (tResult.IsNull == false) { Console.WriteLine(tResult.ToString()); } }
沒有留言:
張貼留言