Kev*_*hen 3 stackexchange.redis
我对如何在StackExchange.Redis中使用Queue感到困惑.我尝试下载源代码并检查文档.我还是找不到如何使用它.
请给我一些建议.
非常感谢.
Redis通过LPUSH,LPOP,RPUSH和RPOP命令支持队列和堆栈.只需在列表中调用正确的操作即可.下面是队列和堆栈的示例实现作为参考.下面的代码中的"连接"只是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);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2758 次 |
| 最近记录: |