如何在 C# 中设置 Redis 哈希键的过期时间?
How to set expiration time for a Redis hash key in C#?
我正在将一个值散列到我的 Redis 中的一个键。
_redis.GetDatabase(0).HashSet("db", "key1" , "value");
我也想给这个key设置30天的过期时间。我没有找到任何方法。
是否有任何可能的方法可以在设置值后立即设置过期时间?
例如,您提供的“db”是 hash-key,而“key1”实际上是 sub-key(参见:https://redis.com/ebook/part-1-getting-started/chapter-1-getting-to-know-redis/1-2-what-redis-data-structures-look-like/1-2-4-hashes-in-redis/)
您不能过期 sub-key 秒(请参阅:Redis: To set timeout for a key value pair in Set)
为了过期hash-key你可以使用:
_redis.GetDatabase(0).KeyExpire("db", TimeSpan.FromDays(30));
我正在将一个值散列到我的 Redis 中的一个键。
_redis.GetDatabase(0).HashSet("db", "key1" , "value");
我也想给这个key设置30天的过期时间。我没有找到任何方法。 是否有任何可能的方法可以在设置值后立即设置过期时间?
例如,您提供的“db”是 hash-key,而“key1”实际上是 sub-key(参见:https://redis.com/ebook/part-1-getting-started/chapter-1-getting-to-know-redis/1-2-what-redis-data-structures-look-like/1-2-4-hashes-in-redis/)
您不能过期 sub-key 秒(请参阅:Redis: To set timeout for a key value pair in Set)
为了过期hash-key你可以使用:
_redis.GetDatabase(0).KeyExpire("db", TimeSpan.FromDays(30));