Redis Advanced Utility Features

Source: Internet
Author: User
Tags strong password redis server

1. Security

Sets the password to be used before any other specified client connection is made. Warning: Because Redis is very fast, an external user can make a 150k password attempt in a second on a better server, which means that a very strong password is required to prevent brute force. First in the configuration file redis.conf set the password, this set the password, and then the Redis client restart, re-enter, and to operate when the need for certification, there are two authentication methods 1), in the Redis client operation Auth Password 2), Enter the password when logging in to the client./redis-cli-a Password2, master-slave replicationRedis Master-slave replication configuration and usage are simple. Master-slave replication allows multiple slave servers to have the same database copy as master server. Redis Master-slave replication features:1), Master can have multiple slave;2), multiple slave can be connected to the same master, but also can be connected to other slave;3), master-slave replication does not block master, when synchronizing data, Master can continue to process client requests;4), improve the scalability of the system. Redis Master-slave replication process:1), Slave and Mater to establish 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), the background to complete the save, the file will be sent to slave;4), slave Save this file to your hard disk. Redis Master-slave replication configuration:Configuring the Slave server is simple, just add the following configuration to the slave configuration fileslaveof host IP address host portMastrauth Host Passwordand then we can do a master-slave copy.View some information about the host and slave, enter command info in the clientHost part information:Slave part information: 3, transaction processing Redis's support for things is still relativelySimple。 Redis can only guarantee that commands in one client-initiated transaction can be executed consecutively, but not in the middle of the other client's commands. When a client is issued in a connectionMulticommand, the connection is entered into a transaction context, and the subsequent command of the connectiondoes not execute immediately, but put it in a queue first, when executingexecCommand, Redis executes all the commands in the queue sequentially. Cancel a thing discard you can see that the 2 set age commands have not been executed. The discard command actually clears the command queue of things and exits the context of things, which is what we often say about rollback. Redis's handling of things is relatively simple, to be improved, reflected in: when the execution of two commands, a correct command, an error command, Redis will not be like other databases to do the full rollback operation, that is, do not do anything, but the correct command to execute, in some cases, can cause serious errors, so the processing of redis things needs to be improved. Optimistic locking complex things control: Optimistic locking: Most are implemented based on the record mechanism of the version of the data. That is, to add a version of the data identity, in a database table-based version of the solution, typically by adding a "version" field for the database table to read out the data, the version number is read together, and then updated, the version number is added 1. At this point, the version number of the submitted data is compared to the current version number of the corresponding record in the database table, and if the submitted data version number is greater than the current version number of the database, it is updated, otherwise it is considered to be outdated data. The watch command monitors the given key, and the entire transaction fails if the monitored key has changed since the call to watch. You can also call watch to monitor multiple keys more than once, so you can add optimistic locks to the specified key. Note that watch's key is valid for the entire connection, and so is the same thing. If the connection is broken, monitoring and transactions are automatically cleared. Of course. The Exec,discard,unwatch command clears all monitoring in the connection.
  4. Persistence mechanismRedis is a persistent, in-memory database, which means that Redis often needs to synchronize the in-memory data to the hard disk to ensure persistence. Redis supports two persistence modes: 1), snapshotting (snapshot) is also the default way to store the data itself in the hard Disk 2), append-only file (abbreviated AOF) to store operations on the database on the hard disk snapshot is the default persistence mode. In this way, the in-memory data is written to a binary file in a snapshot, with the default file name Dunp.rdb. You can automatically make snapshot persistence by configuring settings. We can configure Redis to automatically take snapshots if more than M key is modified in n seconds because the snapshot is done at a certain interval, if Redis accidentally falls down, all the changes after the last snapshot are lost. AOF is more persistent than snapshot, because Redis appends each received write command to a file by using the Write function, and when Redis restarts, it rebuilds the contents of the entire database in memory by re-executing the commands saved in the file. Of course, because the OS caches write modifications in the kernel, it may not be written to disk immediately. It is also possible to lose some of the modifications to the persistence of the AOF mode. The configuration file tells Redis the time we want to write to disk via the Fsync function os5. Publish and subscribe to messagesA Publish Subscription (PUB/SUB) is a message communication pattern that is primarily designed to decouple the coupling between a message publisher and a message subscriber, and Redis acts as a pub/sub server, which functions as a message route between the Subscriber and the publisher. Subscribers can subscribe to Redis server for the type of message they are interested in by using the Subscribe and Psubscribe commands, and Redis is calling the information type Channel. When a publisher sends a specific type of information to Redis server through the Publish command, all clients subscribing to that message type receive this message.  6, virtual memory using Redis virtual memory and operating system virtual memory is not the same thing, but the idea and purpose are the same. is to temporarily swap infrequently accessed data from memory to disk, freeing up valuable memory for other data that needs to be accessed. Especially for memory databases such as Redis, memory is never enough. In addition to splitting the data out to multiple Redis servers. Another way to improve database capacity is to use virtual memory to swap infrequently accessed data to disk.





Redis Advanced Utility Features

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.