Home > Database > Redis > body text

8 things you must know about redis

王林
Release: 2021-01-07 09:46:18
forward
2540 people have browsed it

8 things you must know about redis

The 8 pieces of knowledge you must master about redis are as follows:

(Learning video sharing: redis video tutorial)

1. What is redis

Redis is a storage system that supports multiple data structures such as Key-Value. Can be used in scenarios such as caching, event publishing or subscription, high-speed queues, etc. The database is written in ANSI C language, supports the network, provides direct access to strings, hashes, lists, queues, and collection structures, is memory-based, and is durable.

2. Supported languages

8 things you must know about redis

3. What are the application scenarios of redis

1, Session caching (most commonly used)
2, message queue,
such as payment 3, activity ranking or counting
4, publishing, subscribing message (message notification)
5, product list, comment list, etc.

4, redis data type
Redis supports a total of five data types: string (string), hash (hash), list (list), set (set) and zset (sorted set ordered set).

(1) String (string)
It is the most basic data type of redis. One key corresponds to one value. It should be noted that the maximum storage of a key value is 512MB.

8 things you must know about redis

(2) hash (hash)
redis hash is a collection of key-value pairs, a mapping table of string type field and value, suitable for use For storage objects

8 things you must know about redis

(3) Table (list)
is a simple string list of redis, which is sorted in insertion order

8 things you must know about redis

(4) Group (set)
is an unordered set of string type and cannot be repeated

8 things you must know about redis

(5) zset (sorted set ordered set)
is an ordered set of string type and cannot be repeated
Each element in the ordered set needs to specify a score, and the elements are sorted in ascending order according to the score. If multiple elements have the same The scores are sorted in ascending order in lexicographic order. The sorted set is therefore very suitable for implementing ranking

8 things you must know about redis

5. Redis service-related commands

8 things you must know about redis

slect#Select database (database number 0-15)
Exit#Exit the connection
Information#Get service information and statistics
monitor#Real-time monitoring
config get#Get service Configuration
flushdb#Delete the key in the currently selected database
flushall#Delete the key in all databases

6, redis publication and subscription

redis publication and subscription ( Publish/subscribe) is a message communication model in which one party sends information and the other party receives information.
The picture below shows three clients subscribing to the same channel at the same time

8 things you must know about redis

The picture below shows that when new information is sent to channel 1, the message will be sent to the subscriber. The three clients

8 things you must know about redis

#7, redis persistence

There are two ways of redis persistence: snapshot (snapshot), attach file only (AOF)

Snapshot (snapshot)

1, write the data stored in the memory into a binary file in the form of a snapshot, such as
2 in the default dump.rdb, save 900 1

#If more than 1 Key is modified within 900 seconds, start snapshot saving
3, save 300 10

#If more than 10 Keys are modified within 300 seconds, start snapshot saving
4, Save 60 10000

# If more than 10,000 key points are modified within 60 seconds, snapshot saving will be started

Attach file only (AOF)

1, When using AOF persistence, the service will append each received write command to the file (appendonly.aof) through the write function
2, AOF persistence storage method parameter description

    appendonly yes  
           #开启AOF持久化存储方式     appendfsync always 
         #收到写命令后就立即写入磁盘,效率最差,效果最好    appendfsync everysec
         #每秒写入磁盘一次,效率与效果居中    appendfsync no 
         #完全依赖操作系统,效率最佳,效果没法保证
Copy after login

8, redis performance test

Comes with relevant testing tools

8 things you must know about redis

The actual test executes 1 million requests at the same time

8 things you must know about redis

Related recommendations: redis database tutorial

The above is the detailed content of 8 things you must know about redis. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!