您的位置:首页 > 数据库 > Redis

Redis用LPUSH和RPOP实现消息队列

2017-03-23 14:44 381 查看
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ServiceStack.Redis;
namespace RedisTest3_LPUSH
{
class Program
{
static void Main(string[] args)
{
var r = Console.ReadLine().ToString();
if (r == "push")
{
push();
}
else
{
pop();
}

Console.ReadLine();
}

public static void push()
{
Console.WriteLine("push---");
IRedisClient client = new RedisClient("127.0.0.1", 6379);
while(true)
{
client.PushItemToList("list1", Console.ReadLine());
}
Console.WriteLine("ok");

}

public static void pop()
{
Console.WriteLine("pop---");
IRedisClient client = new RedisClient("127.0.0.1", 6379);
while (true)
{
var msg = client.PopItemFromList("list1");
if(!string.IsNullOrEmpty(msg))
Console.WriteLine(msg);
}

}
}
}


View Code

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: