1、Redis 查看配置

CONFIG get *

[root@localhost redis]# /usr/local/redis/bin/redis-cli
127.0.0.1:6379> CONFIG get *
  1) "dbfilename"
  2) "dump.rdb"
  3) "requirepass"
  4) ""
  5) "masterauth"
  6) ""
  7) "unixsocket"
  8) ""

2、重新设置timeout0

  CONFIG set timeout 0

127.0.0.1:6379>  CONFIG set timeout 0
OK
127.0.0.1:6379>  CONFIG get timeout
1) "timeout"
2) "0"

二、Redis通用配置

[root@localhost redis]# cat /usr/local/redis/etc/redis.conf
     daemonize yes
     pidfile /usr/local/redis/var/redis.pid
     port 6379
     timeout 300
     loglevel debug
     logfile /usr/local/redis/var/redis.log
     databases 16
     save 900 1
     save 300 10
     save 60 10000
     rdbcompression yes
     dbfilename dump.rdb
     dir /usr/local/redis/var/
     appendonly no
     appendfsync always

Redis配置讲解_Redis配置讲解

Redis配置讲解_Redis配置讲解_02

127.0.0.1:6379> select 1
OK
127.0.0.1:6379[1]> keys *
(empty list or set)
127.0.0.1:6379[1]> select 0
OK
127.0.0.1:6379> keys *
1) "caimz"
127.0.0.1:6379> select 15
OK
127.0.0.1:6379[15]> keys
(error) ERR wrong number of arguments for 'keys' command
127.0.0.1:6379[15]> keys *
(empty list or set)
127.0.0.1:6379[15]> select 16
(error) ERR invalid DB index

Redis配置讲解_Redis配置讲解_03

Redis配置讲解_Redis配置讲解_04

1、添加redis的密码,就像mysql设置密码那样

[root@localhost redis]# vim /usr/local/redis/etc/redis.conf 

Redis配置讲解_Redis配置讲解_05

[root@localhost redis]# service redis restart
Stopping redis-server:                                     [  OK  ]
Starting redis-server:                                     [  OK  ]
[root@localhost redis]# /usr/local/redis/bin/redis-c
redis-check-aof   redis-check-dump  redis-cli        
[root@localhost redis]# /usr/local/redis/bin/redis-cli
127.0.0.1:6379> l
(error) ERR unknown command 'l'
127.0.0.1:6379> get caimz
(error) NOAUTH Authentication required. #此时要需要密码

2、密码登陆redis

[root@localhost redis]# /usr/local/redis/bin/redis-cli -a caimz #-a 后面跟随的就是密码
127.0.0.1:6379> get caimz
"leco"

1、重命名

[root@localhost redis]# vim /usr/local/redis/etc/redis.conf

Redis配置讲解_Redis配置讲解_06

重启



redis  AOF


Redis AOF 持久化相关配置

Redis配置讲解_Redis配置讲解_07

Redis配置讲解_Redis配置讲解_08

1、配置redis.conf

[root@localhost redis]# vim /usr/local/redis/etc/redis.conf

[root@localhost redis]# cat /usr/local/redis/etc/redis.conf

     daemonize yes
     pidfile /usr/local/redis/var/redis.pid
     port 6379
     timeout 300
     loglevel debug
     logfile /usr/local/redis/var/redis.log
     databases 16
     save 900 1
     save 300 10
     save 60 10000
     rdbcompression yes
     dbfilename dump.rdb
     dir /usr/local/redis/var/
     appendonly yes     #yes 开启AOF no关闭AOF
     appendfilename append.aof
     appendfsync always
     requirepass caimz

[root@localhost redis]# service redis restart #重启redis 因为新配置redis.conf
Stopping redis-server:                                     [  OK  ]
Starting redis-server:                                     [  OK  ]

[root@localhost Desktop]# ls   /usr/local/redis/var/
append.aof  dump.rdb  redis.log  redis.pid 

[root@localhost Desktop]# ls -al /usr/local/redis/var/
total 128
drwxrwxrwx 2 root  root    4096 Dec  6 01:40 .
drwxr-xr-x 5 root  root    4096 Dec  6 00:44 ..
-rw-r--r-- 1 redis redis      0 Dec  6 01:40 append.aof #此时还没有数据
-rw-r--r-- 1 redis redis     32 Dec  6 01:40 dump.rdb
-rw-r--r-- 1 redis redis 109675 Dec  6 01:42 redis.log
-rw-r--r-- 1 redis redis      5 Dec  6 01:40 redis.pid

[root@localhost redis]# /usr/local/redis/bin/redis-cli  -a caimz #进入redisredis数据
127.0.0.1:6379> set key1 caimz
OK
127.0.0.1:6379> get key1
"caimz"
127.0.0.1:6379> 

[root@localhost Desktop]# ls -al /usr/local/redis/var/ 
total 136
drwxrwxrwx 2 root  root    4096 Dec  6 01:40 .
drwxr-xr-x 5 root  root    4096 Dec  6 00:44 ..
-rw-r--r-- 1 redis redis     57 Dec  6 01:42 append.aof  #此时就有记录
-rw-r--r-- 1 redis redis     32 Dec  6 01:40 dump.rdb
-rw-r--r-- 1 redis redis 110679 Dec  6 01:42 redis.log
-rw-r--r-- 1 redis redis      5 Dec  6 01:40 redis.pid