redis搭建实战记录

系统 2645 0
Redis is an open source, advanced  key-value store . It is often referred to as a  data structure server  since keys can contain strings hashes lists sets  and  sorted sets .   

-- from  http://redis.io/  

 

redis  是一个基于内存的高性能key-value数据库,数据都保存在内存中定期刷新到磁盘,以极高的读写效率而备受关注。他的特点是支持各种数据结构,stirng,hashes, list,set,和sorted sets

client端对于不同数据结构是使用不同的命令

 

这里说一下redis的安装

虚拟机环境:  centos  

 

1 wget  make 安装

wget  http://download.redis.io/redis-stable.tar.gz

tar xvzf redis-stable.tar.gz

cd redis-stable

make

 

  这里记录一下我安装过程中出现的问题 :  

make: Warning: File `Makefile' has modification time 5.4e+06 s in the future

cd src && make all

make[1]: Entering directory `/redis/redis-2.4.7/src'

make[1]: Warning: File `Makefile' has modification time 5.4e+06 s in the future

MAKE hiredis

make[2]: Entering directory `/redis/redis-2.4.7/deps/hiredis'

make[2]: Warning: File `Makefile' has modification time 5.4e+06 s in the future

cc -c -std=c99 -pedantic -O3 -fPIC -Wall -W -Wstrict-prototypes -Wwrite-strings    -g -ggdb  net.c

make[2]: cc: Command not found

make[2]: *** [net.o] Error 127

make[2]: Leaving directory `/redis/redis-2.4.7/deps/hiredis'

make[1]: *** [dependencies] Error 2

make[1]: Leaving directory `/redis/redis-2.4.7/src'

make: *** [all] Error 2

 

 

第一个问题

make: Warning: File `Makefile' has modification time 5.4e+06 s in the future

系统时间调整错了,调过来就好了

 

第二个问题:

make[2]: Entering directory `/redis/redis-2.4.7/deps/hiredis'

cc -c -std=c99 -pedantic -O3 -fPIC -Wall -W -Wstrict-prototypes -Wwrite-strings    -g -ggdb  net.c

make[2]: cc: Command not found

没安装 gcc

yum install gcc-c++

 

第三个问题:

make 的时候显示

make[1]: Entering directory `/redis/redis-2.4.7/src'

which: no tclsh8.5 in (/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)

You need 'tclsh8.5' in order to run the Redis test

没安装 tcl

按照官网 http://www.linuxfromscratch.org/blfs/view/cvs/general/tcl.html  上的安装
 

安装完成之后, make 成功!

 

安装成功之后会在 src 文件夹内有redis-server和redis-cli两个命令

建议将其放到 bin

sudo cp redis-server /usr/local/bin/

sudo cp redis-cli /usr/local/bin/

 

 

好了,现在 redis 就安装成功了

 

2 测试redis安装情况 

我只在一台虚拟机上安装了 redis ,所以这台虚拟机既是服务器,又是客户端

测试:

 

使用 secureRt 打开一个会话,redis-server,让其作为服务器运行

[19282] 19 Feb 23:52:57 - 1 clients connected (0 slaves), 726248 bytes in use

[19282] 19 Feb 23:53:02 - DB 0: 1 keys (0 volatile) in 4 slots HT.

[19282] 19 Feb 23:53:02 - 1 clients connected (0 slaves), 726248 bytes in use

[19282] 19 Feb 23:53:07 - DB 0: 1 keys (0 volatile) in 4 slots HT.

[19282] 19 Feb 23:53:07 - 1 clients connected (0 slaves), 726248 bytes in use

 

打开另一个会话:

ast login: Tue Feb 19 22:49:49 2013 from 192.168.1.103

redis搭建实战记录

 

set key get key 都正确

redis 搭建测试通过  

 

参考文章:

http://redis.io/  

http://redis.io/topics/quickstart  

http://hi.baidu.com/thinkinginlamp/blog/item/3358c93d174e35ce9f3d62bf.html  

持久化  

redis 支持 RDB AOF 两种持久化方式

 

The RDB persistence performs point-in-time snapshots of your dataset at specified intervals.

RDB 是一种即时快照的存储方式,定时对数据库进行 snap shot

RDB 优点:

1 RDB 对于数据备份非常容易。你可以设置 1 天或者 30 天对数据进行一次备份,这样当发生数据灾难的时候能很容易恢复

由于 RDB 对数据备份时 redis 只做备份操作,所以备份最大化的使用了 redis 的性能,同时也导致了对于大的数据集, RDB 备份快于 AOF

 

RDB 缺点:

如果你的需求只是要知道两个时间段中 redis 的变化, RDB 是弱于 AOF

由于 RDB 经常使用子进程 fork() 进行数据备份,所以如果当数据比较大的时候,数据备份会比较耗时

 

AOF 优点:

你必须有一个 AOF f sync 的策略:

或者是不进行 fsync   或者每秒 fsync 一次,或者每次 query 查询的时候 fsync

2 AOF 只记录修改 log ,当存储的时候由于某种原因写 log 失误了,使用 redis -check-aof 能很好的修复

redis 数据太大的时候, AOF 可以很好被重写到新的 redis

 

AOF 缺点:

1 AOF 通常比 RDB

2 AOF RDB

 

 --------------------------

流水线

 

redis 是客户端和服务器端的通信交互 TCP 协议

 

当客户端发送请求,服务器端接受请求并发送回复,客户端接收回复,这个过程叫做 RTT (Round Trip Time)

比如如果 RTT 时间是 250 微秒,既是服务器端每秒能处理 10 万个请求,那么,我们只能认为 redis 每秒处理 4 个请求

 

server 不需要等待 client 接收了消息之后再处理新 request 的技术叫做 pipe lining (流水线)。这个技术早在几十年前就应用在了各种协议上(比如 pop3 ), redis 也很早使用了这个技术。

 

实验:

$ (echo -en "PING\r\nPING\r\nPING\r\n"; sleep 1) | nc localhost 6379

当调用这个例子的时候:

server 一次返回:

+PONG

+PONG

+PONG

 

而不是返回一次 PONG ,过了 RTT 时间再返回 PONG ,这个例子就说明了 redis 使用 pipe lining

 

注: nc 命令说明请看:

http://www.cnblogs.com/faraway/archive/2008/08/30/1280070.html  

 

 

---------------------------------

订阅 

 

  redis 支持订阅( sub scribe

当一个 client 订阅一个或多个变量,其他客户端修改了变量并 publish 之后,这个客户端会收到消息

 

例子:

Client 1:

SUBSCRIBE first second

 

Client2:

PUBLISH second Hello

 

client1 显示:

message

second

Hello2

 

 

redis 还支持模式订阅( psubscribe 命令)

PSUBSCRIBE f*

 

PHP

PHP,Linux学习
 
posted @  2012-02-21 18:32  轩脉刃 阅读(109) |  评论 (0)   编辑
 
 
posted @  2012-02-20 00:11  轩脉刃 阅读(684) |  评论 (1)   编辑
 
 
 
 
posted @  2012-02-06 07:59  轩脉刃 阅读(1530) |  评论 (4)   编辑
 
 
posted @  2012-02-03 01:10  轩脉刃 阅读(1049) |  评论 (1)   编辑
 
 
 
 
 
posted @  2011-09-01 14:41  轩脉刃 阅读(218) |  评论 (0)   编辑
 
 
posted @  2011-08-31 19:44  轩脉刃 阅读(1931) |  评论 (1)   编辑
 
 
posted @  2011-08-30 13:35  轩脉刃 阅读(2229) |  评论 (8)   编辑
 
 
 
posted @  2011-06-07 18:37  轩脉刃 阅读(1867) |  评论 (3)   编辑
 
 
posted @  2011-06-03 14:40  轩脉刃 阅读(1544) |  评论 (3)   编辑
 
 
 
 
 
 
 
 
posted @  2010-11-26 18:15  轩脉刃 阅读(363) |  评论 (0)   编辑

 

 
 

---------------------------------

参考文档:

---------------------------------

作者:yjf512(轩脉刃)

出处:http://www.cnblogs.com/yjf512/

本文版权归yjf512和cnBlog共有,欢迎转载,但未经作者同意必须保留此段声明 

redis搭建实战记录


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论