The master-slave mode and encryption method of Redis in PHP development

Source: Internet
Author: User
1. Redis Download 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-cliredis> set foo barokredis> get foo "bar"

Restart:

Ps-el | grep Redis

Redis-cli-h 10.185.141.146-p 6379 shutdown

Redis.conf can be re-specified 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

Master-Slave mode: cluster-enabled No

Reference: https://www.cnblogs.com/janehoo/p/6119175.html

3, the master-slave setup and construction

Bind 192.168.119.131 (bind current machine IP)
Slave settings: slaveof 10.181.24.207 6379

4, plus password reference: https://blog.csdn.net/ningxuezhu/article/details/50341613

Requirepass "Admin.123" #设置redis登录密码

Masterauth "admin.123" #主从认证密码, otherwise the master and slave cannot synchronize

Visit:/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: "The", pwd: "Ra8gp8dyan"},\       {name: " REDIS-MJQ ", Host:" 10.185.181.250 ", Port:" 6379 ", timeout:" The ", pwd:" Ra8gp8dyan "},\       {name:" Redis-ht ", Host:" 11.24.69.219 ", Port:" 6379 ", timeout:" The ", pwd:" Ra8gp8dyan "}]

3) If Redis is started, it can be set by config set Masterauth "Ra8gp8dyan" and then modify the configuration file to be loaded with the next reboot.

5. Persistence

There are two ways to persist Redis: reference: http://redisdoc.com/topic/persistence.html

Reference: https://blog.csdn.net/RobertoHuang/article/details/70847194

1, appendonly Yes//enable AOF persistence mode

2. The RDB is the default persistence mode for Redis.

RDB configuration: Three conditions have been provisioned in the configuration file

Save 900 1 # 15 minutes At least one key is changed save 300 10 # 5 minutes of at least 10 keys are changed in Save 60 10000 # 1 keys are changed at least 10,000
    • The default Rdb file path is the current directory, the file name is: Dump.rdb, you can modify the path and file name in the configuration file, respectively dir and Dbfilename

Dir./# RDB File Store path dbfilename Dump.rdb # RDB filename

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.