■ IDatabase 인터페이스의 KeyExpire 메소드를 사용해 키 제한 시간을 설정하는 방법을 보여준다.
▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
using System; using System.Threading; using StackExchange.Redis; ConnectionMultiplexer multiplexer = ConnectionMultiplexer.Connect("192.168.29.197:6379"); IDatabase database = multiplexer.GetDatabase(); database.StringSet("key1", "value1"); database.StringSet("key2", "value2"); string value1 = (string)database.StringGet("key1"); string value2 = (string)database.StringGet("key2"); Console.WriteLine(value1); Console.WriteLine(value2); database.KeyExpire("key1", TimeSpan.FromSeconds(1), flags : CommandFlags.FireAndForget); database.KeyExpire("key2", TimeSpan.FromSeconds(1), flags : CommandFlags.FireAndForget); Thread.Sleep(5000); value1 = (string)database.StringGet("key1"); value2 = (string)database.StringGet("key2"); Console.WriteLine(value1); Console.WriteLine(value2); |