M. Rezaeyan
M. Rezaeyan

Reputation: 408

How to set TTL to List Values in ServiceStack.Redis?

I Have a List in ServiceStack.Redis that I want to set a TimeSpan to expire it.
In the other word, how to call the following redis command in ServiceStack.Redis

EXPIRE ListId ttl

my desired method is:

client.Lists(listId, timespan);

Is there any solution for my problem?

Upvotes: 1

Views: 740

Answers (1)

user7615014
user7615014

Reputation:

With the new Custom and RawCommand APIs on IRedisClient and IRedisNativeClient you can now use the RedisClient to send your own custom commands that can call adhoc Redis commands:

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

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

These Custom APIs take a flexible object[] arguments which accepts any serializable value e.g. byte[], string, int as well as any user-defined Complex Types which are transparently serialized as JSON and send across the wire as UTF-8 bytes.

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

Result:

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

See ServiceStack github

Upvotes: 3

Related Questions