Redis Advanced Applications

Source: Internet
Author: User

Redis Advanced utility features are divided into 6 parts:


1. Security

You need to use a password when you set up a client connection for any other action

Modify the redis.conf configuration file, requirepass password instructions are used to set the password

To restart the Redis service after modifying the configuration file

When you restart, you will see the following prompt when you perform an action on the command line. You need to use Auth password to authorize this.

127.0.0.1:6379> keys * (Error) Noauth authentication required.127.0.0.1:6379> Auth redis123ok127.0.0.1:6379> Keys * (empty list or set)


If you do not want to enter a password at the command line to complete authorization, you can enter the password when you log on to the client

[[email protected] init.d]#/usr/local/redis/bin/redis-cli-a redis123127.0.0.1:6379> keys * (empty list or set)



2, master-slave replication

Redis Master-slave replication configuration and usage is straightforward. Master-slave replication allows multiple slave servers to have the same database copy as master server


How master-slave replication works:

1, slave and Master after establishing a connection, send Sync Sync command

2. Master initiates a background process, saves the database snapshot to a file, and the master master process starts collecting new write commands and caches

3. After the background is finished saving, send this file to slave

4. Slave save this file to your hard disk


Features of Master-slave replication:

A, master can have multiple slave

b, multiple slave can be connected to the same master, you can also connect to other slave (this feature is to prevent master failure, slave cannot synchronize, if slave also connected to other slave, then master hangs up, This slave will become master, take over the service)

C, master-slave replication does not block master, while synchronizing data, Master can continue to process client requests

D, improve the scalability of the system


configuration of Master-slave replication :

In the Slava configuration file, add the following configuration:

Slaveof 192.168.1.1 6379 #指定master的ip和端口

Masterauth PASSWORD # This is master's password


Note: master-slave configuration considerations:

The configuration file for master, slave, bind 127.0.0.1 This configuration is changed to the IP address of the ETH0 network card, otherwise the Redis port listens on the 127.0.0.1 by default. This way the slave to the master port does not pass.

After changing the IP address of BIND, use the command when entering the client:

$redis _home/bin/redis-cli-h 172.16.206.140

Even if you specify the IP address of the eth0 NIC with the-h parameter, the default is 127.0.0.1



3. Transaction processing

Redis's handling of transactions is now relatively straightforward, and Redis can only guarantee that commands in one client-initiated thing can be executed consecutively, without inserting the commands of other clients in the middle. When a client issues a multi command in a connection, the connection goes into a transaction context, and the subsequent command of the connection is not executed immediately, but is placed first in a queue, and Redis executes the commands in the queue sequentially when the EXEC command is executed

For example:

172.16.206.142:6379> set age 27ok172.16.206.142:6379> 172.16.206.142:6379> get Age "27" 172.16.206.142:6379 > multiok172.16.206.142:6379> Set Age 37queued172.16.206.142:6379> set age 47queued172.16.206.142:6379> Set age 47queued172.16.206.142:6379> exec1) OK2) OK3) ok172.16.206.142:6379> Get the Age "47"


Discard: Canceling a transaction

172.16.206.142:6379> get Age "172.16.206.142:6379>" multiok172.16.206.142:6379> set Age 100queued172.16.206.142:6379> set age 200queued172.16.206.142:6379> discardok172.16.206.142:6379> get Age " 47 "




4. Persistence mechanism





5. Publish a subscription message






6, the use of virtual memory



This article is from the "Zengestudy" blog, make sure to keep this source http://zengestudy.blog.51cto.com/1702365/1854178

Redis Advanced Applications

Related Article

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.