一、redis编译需要gcc,因此先安装gcc # yum install gcc
make test 需要tcl #yum -y install tcl

#cd /usr/local
#yum install wget
#wget http://download.redis.io/releases/redis-3.2.4.tar.gz
#tar zxvf redis-3.2.4.tar.gz
#cd redis-3.2.4


#cd src
#./redis-server /usr/local/redis-3.2.4/redis.conf &


20459:M 14 Oct 06:27:24.782 * Increased maximum number of open files to 10032 (it was originally set to 1024).
           _.-``__ ''-._
      _.-``    `.  `_.  ''-._           Redis 3.2.4 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 20459
  `-._    `-._  `-./  _.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |           http://redis.io
  `-._    `-._`-.__.-'_.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |
  `-._    `-._`-.__.-'_.-'    _.-'
      `-._    `-.__.-'    _.-'
          `-._        _.-'

20459:M 14 Oct 06:27:24.785 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
20459:M 14 Oct 06:27:24.785 # Server started, Redis version 3.2.4
20459:M 14 Oct 06:27:24.785 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
20459:M 14 Oct 06:27:24.785 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
20459:M 14 Oct 06:27:24.785 * The server is now ready to accept connections on port 6379

四、关闭redis#./redis-cli shutdown
该命令可能出错:Could not connect to Redis at Connection refused not connected>这是由于我们启动redis时候结束窗口或Ctrl+c(注意和Ctr+z、Ctrl+d的区别)终止了redis进程

[root@localhost src]# ./redis-cli> set foo ba
OK> get foo
"ba"> quit
[root@localhost src]#

七、远程使用时候可能会报下面错误-DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients.......
修改redis.conf中的protected-mode yes 为protected-mode no重启redis

#cd  /usr/local/redis-3.2.4/utils
[root@localhost utils]# ./install_server.sh
Welcome to the redis service installer
This script will help you easily set up a running redis server

Please select the redis port for this instance: [6379]
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf]
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log]
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379]
Selected default - /var/lib/redis/6379
Please select the redis executable path [] /usr/local/redis-3.2.4/redis-server
Mmmmm...  it seems like you don't have a redis executable. Did you run make install yet?


#ln -s /usr/local/redis-3.2.4/src/redis-*  /usr/local/bin/
#service redis_6379 start(systemctl start redis_6379.service)
#ps -ef | grep redis
#service redis_6379 stop(systemctl stop redis_6379.service)


#chkconfig redis_6379 on
#chkconfig redis_6379 off

基本操作 redis-cli
redis> info #查看server版本内存使用连接等信息
redis> client list #获取客户连接列表
redis> client kill #终止某个客户端连接
redis> dbsize #当前保存key的数量
redis> save #立即保存数据到硬盘
redis> bgsave #异步保存数据到硬盘
redis> flushdb #当前库中移除所有key
redis> flushall #移除所有key从所有库中
redis> lastsave #获取上次成功保存到硬盘的unix时间戳
redis> monitor #实时监测服务器接收到的请求
redis> slowlog len #查询慢查询日志条数
(integer) 3
redis> slowlog get #返回所有的慢查询日志,最大值取决于slowlog-max-len配置
redis> slowlog get 2 #打印两条慢查询日志
redis> slowlog reset #清空慢查询日志信息