I am confused about how to use Queue in StackExchange.Redis. I have tried download the source code and check the documentation. I still can not find how to use it.
please give me suggestion.
thanks very much.
Redis supports both queues and stacks through the LPUSH, LPOP, RPUSH and RPOP commands. It is just a matter of calling the right operations on a list. Below are sample implementations of a queue and a stack as a reference. "Connection" in the code below is just an instance of a ConnectionMultiplexer
static class RedisStack
{
public static void Push(RedisKey stackName, RedisValue value)
{
Connection.GetDatabase().ListRightPush(stackName, value);
}
public static RedisValue Pop(RedisKey stackName)
{
return Connection.GetDatabase().ListRightPop(stackName);
}
}
static class RedisQueue
{
public static void Push(RedisKey queueName, RedisValue value)
{
Connection.GetDatabase().ListRightPush(queueName, value);
}
public static RedisValue Pop(RedisKey queueName)
{
return Connection.GetDatabase().ListLeftPop(queueName);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With