Redis has powerful functions and rich data types. No matter how fast the system is, it cannot withstand crazy abuse. By disabling some high-risk functions and hanging the shackles of development, the business can consider problems with concise and general ideas instead of being bound to a certain implementation.
Redis will have different persistence strategies and eviction strategies based on different uses. Therefore, before using and applying for a Redis cluster, please clarify whether it is used for caching or storage. Redis cluster has two modes: master-slave and Cluster, both of which have their own advantages and disadvantages. The following specifications do not distinguish between cluster modes. We explain them in terms of usage scenarios and operational restrictions.
Usage specifications
Hot and cold data distinction
Although redis supports persistence, storing all data in redis is very expensive. It is recommended to load hot data (such as data with QPS exceeding 5k) into redis. Low-frequency data can be stored in Mysql
and ElasticSearch
.
Business data separation
Do not put all irrelevant data services into one Redis
. On the one hand, it avoids mutual business impact, on the other hand, it avoids the expansion of a single instance, and can reduce the impact and quickly recover in the event of a failure.
Message size limit
Since Redis
is a single-threaded service, excessive messages will block and slow down other operations. It's a good practice to keep message content under 1KB. Single records exceeding 50KB are strictly prohibited. Excessively large messages will also cause high usage of network bandwidth and IO problems when persisting to disk.
Limit on the number of connections
Frequent creation and destruction of connections will waste a lot of system resources, and in extreme cases will cause the host to crash. Please make sure you are using the correct Redis
client connection pool configuration.
Cache Key Set expiration time
As a Key
used for cache, the expiration time must be set. The longer the expiration time is, the better. Please set it according to the nature of your business. Note that some units of the failure time are seconds and some are milliseconds. Many students may easily make mistakes if they don't pay attention.
The cache cannot have intermediate states
The cache should be used only for caching. The business logic should not change after being removed, and it must not be cut into the business. First, the high availability of the cache will affect the business; second, the deep coupling will have unpredictable effects; third, it will have a skin effect on the maintenance row.
The preferred extension method is client-side hash
Forget about small applications
Such as singleredis
The cluster cannot be used for your data Services, do not rush to expand your redis
cluster (including M/S and Cluster). The larger the cluster, the worse the performance in state synchronization and persistence. Priority is given to using the client hash
for cluster splitting. For example: 10 clusters are divided according to user ID, and the user whose last number is 0 falls into the first cluster.
Operation restrictions
The use of Keys is strictly prohibited
Keys
The command efficiency is extremely low, it is an O(N)
operation and will block Other normal commands, on cluster
, would be disastrous operations. Use is strictly prohibited, DBA
should rename
this command and disable it from the source.
It is strictly prohibited to use Flush
flush
The command will clear all data and is a high-risk operation. Use is strictly prohibited, DBA
should rename
this command, disabled from the source, only DBA
is operable.
It is strictly prohibited to use it as a message queue
If there are no very special needs, it is strictly prohibited to use Redis
as a message queue. Redis
When used as a message queue, there will be various problems in terms of capacity, network, efficiency, and functionality. If you need a message queue, you can use the high-throughput Kafka
or the highly reliable RocketMQ
.
Batch operations without setting a range are strictly prohibited
redis
So fast and slow queries, except for network delays, belong to these batch operation functions. Most online problems are caused by these functions.
1. [zset] Unranged operations on zset are strictly prohibited
ZRANGE
, ZRANGEBYSCORE
and other multiple operationsZSET
function, it is strictly prohibited to use ZRANGE myzset 0 -1
and other operations that do not set a range. Please specify the range, such as ZRANGE myzset 0 100
. If you are not sure about the length, you can use ZCARD
to determine the length
2. [hash] It is strictly prohibited to use HGETALL
HGETALL
for large data volume keys and it will be taken out For all data related to HASH
, if the number of data items is too large, it will also cause congestion. Please ensure that the business is controllable. If you are not sure about the length, you can use HLEN
to determine the length first
3, [key] mget operation of Redis Cluster cluster
Redis Cluster
##MGET operation will collect data from each shard and aggregate it. Compared with the traditional
M/S architecture, the performance will drop a lot. Please stress test and evaluate in advance
select function is used to switch
database, for For users, this is where problems can easily occur. The
cluster mode does not support multiple
database and has no benefits, so it is disabled.
Disable transactions
redis
It is already very fast. If there is no major need, it is recommended to catch exceptions and roll back. Do not use transaction functions. Few people do this.
Disable lua script extension
lua
Although the script can do many things that look cool
, it is like SQL
's stored procedures will introduce performance and some difficult maintenance issues and should be disabled.
Prohibit long-term monitor
monitor
function can quickly see the data flow currently being executed by redis
, but be careful, it will be blocked for a long time during peak periods On the monitor
command, it will seriously affect the performance of redis
. This command is not prohibited from being used, but special care must be taken when using it.
Key specification
Redis
's Key
must be standardized so that when problems are encountered, they can be easily located. Redis
belongs to the KV
database without scheme
, so we rely on convention to establish its scheme
semantics. Its benefits:
Can clean data based on a certain type of key
Can update data based on a certain type of key
Be able to understand the ownership and application scenarios of certain types of keys
Prepare for unification and platformization and reduce technical changes
Generally, a key
needs to have the following dimensions: business, key purpose, variables, etc. Each dimension is separated by:. Here are several examples of keys:
user:sex User 10002232’s gender
msg:achi 201712’s user number ranking
The above is the detailed content of What are the Redis specifications?. For more information, please follow other related articles on the PHP Chinese website!

Redisisanopen-source,in-memorydatastructurestoreusedasadatabase,cache,andmessagebroker,excellinginspeedandversatility.Itiswidelyusedforcaching,real-timeanalytics,sessionmanagement,andleaderboardsduetoitssupportforvariousdatastructuresandfastdataacces

Redis is an open source memory data structure storage used as a database, cache and message broker, suitable for scenarios where fast response and high concurrency are required. 1.Redis uses memory to store data and provides microsecond read and write speed. 2. It supports a variety of data structures, such as strings, lists, collections, etc. 3. Redis realizes data persistence through RDB and AOF mechanisms. 4. Use single-threaded model and multiplexing technology to handle requests efficiently. 5. Performance optimization strategies include LRU algorithm and cluster mode.

Redis's functions mainly include cache, session management and other functions: 1) The cache function stores data through memory to improve reading speed, and is suitable for high-frequency access scenarios such as e-commerce websites; 2) The session management function shares session data in a distributed system and automatically cleans it through an expiration time mechanism; 3) Other functions such as publish-subscribe mode, distributed locks and counters, suitable for real-time message push and multi-threaded systems and other scenarios.

Redis's core functions include memory storage and persistence mechanisms. 1) Memory storage provides extremely fast read and write speeds, suitable for high-performance applications. 2) Persistence ensures that data is not lost through RDB and AOF, and the choice is based on application needs.

Redis'sServer-SideOperationsofferFunctionsandTriggersforexecutingcomplexoperationsontheserver.1)FunctionsallowcustomoperationsinLua,JavaScript,orRedis'sscriptinglanguage,enhancingscalabilityandmaintenance.2)Triggersenableautomaticfunctionexecutionone

Redisisbothadatabaseandaserver.1)Asadatabase,itusesin-memorystorageforfastaccess,idealforreal-timeapplicationsandcaching.2)Asaserver,itsupportspub/submessagingandLuascriptingforreal-timecommunicationandserver-sideoperations.

Redis is a NoSQL database that provides high performance and flexibility. 1) Store data through key-value pairs, suitable for processing large-scale data and high concurrency. 2) Memory storage and single-threaded models ensure fast read and write and atomicity. 3) Use RDB and AOF mechanisms to persist data, supporting high availability and scale-out.

Redis is a memory data structure storage system, mainly used as a database, cache and message broker. Its core features include single-threaded model, I/O multiplexing, persistence mechanism, replication and clustering functions. Redis is commonly used in practical applications for caching, session storage, and message queues. It can significantly improve its performance by selecting the right data structure, using pipelines and transactions, and monitoring and tuning.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

WebStorm Mac version
Useful JavaScript development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
