当前位置:网站首页>A complete tutorial for getting started with redis: getting to know redis for the first time
A complete tutorial for getting started with redis: getting to know redis for the first time
2022-07-04 22:59:00 【Gu Ge academic】
Redis [1] It's based on key value pairs (key-value) Of NoSQL database , With many key value pairs
The difference between databases is ,Redis The value in can be from string( character string )、hash( Hash )、
list( list )、set( aggregate )、zset( Ordered set )、Bitmaps( Bitmap )、
HyperLogLog、GEO( Location of geographic information ) And other data structures and algorithms , therefore
Redis It can satisfy many application scenarios , And because Redis All data will be stored in memory
in , So its read-write performance is amazing . More Than This ,Redis It can also store the data in memory
Save to hard disk in the form of snapshot and log , In this way, in the event of similar power failure or machine failure
Hou , Data in memory does not “ The loss of ”. In addition to the above functions ,Redis Keying is also provided
period 、 Publish subscribe 、 Business 、 Assembly line 、Lua Additional functions such as scripts . All in all , If in the right
Use the scene well Redis, It will be as invincible as a Swiss Army knife .
2008 year ,Redis The author of Salvatore Sanfilippo [2] In the development of a LLOOGG Net of
When standing , We need to implement a high-performance queue function , It started with MySQL To achieve ,
But then it turns out that no matter how optimized SQL Statement can not improve the performance of the website , Plus from
Be shy in your own pocket , So he decided to make one for himself LLOOGG The database of , This is
Redis The forerunner of . later ,Salvatore Sanfilippo take Redis1.0 Open source to GitHub [3]
On , Maybe he didn't even think of ,Redis So popular later .
If someone asks now Redis Who is the author of Redis, I think he can joke
Answer : Who else doesn't use Redis, Of course, it's just a joke , But from Redis The official company of
The statistic , Many heavyweight companies are using Redis, Such as foreign Twitter、
Instagram、Stack Overflow、GitHub etc. , There are more in China , If only from the volume
meter , Sina Weibo is arguably the largest in the world Redis Users , Besides Sina Weibo , And like ah
Ribaba 、 tencent 、 Baidu 、 sohu 、 Youku tudou 、 Meituan 、 millet 、 Vipshop and other companies are
Redis Users of . besides , Many open source technologies like ELK Wait until you have Redis As their group
An important part of the piece , and Redis The module system will be provided in future versions for third-party personnel
Realize function expansion , Give Way Redis To exert greater power . therefore , You can say that , Skillfully use
And operation and maintenance Redis It has become a necessary skill for development and operation personnel .
[1] http://redis.io
[2] http://antirez.com
[3] https://github.com/antirez/redis
1.2 Redis characteristic
Redis The reason why it is favored by so many companies , There must be something extraordinary , Here is about
Redis Of 8 There are two important characteristics .
1. Fast
Under normal circumstances ,Redis The execution of orders is very fast , The official figures are for reading and writing
Can achieve 10 ten thousand / second , Of course, it also depends on the performance of the machine , But let's not talk about machinability here
The difference in ability , Just analyze what makes Redis In addition, the speed , It can be roughly attributed to
Take the following four points :
·Redis All data is stored in memory , surface 1-1 It's Google 2009 Given in
Hardware execution speed at all levels , So putting data in memory is Redis The main reason for speed
because .
·Redis Yes, it is C The realization of language , Generally speaking C Language implementation of the program “ distance ” The operating system is more
near , The execution will be relatively faster .
·Redis A single threaded architecture is used , Prevent the possible competition problems caused by multi-threading .
· The author for Redis The source code can be said to be fine grinding , There has been comment Redis Is one of the few
Open source code that combines performance and elegance

2. Data structure server based on key value pairs
Almost all programming languages provide dictionary like functions , for example Java Inside map、
Python Inside dict, Similar to this way of organizing data is called key value based method , With a lot of
The key value is different from the database ,Redis The value in can be more than a string , And it can also be a
Body data structure , This can not only facilitate the development of many application scenarios , At the same time, it can also improve the opening
Hair efficiency .Redis The full name is REmote Dictionary Server, It mainly provides 5 It's a data node
structure : character string 、 Hash 、 list 、 aggregate 、 Ordered set , At the same time, it evolves on the basis of string
Bitmap out (Bitmaps) and HyperLogLog Two magical “ data structure ”, And with
LBS(Location Based Service, Location based services ) Continuous development ,Redis3.2 In the version
Add information about GEO( Location of geographic information ) The function of , In short, with the help of these data structures , open
The developer can develop various “ interesting ” Application .
3. Rich functions
except 5 Data structures ,Redis There are also many additional features :
· Key expiration is provided , Can be used to implement caching .
· Provides publish subscribe function , Can be used to implement messaging systems .
· Support Lua Script function , You can use Lua Create new Redis command .
· Simple transaction functionality is provided , To a certain extent, transaction characteristics can guarantee .
· It provides an assembly line (Pipeline) function , In this way, the client can send a batch of commands to
Redis, Reduced network overhead .
4. Simple and stable
Redis The simplicity of is mainly reflected in three aspects . First ,Redis The source code of is very few , Early versions
The code for is 2 About ten thousand lines ,3.0 After version, due to the addition of cluster feature , The code increases to 5 Line ten thousand
about , Compared with a lot of NoSQL For the database, the amount of code is relatively much less , That means ordinary
Our development and operation and maintenance personnel can “ Read and ” it . secondly ,Redis Using the single threaded model , such
Not only makes Redis The server-side processing model becomes simple , And it also makes client development simpler
single . Last ,Redis No need to rely on class libraries in the operating system ( for example Memcache Need to rely on
libevent Such a system class library ),Redis I realized the related functions of event processing .
Redis Although it's very simple , But that doesn't mean it's unstable . With thousands of... Maintained by the author Redis by
example , Not because Redis Oneself bug And the downtime .
5. Many client languages
Redis Simple is provided TCP Communication protocol , Many programming languages can easily access
Redis, And because of Redis Widely recognized by the community and major companies , So support Redis My guest
There are also many client languages , Almost covers the mainstream programming languages , for example Java、PHP、
Python、C、C++、Nodejs etc. [1] , The first 4 In this chapter, we will discuss Redis The client of bright .
6. Persistence
Usually , It's not safe to put data in memory , In case of power failure or machine failure ,
Important data may be lost , therefore Redis There are two ways to persist :RDB and
AOF, That is, two strategies can be used to save the data in memory to the hard disk ( Pictured 1-1 Shown ), this
This ensures the persistence of data , The first 5 In this chapter, we will discuss Redis The persistence of .

7. Master slave copy
Redis Provides copy function , Implement multiple data of the same Redis copy ( Pictured 1-2 the
in ), The replication function is distributed Redis The basis of . The first 6 In this chapter, we will discuss Redis Details of replication
Detailed description .
8. Highly available and distributed
Redis from 2.8 Version officially provides a high availability implementation Redis Sentinel, It can guarantee Redis
Node fault detection and automatic fault transfer .Redis from 3.0 The version officially provides a distributed implementation
Redis Cluster, It is Redis True distributed implementation , Provides high availability 、 Reading, writing and capacity
Extensibility .
边栏推荐
- Advanced area of attack and defense world misc 3-11
- Google Earth engine (GEE) -- take modis/006/mcd19a2 as an example to batch download the daily mean, maximum, minimum, standard deviation, statistical analysis of variance and CSV download of daily AOD
- Tla+ introductory tutorial (1): introduction to formal methods
- Redis入门完整教程:HyperLogLog
- 攻防世界 misc 高手进阶区 a_good_idea
- P2181 diagonal and p1030 [noip2001 popularization group] arrange in order
- Lost in the lock world of MySQL
- 攻防世界 MISC 进阶区 hit-the-core
- EditPlus--用法--快捷键/配置/背景色/字体大小
- Locust performance test - environment construction and use
猜你喜欢

A complete tutorial for getting started with redis: transactions and Lua

Redis入门完整教程:列表讲解

【OpenGL】笔记二十九、抗锯齿(MSAA)

On-off and on-off of quality system construction

Wake up day, how do I step by step towards the road of software testing

【剑指offer】1-5题
![[roommate learned to use Bi report data processing in the time of King glory in one game]](/img/06/22dde3fcc0456bd230e1d0cde339ec.png)
[roommate learned to use Bi report data processing in the time of King glory in one game]

Redis入门完整教程:集合详解

新版判断PC和手机端代码,手机端跳转手机端,PC跳转PC端最新有效代码

Attack and defense world misc advanced grace-50
随机推荐
【ODX Studio編輯PDX】-0.2-如何對比Compare兩個PDX/ODX文件
Install the gold warehouse database of NPC
Editplus-- usage -- shortcut key / configuration / background color / font size
Redis入门完整教程:API的理解和使用
Redis入门完整教程:Bitmaps
Three stage operations in the attack and defense drill of the blue team
浅聊一下中间件
剑指 Offer 65. 不用加减乘除做加法
【图论】拓扑排序
位运算符讲解
Google Earth Engine(GEE)——Tasks升级,实现RUN ALL可以一键下载任务类型中的所有影像
Redis入門完整教程:Pipeline
【OpenGL】笔记二十九、抗锯齿(MSAA)
How to choose a securities company? Is it safe to open an account on your mobile phone
Is Huatai Securities a nationally recognized securities firm? Is it safe to open an account?
蓝队攻防演练中的三段作战
质量体系建设之路的分分合合
Explanation of bitwise operators
Analysis of environmental encryption technology
Lost in the lock world of MySQL