Redis 学习1 环境搭建

1.1 简介 
     Redis是一个开源的key-value数据库,它又经常被认为是一个数据结构服务器。因为它的Value不仅包括基本的String类型还有 list, set, sorted set和hash类型。当然这些类型的元素也都是String类型。也就是说list,set这些集合类型也只能包含String 类型。你可以在这些类型上做很多原子性的操作。比如对一个字符value追加字符串(Append命令)。加加或者减减一个数字字符串(Incr命令,当然是按整数处理的).可以对list类型进行push,或者pop元素操作(可以模拟栈和队列)。对于set类型可以进行一些集合相关操作 (intersection union difference)。
     memcache也有类似与++,--的命令。不过memcache的 value只包括string类型。远没有Redis的value类型丰富。和memcache一样为了性能,Redis的数据通常都是放到内存中的。当然 Redis可以每间隔一定时间将内存中数据写入到磁盘以防止数据丢失。Redis也支持主从复制机制(master-slave replication)。
     Redis的其他特性包括简单的事务支持和发布订阅(pub/sub)通道功能,而且Redis配置管理非常简单。还有各种语言版本的开源客户端类库。

1.2 下载

     目前Redis的下载地址有两个,其中googlecode上只有linux的安装包
    
     googlecode: https://code.google.com/p/redis/downloads/list

     github: https://github.com/dmajkic/redis/downloads

1.3 安装

    压缩包下载后,我解压到桌面上,看到32bit和64bit两个文件夹,我只是用32bit那个,主要的文件如下

       redis-server.exe:服务程序

       redis-check-dump.exe:本地数据库检查

       redis-check-aof.exe:更新日志检查

       redis-benchmark.exe:性能测试,用以模拟同时由N个客户端发送M个 SETs/GETs 查询 (类似于 Apache 的ab 工具).

       redis-cli.exe  客户端,访问服务程序的节点

1.4、体验

(1)启动服务端

C:\Users\Administrator\Desktop\Redis\redis-2.4.5-win32-win64\32bit>redis-server.exe redis.conf
[4392] 01 Apr 13:27:59 * Server started, Redis version 2.4.5
[4392] 01 Apr 13:27:59 # Open data file dump.rdb: No such file or directory
[4392] 01 Apr 13:27:59 * The server is now ready to accept connections on port 6379                //服务端的端口
[4392] 01 Apr 13:28:00 - 0 clients connected (0 slaves), 1179896 bytes in use                            //显示连接服务端的客户端数量
[4392] 01 Apr 13:28:06 - 0 clients connected (0 slaves), 1179896 bytes in use
[4392] 01 Apr 13:28:11 - 0 clients connected (0 slaves), 1179896 bytes in use
[4392] 01 Apr 13:28:17 - 0 clients connected (0 slaves), 1179896 bytes in use
…………
(2)启动客户端

C:\Users\Administrator\Desktop\Redis\redis-2.4.5-win32-win64\32bit>redis-cli.exe -h localhost -p 6379    //localhost可以换为服务器的IP地址,127.0.0.1

(3)操作

redis localhost:6379> set wil "Niu"
OK
redis localhost:6379> get wil
"Niu"
redis localhost:6379> lpush "Be"
(error) ERR wrong number of arguments for 'lpush' command
redis localhost:6379> lpush friends "be"
(integer) 1
redis localhost:6379> get wil
"Niu"
redis localhost:6379> lrange friends 0 -1
1) "be"
redis localhost:6379> lrange friends 0 -2
(empty list or set)
redis localhost:6379> lrange friends get friends
1) "be"
redis localhost:6379> exists wil

(integer) 1
redis localhost:6379>

猜你喜欢

转载自snailliuwei.iteye.com/blog/2040736