当前位置:网站首页>Redis knowledge points
Redis knowledge points
2022-06-09 20:20:00 【It is small new】
Redis
NoSQL
NoSQL, A general term for a non-relational database . With the Internet web2.0 The rise of websites , Traditional relational databases
Processing web2.0 Website , Especially in large-scale and highly concurrent communities , A lot of difficult problems have been exposed ,NoSQL
Redis It's the fastest growing , And it is what we must master at present
A technical
Relational database : form , That's ok , Column
Non relational database : Key value pair Map<String,Object>
NoSQL characteristic
1 decoupling
2 Easy to expand ( There's no relationship between the data , Very easy to expand )
3 Large data volume and high performance (Redis One second can write 8 All the data , Read 11 All the data )
4 Data types are diverse ,5 Common use ,3 Species characteristics ( There's no need to design the database in advance , Take it and use it )
5 Tradition RDBMS and NoSQL The difference between
That is, the difference between relational and non relational databases
NoSQL Four categories
KV Key value pair
Document database (bson Format , and json equally )
Column store database
Graphical relational database
Solve application scenarios
Create objects by reflection
Get and set properties through reflection
Call methods through reflection
Classic application scenarios
Do caching
Publish subscribe mode
Distributed lock , share session
Redis Installation and use
○ install
Before reference linux Documentation for installation
Use
Modify the configuration
bind Set up redis It can be connected remotely , By default, only localhost Connect
port Specify port number , Just use the default ( When the port conflicts, it needs to be modified )
daemonize: Set to yes Delegates can start in the background
requirepass: Specified password redis The default is protected mode , You can connect remotely only if you have configured a password
stay redis Start in the installation directory redis-server redis.conf
Connect redis
redis-cli Connect
auth password Verify authority
keys * View all key
Basic operation
select Select Library
set key value Set the value
get key Get value
del key Delete key
flushdb Empty the current library
flushall Empty all libraries
expire key seconds Set up key The expiration time of
ttl key Check the time remaining
○ Redis Five basic data types
String
set
get
del
setex key expire value Set up kv And specify the expiration time
setnx key value Set if key Add if not
getrange key start stop Get the specified returned content
strlen key To obtain the length of the
List
lpush key elements Left side insertion means head insertion
rpush key elements Right side insertion means tail insertion
lrange key start stop View the contents of the specified index range
lpop / rpop Out of the stack
lrem key count element Delete the specified number of element Elements
ltrim key start stop Intercept the contents of the specified range of the array
llen key Viewing the length of an array
rpoplpush source target source Tail out of stack target Head in stack
lset key index value Set the value of the specified index
linsert key before/after element value Add content before and after the specified element
Set
sadd key value
smembers key See all members
sismemeber key element Determine whether you are a member
srem Delete
srandmemeber Get a member randomly
spop Stack randomly
sdiff Subtraction
sinter Find the intersection
sunion Union
Hash
hset key field value Set the element
hget key field Get elements
hgetall key Get all
hdel key field Remove elements
hlen key field To obtain the length of the
hkeys Get all key
hvals Get all val
hsetnx If no settings exist , To exist is to ignore
hincrby += Integer type
hincrbyfloat += floating-point
ZSet( The corresponding ones are sorted set)
In addition to the basic elements, a score Field of , The default in accordance with the score Sort
zadd key score element Additive elements
zrange key min max View the data of the specified ranking range .( The default value is from small to large )
zrevrange key max min View the data of the specified ranking range .( According to the score from big to small )
zrem Delete
zrank key element Get ranking
zrevrank key element Get the rank in reverse order
zrangebyscore Get the specified score range
zrevrangebyscore Get the specified score range ( The reverse )
redis Persistence problem
RDB
The default way
fork A sub thread is created , And the sub thread periodically synchronizes the data of the main thread , Save to local form file
advantage
For the main thread IO No impact , All for redis The read / write performance of is not affected
The efficiency of backup and recovery is relatively high , It is very suitable for backing up a large amount of data
shortcoming
Data may be lost , If the data requirements are strict, try not to use this
fork One thread Double the memory usage
How do you use it?
redis This mode is on by default
You can configure the dump The name and location of the file
dump_test.rdb
dir ./
How to actively trigger saving
save: Save after blocking
bgsave: Do not block save
How to restore backups
Just put dump.rdb Just put it in the designated position
AOF
By appending set How to log , persist , The recovery can be completed by performing the recovery according to the log
advantage
Data is relatively complete
shortcoming
The log file is too large
Slow backup and recovery
rewrite Mechanism
When the file is too large , Would be right aof Text plus compression , Keep only the smallest recoverable file size
Application scenarios
High requirements for data completion , When the performance is not so high
How do you use it?
Turn on AOF The configuration can be
appendonly yes
appendfilename "appendonly.aof"
Delete mechanism
timer
For every one key Start a timer , Point to point deletion
CPU Large occupation , Trade time for space
Lazy deletion
Visit this key It is not until the expiration date , Delete expired
Large memory consumption , Trade space for time
Delete periodically
To perform a second hz Delete times
When deleting, delete the database one by one
It's not completely deleted , Is sample deletion , The expired memory usage after sampling is less than 25% stop it
Eliminate the eviction mechanism
What to do if the memory is full
classification
Eliminate those that have not been used for a long time key
Eliminate the least frequently used key
Eliminate those that are about to expire key
To be eliminated at random
How do you use it?
Use the maximum memory in the configuration
Specify obsolescence policy
Main standby mode
Sentinel mode
Cluster building
Common cluster architecture
master/slave
De centralization
Summarize the key points
redis summary
Installation and basic configuration
Five data types
Persistence
rdb and aof
jedis
Understand the deletion and obsolescence mechanism
redis Main standby mode
One master and two subordinates
It's passed down from generation to generation
Going to
Sentinel mode
Cluster building
边栏推荐
- Jerry's modification to improve the output frame rate of camera source video [chapter]
- 平安证券开户有什么风险吗?安全的吗?
- Look at other people's text recognition system. It's called elegant!
- ConvNets Principles
- Leetcode stack and queue
- Unity UI scrollbar component
- Automatically update domain name resolution to local IP, DDNS
- Resolving the disorder of JSON parsing by fastjson
- Jerry's Bluetooth distribution network [chapter]
- 安路科技发布SF1系列FPSoC新品:高集成低功耗,助力实现多种应用场景
猜你喜欢

护网面试(杂)

2022年GDCPC广东省大学生程序设计竞赛题解

The processor of this virtual machine supports different functions than the processor of the virtual machine that holds the state of the virtual machine

After the job interview failed, the interviewer roast in the circle of friends (heart tired)

面试字节测开岗失败后,被面试官在朋友圈吐槽了......(心累)

Jvm- how the bytecode is executed by the JVM + a little thought about the thread primer

NoSQL之Redis配置与优化(你不在南京的日子我替你吹了秦淮河的晚风)

The best time to plant a tree is ten years ago, and the second is now (C language selection and cycle training topic)

Leetcode 1984. 学生分数的最小差值(可以,已解决)

ConvNets Principles
随机推荐
UNION ALL UNION FULL JOIN
Personal blog system (with source code)
ASP Err.Number 错误描述详解
Is there any risk in opening an account with Ping An Securities? Is it safe?
杰理之io_key 双按键如何使用?【篇】
FPGA introduction experiment - multi key control of variable speed running light and jump light based on state machine
WIN7 64位旗舰版安装OFFICE2003 提示:“错误1919,配置ODBC数据源MS Access Database时发生错误ODEC错误”
【RK2206】4. MQTT示例
Jerry's chart confirms that the project has not opened config_ NO_ SDRAM_ Enable macro, SDRAM used in the project [chapter]
谁是最后大赢家?华为云IoT创新应用开发大赛圆满落幕!
Download the latest global epidemic history data to the two days before the current day
Xcode 14 带来全新提升,Xcode Cloud 正式推出!
2022 gdcpc Guangdong undergraduate program design competition
2022 Shandong Health Expo, dietotherapy and nourishing health exhibition, health management and precision medicine Exhibition
Sqlsugar帮助类
Sqlsugar help class
NoSQL之Redis配置与优化(你不在南京的日子我替你吹了秦淮河的晚风)
Tidb single machine and cluster environment installation, single machine rapid experience
MobX初探
95 ans plus tard, le programmeur de Big Factory a été condamné à neuf mois de prison pour avoir supprimé la bibliothèque.