Home>Article>Backend Development> The master-slave mode and encryption method of redis in PHP development
1. Redis download and installation: https://redis.io/download
$ wget http://download.redis.io/releases/redis-4.0.10.tar.gz $ tar xzf redis-4.0.10.tar.gz $ cd redis-4.0.10 $ make $ src/redis-server $ src/redis-cli redis> set foo bar OK redis> get foo "bar"
Restart:
ps -el | grep redis
redis- cli -h 10.185.141.146 -p 6379 shutdown
You can re-specify redis.conf in this way:
/usr/local/bin/redis-server /export/servers/redis/ redis.conf
2. Introduction to master-slave mode and cluster mode
Note the cluster mode setting: cluster-enabled yes
The master-slave mode is: cluster-enabled no
Reference: https://www.cnblogs.com/janehoo/p/6119175.html
3. Master-slave setup
bind 192.168.119.131 (bind the current machine IP)
Slave settings: slaveof 10.181.24.207 6379
4. Password reference: https://blog.csdn.net/ningxuezhu/article/details/50341613
requirepass "admin.123" #Set redis login password
masterauth "admin.123" #Master-slave authentication password, otherwise master-slave cannot be synchronized
Access:/usr/local/bin/redis- cli -h 10.181.21.214 -p 6379 -a RA8gp8DyAn
Code encryption method:
1)
URI uri = URI.create(config.getUri()); redis = new Jedis(uri, config.getTimeout());
"uri": "redis://:RA8gp8DyAn@10.181.24.207:6379/0"
2)
Jedis jedis=new Jedis(map.get("host"),Integer.parseInt(map.get("port")),Integer.parseInt(map.get("timeout"))
redis=[{name:"redis-lf",host:"10.181.24.207",port:"6379",timeout:"5000",pwd:"RA8gp8DyAn"},\ {name:"redis-mjq",host:"10.185.181.250",port:"6379",timeout:"5000",pwd:"RA8gp8DyAn"},\ {name:"redis-ht",host:"11.24.69.219",port:"6379",timeout:"5000",pwd:"RA8gp8DyAn"}]
3) If redis It has been started. You can set it through config set masterauth "RA8gp8DyAn" first, and then modify the configuration file to load it at the next restart.
5. Persistence
Redis has two persistence methods: Reference: http://redisdoc.com/topic/persistence.html
Reference: https://blog.csdn.net/RobertoHuang/article/details/70847194
1. appendonly yes //Enable aof persistence method
2. RDB is the default persistence method of Redis .
RDB configuration: Three conditions have been preset in the configuration file
save 900 1 # 15分钟内至少有一个键被更改 save 300 10 # 5分钟内至少有10个键被更改 save 60 10000 # 1分钟内至少有10000个键被更改
The default rdb file path is the current directory, and the file name is: dump.rdb , you can modify the path and file name in the configuration file, which are dir and dbfilename
dir ./ # rdb文件存储路径 dbfilename dump.rdb # rdb文件名
The above is the detailed content of The master-slave mode and encryption method of redis in PHP development. For more information, please follow other related articles on the PHP Chinese website!