1、密码的使用,使用ServiceStack.Redis会发现,连接字符串中,好像没有密码的属性,其实还是可以输入密码,只是这个设计不是很理解啊。
//先看无密码的连接 <redisUserConfiguration db="0" writeServerConStr="192.168.20.35:6379" readServerConStr="192.168.20.35:6379" maxWritePoolSize="100" maxReadPoolSize="100" autoStart="true" localCacheTime="31536000" recordeLog="false" /> //再看有密码的连接 <redisUserConfiguration db="0" writeServerConStr="123456@192.168.20.35:6379" readServerConStr="123456@192.168.20.35:6379" maxWritePoolSize="100" maxReadPoolSize="100" autoStart="true" localCacheTime="31536000" recordeLog="false"/>
发现有啥不一样了吗,连接地址用@符号隔开,密码@IP:端口
2、队列的使用。
入列:IRedisClient接口有个方法EnqueueItemOnList("队列id","值");
其实这个也是接口层封装之后的,其实调用的LPush方法。
出列:IRedisClient接口有个方法DequeueItemFromList("队列id");
其实这个也是接口层封装之后的,其实调用的RPop方法。
//一下方法不做参考,每个人写法不一样。
//入列
private static void run()
{
using (var client = new DoRedisString(RedisUtility.RedisConfig))
{
int i = 0;
while (true)
{
client.Core.EnqueueItemOnList("Myqueue", i.ToString());
i++;
}
}
}
//出列
private static void Pull()
{
using (var client = new DoRedisString(RedisUtility.RedisConfig))
{
while (true)
{
if (client.Core.GetListCount("Myqueue") > 0)
{
Thread.Sleep(1000);
string result = client.Core.DequeueItemFromList("Myqueue");
Console.WriteLine("Threadid:" + Thread.CurrentThread.ManagedThreadId.ToString() + "\t" + result);
}
else
{
//如果当前队列为空,挂起1s
Thread.Sleep(1000);
}
}
}
}用的多,了解的少,欢迎交流。
川公网安备 51010702003150号
留下您的脚步
最近评论