redis - 如何在 ServiceStack.Redis 中设置 TTL 以列出值?

标签 redis servicestack servicestack.redis

我在 ServiceStack.Redis 中有一个列表,我想设置一个 TimeSpan 使其过期。
也就是说,如何在ServiceStack.Redis中调用下面的redis命令

EXPIRE ListId ttl

我想要的方法是:

client.Lists(listId, timespan);

我的问题有解决方案吗?

最佳答案

通过 IRedisClient 和 IRedisNativeClient 上的新 Custom 和 RawCommand API,您现在可以使用 RedisClient 发送您自己的自定义命令,这些命令可以调用 adhoc Redis 命令:

public interface IRedisClient
{
    ...
    RedisText Custom(params object[] cmdWithArgs);
}

public interface IRedisNativeClient
{
    ...
    RedisData RawCommand(params object[] cmdWithArgs);
    RedisData RawCommand(params byte[][] cmdWithBinaryArgs);
}

这些自定义 API 采用灵活的 object[] 参数,它接受任何可序列化的值,例如byte[]、string、int 以及任何用户定义的复杂类型,它们被透明地序列化为 JSON 并作为 UTF-8 字节通过网络发送。

Redis.Custom("SET", "foo", 1);

结果:

client.Custom("EXPIRE", "list-id", "100");

参见 ServiceStack github

关于redis - 如何在 ServiceStack.Redis 中设置 TTL 以列出值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45476906/

相关文章:

servicestack - REDIS连接错误: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host

django - 为什么删除 Django 服务器缓存中的 session 记录不会让我注销?

REDIS:随机访问列表

c# - 如何读取json文件并在自定义类中序列化?

c# - ServiceStack JsonServiceClient 使用路由属性发送抛出异常未找到

redis - ServiceStack Redis 客户端发生意外错误

python - 如何避免 django 1.11 和 redis 3.0 上的缓存错误

lua - 如何将 Lua 字符串转换为 float

c# - 在 Redis 中使用字段值查询数据

redis - 如何连接到需要通过 ServiceStack.Redis 传递的 Redis Sentinel?