In the final chapter, we'll focus on some of the management aspects of Redis's operations. This is an incomplete Redis administration Guide, and we will answer some basic questions that may be of interest to new users who are initially contacted by Redis.
Configuration (config)
When you run the Redis server for the first time, it will show you a warning that the redis.conf
file was not found. This file can be used to configure various aspects of Redis. A well-defined (well-documented) redis.conf
file is valid for each version of Redis. The sample file contains the default configuration options, so it can be useful for you to know what the settings are doing or what the default settings are. You can find this file in https://github.com/antirez/redis/raw/2.4.6/redis.conf.
This profile is for Redis 2.4.6, you should use your version number instead of "2.4.6" in the URL above. Run the info
command, which displays the first value that is the version number of the Redis.
Since this file is already fully defined (well-documented), we will not be setting it up again.
In addition to redis.conf
configuring Redis through files, config set
commands can be used to set individual values. In fact, slowlog-log-slower-than
we've already used this command when we set it to 0 o'clock.
There is also a config get
command to display a setting value. This command supports pattern matching, so if we want to display all the settings associated with the log (logging), we can do this:
config get *log*
Verification (authentication)
By setting requirepass
(using config set
commands or redis.conf
files), you can have redis require a password validation. When requirepass
a value is set (that is, the password to be used), the client will need to execute a auth password
command.
Once a client passes the validation, it can execute any command in any database, including flushall
commands, which will erase all the keywords in each database. By configuring, you can rename some important commands as confusing strings, thereby obtaining some security.
rename-command CONFIG 5ec4db169f9d4dddacbfb0c26ea7e5efrename-command FLUSHALL 1041285018a942a4922cbf76623b741e
Alternatively, you can disable a command by setting the new name to an empty string.
Size limit (size limitations)
When you start using Redis, you may wonder how many keywords can I use? You might also want to know how many domains a hash data structure can have (especially when you use it to organize your data), or, how many elements can a list or collection data structures have? For each instance, the actual limit can reach hundreds of millions of levels (hundreds of millions).
Copy (Replication)
Redis supports replication, which means that when you write to a Redis instance (master), one or more other instances (slaves) are kept up-to-date through the Master instance. You can set it in a configuration file slaveof
, or use slaveof
a command to configure a slave instance. For Redis instances that do not have these settings, it is possible to have a master instance.
To better protect your data, copy the function to copy the data to different servers. The replication feature can also be used to improve performance because read requests can be sent to slave instances. They may return some slightly lagged data, but for most programs this is a tradeoff worth making.
Unfortunately, the Redis replication feature does not provide automatic recovery. If the master instance crashes, a slave instance needs to be manually upgraded. If you want to use Redis to achieve some high availability, it's still a tricky task for traditional high-availability tools that use heartbeat monitoring (heartbeat monitoring) and script auto-switch (scripts to automate the switch).
Backup Files (Backups)
Backing up Redis is easy, and you can copy Redis snapshots (snapshot) anywhere, including S3, FTP, and more. By default, Redis stores the snapshot as a dump.rdb
file named. At any time, you can perform scp
, or wait for, ftp
common commands on this file cp
.
There is a common case where a snapshot and a single attached file (AOF) are deactivated on the master instance, and a slave instance is processed for backup. This can help reduce the load on the master instance. You can also set more active storage parameters on slave instances without compromising overall system responsiveness.
Scaling and Redis clusters (scaling and Redis Cluster)
The replication feature (Replication) is the first tool that a growing web site can take advantage of. There are some commands that are more expensive than others (such as sort
commands) that transfer these running loads to a slave instance, keeping the overall system responsive to queries.
In addition, by distributing your keywords to multiple Redis instances, you can achieve true scaling of Redis (remember that Redis is single-threaded, which can be run in the same logical box). Over time, you will need to pay particular attention to these things (although many of the Redis vectors provide the consistent-hashing algorithm). The consideration of the horizontal distribution of data (horizontal distribution) is not within the scope of this book. These things you probably don't need to worry about, but no matter which solution you use, there are some things you have to be aware of.
The good news is that all of this work can be done under a Redis cluster. Not only provides horizontal scaling (including equalization), but also provides automatic recovery for high availability.
High availability and scaling are achievable, and redis clusters make things a lot easier as long as you're willing to spend time and effort on it.
Summary
Over the past few years, there have been many programs and sites using Redis, without a doubt that Redis can already be used in real production. However, some tools are not mature enough, especially for some security and usability-related tools. For Redis clusters, we hope to see their implementations soon, which should provide a handle to some of the existing management challenges.
\clearpage
Summarize
In many ways, Redis embodies a simple method of data processing that strips away most of the complexity and abstraction and works effectively in different systems. In many cases, choosing Redis is not the best option. In other cases, Redis is like a specially tailored solution for your data.
Finally, back to what I said at the very beginning: Redis is easy to learn. There are so many new technologies that it's hard to figure out which ones are really worth our time. If you consider the actual benefits, Redis offers his simplicity. I firmly believe that for you and your team, learning Redis is one of the best technology investments.
Redis System learning Five, management