Redis操作

环境准备:centOS6.5

Redis是c语言开发的。
安装redis需要c语言的编译环境。如果没有gcc需要在线安装。

安装编译环境

yum install gcc-c++

安装步骤

  • 第一步:redis的源码(安装)包上传到linux系统。

  • 第二步:进入到压缩包所在的路径,解压缩redis。

1
tar -zxvf redis-3.0.0.tar.gz
  • 第三步:编译。进入redis源码目录(redis3.0.0)。

执行:make

  • 第四步:进入/usr/redis-3.0.0/src/安装。
1
make install PREFIX=/usr/java/redis

如果报错

1
2
3
4
5
6
zmalloc.h:50:31: error: jemalloc/jemalloc.h: No such file or directory
zmalloc.h:55:2: error: #error "Newer version of jemalloc required"
make[1]: *** [adlist.o] Error 1
make[1]: Leaving directory
`/data0/src/redis-2.6.2/src'
make: *** [all] Error 2

解决办法是:

1
make MALLOC=libc

PREFIX参数指定redis的安装目录。一般软件安装到/usr目录下

连接redis

redis的启动

前端启动

在redis的安装目录的bin目录下直接启动redis-server

1
./redis-server 

后台启动

把/root/redis-3.0.0/redis.conf复制到/usr/java/r
edis/bin目录下

1
cp redis.conf /usr/java/redis/bin/

修改配置文件:

启动服务器:

1
./redis-server redis.conf

查看redis进程:

1
ps aux|grep redis
1
2
root      5190  0.1  0.3  33936  1712 ?        Ssl  18:23   0:00 ./redis-server *:6379    
root 5196 0.0 0.1 4356 728 pts/0 S+ 18:24 0:00 grep redis

关闭服务

1
./redis-cli shutdown

或者通过kill -9 PID关闭

Redis-cli

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

默认连接localhost运行在6379端口的redis服务。

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

192.168.75.128 -p 6379

-h:连接的服务器的地址

-p:服务的端口号

关闭redis:

1
./redis-cli shutdown