且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

redis 安装和使用

更新时间:2022-09-15 12:37:20

环境:centos6.5  

安装gcc、gcc-c++编译的环境

1、下载Redis

wget http://download.redis.io/releases/redis-2.8.3.tar.gz

2、解压

tar xf redis-2.8.3.tar.gz -C /usr/src/

cd /usr/src/redis-2.8.3/

3、安装Redis之前测试一下make test(执行make test必须先安装tcl语言包)

wget http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz

tar xf tcl8.6.1-src.tar.gz

cd tcl8.6.1/unix/

./configure && make && make install

这个时候在命令行就可以输入tclsh进入tcl解释器 tcl就可以使用了。

4、安装

[root@moban src]# make PREFIX=/usr/local/redis install

[root@moban src]# cd /usr/local/redis/

[root@moban redis]# ls

bin

[root@moban redis]# cd bin/

[root@moban bin]# ls

redis-benchmark  redis-check-aof  redis-check-dump  redis-cli  redis-server

[root@moban bin]# cp /usr/src/redis-2.8.3/redis.conf /usr/local/redis

[root@localhost redis]# ls

bin  redis.conf 到这里redis已经安装成功了

5、启动Redis

方法一:进入 安装路径下的bin下

[root@localhost redis]# cd bin

[root@localhost bin]# ./redis-server redis.conf

[23753] 13 Nov 00:43:50.340 * Max number of open files set to 10032

                _._                                                  

           _.-``__ ''-._                                             

      _.-``    `.  `_.  ''-._           Redis 2.8.3 (00000000/0) 64 bit

  .-`` .-```.  ```\/    _.,_ ''-._                                   

 (    '      ,       .-`  | `,    )     Running in stand alone mode

 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379

 |    `-._   `._    /     _.-'    |     PID: 23753

  `-._    `-._  `-./  _.-'    _.-'                                   

 |`-._`-._    `-.__.-'    _.-'_.-'|                                  

 |    `-._`-._        _.-'_.-'    |           http://redis.io        

  `-._    `-._`-.__.-'_.-'    _.-'                                   

 |`-._`-._    `-.__.-'    _.-'_.-'|                                  

 |    `-._`-._        _.-'_.-'    |                                  

  `-._    `-._`-.__.-'_.-'    _.-'                                   

      `-._    `-.__.-'    _.-'                                       

          `-._        _.-'                                           

              `-.__.-'                                               


[23753] 13 Nov 00:43:50.342 # Server started, Redis version 2.8.3

[23753] 13 Nov 00:43:50.342 * DB loaded from disk: 0.000 seconds

[23753] 13 Nov 00:43:50.342 * The server is now ready to accept connections on port 6379

这样其实已经启动成功了,但是这属于前端启动,启动redis之后,我们的控制台就不能进行任何操作了。只能ctrl+c停止启动。

方法二:后台启动

编辑redis.conf文件  daemonize no 改为yes保存退出

再次启动

[root@localhost bin]# ./redis-server redis.conf

查看启动成功没有:

netstat -anptl |grep redis

[root@moban redis]# netstat -antp|grep redis

tcp        0      0 0.0.0.0:6379                0.0.0.0:*                   LISTEN      23767/./bin/redis-s 

tcp        0      0 :::6379                     :::*                        LISTEN      23767/./bin/redis-s

6、关闭redis

[root@localhost redis]# ./bin/redis-cli shutdown

7、简单的使用

//连接客户端

[root@moban redis]# ./bin/redis-cli 

127.0.0.1:6379>

//检查网络是否通

127.0.0.1:6379> ping

PONG

//设置一个键值对

127.0.0.1:6379> set name cheny

OK

//获取刚刚设置的键值对

127.0.0.1:6379> get name

"cheny"

//查看所有的键

127.0.0.1:6379> keys *

1) "name"

//删除name这个键

127.0.0.1:6379> del name

(integer)

1127.0.0.1:6379> keys * (empty list or set)

127.0.0.1:6379>

到这里简单的redis安装就好了












本文转自liujing0751CTO博客,原文链接:http://blog.51cto.com/13281352/1981017 ,如需转载请自行联系原作者