Jun 01, 2021 Article blog
This article was reproduced from the public number: Little Sister Taste
Redis is powerful, data-rich, and fast systems can't stand crazy abuse. By disabling some of the high-risk features and attaching the shackles of development, the business is better able to think about issues with a concise, generic mindset than to be tied to an implementation.
Redis have different persistence and eviction policies for different purposes, so before you use and apply for a Redis cluster, make it clear whether it is used for caching or storage. R edis clusters have both master and cluster modes, each with advantages and disadvantages. The following specifications do not distinguish between cluster patterns, which we explain in terms of usage scenarios and operational limitations, respectively.
Although
redis
supports persistence, storing all data in
redis
can be expensive. I
t is recommended that data from hot data, such as QPS exceeding 5k, be loaded into
redis.
Low-frequency data can be stored in
Mysql
ElasticSearch中
Don't put unrelated data services in one
Redis
On the one hand, avoid business interaction, on the other hand, avoid single-instance expansion, and can reduce the impact surface in the event of failure, rapid recovery.
Because
Redis
is a single-threaded service, messages are blocked over the general assembly and other operations are slowed down. I
t's a good habit to keep message content below 1KB. N
o more than 50KB of a single record is strictly prohibited.
Too large a message can also cause high usage of network bandwidth and IO problems when persisting to disk.
Frequent creation and destruction of connections wastes a lot of system resources, and extreme situations can cause hosting to crash.
Make sure that the correct
Redis
client connection pool configuration is used.
Key
which is used as a cache, must set an expiration time. T
he longer the failure time, the better, depending on the nature of the business.
Note that the failure time of the unit is seconds, some milliseconds, this many students do not pay attention to easy to make mistakes.
The cache should only be used for caching purposes, and the business logic should not change after removal and must not be cut into the business. First, the high availability of caches can affect the business;
Small apps are gone
If a single
redis
cluster doesn't serve your data, don't rush to expand your
redis
cluster (including M/S and Cluster), the larger the cluster, the worse the performance in terms of state synchronization and persistence. P
riority is given to cluster splitting using client
hash
For example, depending on the user id of 10 clusters, the user's tail number of 0 falls on the first cluster.
Keys
are extremely inefficient, are
O(N)
operations, block other normal commands, and can be catastrophic on
cluster
It is strictly prohibited to use,
DBA
should
rename
this command, disabled from the root cause.
flush
command emptys all data and is a high-risk operation.
It is strictly prohibited to use,
DBA
should
rename
this command, disabled from root cause, only
DBA
can operate.
Redis
is strictly prohibited as a message queue if there are no very specific needs.
Redis
is used as a message queue and has a variety of capacity, network, efficiency, and functionality issues.
If you need a message queue, you can use a high-throughput
Kafka
or a highly reliable
RocketMQ
redis
is so fast that slow queries belong to these bulk operation functions, except for network latency.
Most online problems are caused by these functions.
ZRANGE
ZRANGEBYSCORE
AND OTHER FUNCTIONS THAT OPERATE
ZSET
ARE STRICTLY PROHIBITED FROM USING SUCH OPERATIONS AS
ZRANGE myzset 0 -1
WHICH DO NOT SET THE RANGE. S
pecify a range, such as
ZRANGE myzset 0 100
If the length is not known, you can use
ZCARD
to determine the length
HGETALL
takes out all data related
HASH
and, if the number of data bars is too large, can also cause congestion, making sure the business is under control.
If you are not sure of the length, you can use
HLEN
to determine the length first
Redis Cluster
MGET
operations take data aggregations to each shard, and performance is much lower than traditional
M/S
architectures
select
function is used to switch
database
which is a problem-prone place for the user, and
cluster
mode does not support multiple
database
and does not have any benefit, disabled.
redis
itself is already fast, and if there is no need to do so, it is recommended to catch exceptions for rollback, not using transaction functions, which few people do.
lua
scripts can do a lot of things that look
cool
but they're like a stored procedure for
SQL
introducing performance and some hard-to-maintain issues to disable.
monitor
function can quickly see the traffic that is currently being performed by
redis
but beware that blocking the monitor command for long
monitor
of time during peak periods can seriously affect the performance of
redis
This command is not prohibited, but it is important to pay special attention to use it.
Redis
Key
must be regulated so that it can be easily positioned when problems arise.
Redis
belongs to
scheme
KV
database, so we rely on conventions to establish its
scheme
semantics.
Benefits:
In general, a
key
needs to have the following dimensions: business, key purpose, variables, and so on, each dimension is separated by:
User:sex user 10002232 gender
msg:achi 201712 user number of speakers leaderboard
Proper constraints are necessary for the maturity of the architecture, and it is the highest level of collective development that can be achieved through agreement.
Redis
use more, but also to use stability, give some restraint, set some rules, life will become better.
Direct blocking through secondary encapsulation of
redis
client works better.
These are
W3Cschool编程狮
about
the Redis specification, which is probably the most pertinent
related introduction, I hope to help you.