如何设置 TTL 以在 ServiceStack.Redis 中列出值?
How to set TTL to List Values in ServiceStack.Redis?
我在 ServiceStack.Redis 中有一个列表,我想设置一个 TimeSpan 使其过期。
也就是说,如何在ServiceStack.Redis
中调用下面的redis命令
EXPIRE ListId ttl
我想要的方法是:
client.Lists(listId, timespan);
我的问题有解决办法吗?
借助 IRedisClient 和 IRedisNativeClient 上的新自定义 API 和 RawCommand API,您现在可以使用 RedisClient 发送您自己的自定义命令,这些命令可以调用临时 Redis 命令:
public interface IRedisClient
{
...
RedisText Custom(params object[] cmdWithArgs);
}
public interface IRedisNativeClient
{
...
RedisData RawCommand(params object[] cmdWithArgs);
RedisData RawCommand(params byte[][] cmdWithBinaryArgs);
}
这些自定义 API 采用灵活的对象[] 参数,它接受任何可序列化的值,例如byte[]、string、int 以及任何用户定义的复杂类型,它们被透明地序列化为 JSON 并作为 UTF-8 字节通过网络发送。
Redis.Custom("SET", "foo", 1);
结果:
client.Custom("EXPIRE", "list-id", "100");
我在 ServiceStack.Redis 中有一个列表,我想设置一个 TimeSpan 使其过期。
也就是说,如何在ServiceStack.Redis
EXPIRE ListId ttl
我想要的方法是:
client.Lists(listId, timespan);
我的问题有解决办法吗?
借助 IRedisClient 和 IRedisNativeClient 上的新自定义 API 和 RawCommand API,您现在可以使用 RedisClient 发送您自己的自定义命令,这些命令可以调用临时 Redis 命令:
public interface IRedisClient
{
...
RedisText Custom(params object[] cmdWithArgs);
}
public interface IRedisNativeClient
{
...
RedisData RawCommand(params object[] cmdWithArgs);
RedisData RawCommand(params byte[][] cmdWithBinaryArgs);
}
这些自定义 API 采用灵活的对象[] 参数,它接受任何可序列化的值,例如byte[]、string、int 以及任何用户定义的复杂类型,它们被透明地序列化为 JSON 并作为 UTF-8 字节通过网络发送。
Redis.Custom("SET", "foo", 1);
结果:
client.Custom("EXPIRE", "list-id", "100");