using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RedisCall
{
using ServiceStack.Redis;
class Program
{
static void Main(string[] args)
{
//开始调用
//1.0 确定redis服务器的ip(127.0.0.1)+port (默认6379)
//2.0 实例化redis的客户端实例
using (var client = RedisClientFactory.Instance.CreateRedisClient("127.0.0.1", 6379))
{
//3.0 利用Set存储数据:特点:如果key不存在,则创建,否则跟新其数据(相同的键后面的会覆盖前面的)
client.Set<string>("name1", "{name:ivan}");
client.Set<string>("name1", "{name:ivan11111111}");
Console.WriteLine(client.Get<string>("name1"));
//4.0 List
client.AddItemToList("age1", "29");
client.AddItemToList("age1", "30");
client.AddItemToList("age1", "29");
List<string> list = client.GetAllItemsFromList("age1");
list.ForEach(c => Console.WriteLine(c));
//5.0 Set 用于数据消重
client.AddItemToSet("蜀国", "刘备");
client.AddItemToSet("蜀国", "张飞");
client.AddItemToSet("蜀国", "刘备");
client.GetAllItemsFromSet("蜀国").ToList().ForEach(c => Console.WriteLine(c));
//6.0 实现队列操作(先进先出)
//client.EnqueueItemOnList("魏国", "老王");
//client.EnqueueItemOnList("魏国", "曹操");
//client.EnqueueItemOnList("魏国", "张辽");
int count = client.GetListCount("魏国");
for (int i = 0; i < count; i++)
{
//将数据出队列以后,同时移除该数据
Console.WriteLine(client.DequeueItemFromList("魏国"));
}
}
Console.ReadKey();
}
}
}