沈阳格力专卖店 发表于 2015-7-20 13:34:29

Redis入门学习

  Redis安装
  $ wget http://redis.googlecode.com/files/redis-2.6.13.tar.gz
$ tar xzf redis-2.6.13.tar.gz
$ cd redis-2.6.13
$ make

  Redis启动
  $ src/redis-server
  
Redis 简单测试:
  $ src/redis-cli
redis> set foo bar
OK
redis> get foo
"bar"

  复杂测试:
  ./runtest (注:要先安装tcl 8.5 tk 8.5, sudo apt-get install tk )
  此命令会运行一个官方的测试程序。看最后的结论:全部测试成功通过。
  
  这样就可以让客户端连接上来了。
  客户端软件有很多, 在这个连接里有列表: http://redis.io/clients
  对c#最熟悉,就选了一个c# client, ServiceStack.Redis这个可以在Nuget界面里找到。找到后加入项目。



using ServiceStack.Redis;
using System.Diagnostics;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Stopwatch sw = new Stopwatch();
sw.Start();
using (var client = new RedisClient("192.168.63.134"))
{
for (int i = 0; i < 100000; i++)
{
client.Add("key" + i, i);
}
}
sw.Stop();
System.Console.WriteLine("It takes " + sw.ElapsedMilliseconds + "ms to add 100000 key to Redis");
sw.Restart();
using (var client = new RedisClient("192.168.63.134"))
{
for (int i = 0; i < 100000; i++)
{
client.Get("key" + i);
}
}
sw.Stop();
System.Console.WriteLine("It takes " + sw.ElapsedMilliseconds + "ms to get 100000 key from Redis");
System.Console.ReadKey();
}
}
}
  本人的机器运行出结果:大概14秒来存储100000个key, 大概14秒取出100000个key.
  
页: [1]
查看完整版本: Redis入门学习