当前位置:网站首页>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 .
边栏推荐
- 攻防世界 MISC 进阶区 can_has_stdio?
- Notepad++--编辑的技巧
- 共创软硬件协同生态:Graphcore IPU与百度飞桨的“联合提交”亮相MLPerf
- Async await used in map
- A complete tutorial for getting started with redis: redis shell
- Explanation of bitwise operators
- Redis入门完整教程:Redis Shell
- A complete tutorial for getting started with redis: transactions and Lua
- NFT insider 64: e-commerce giant eBay submitted an NFT related trademark application, and KPMG will invest $30million in Web3 and metauniverse
- A complete tutorial for getting started with redis: Pipeline
猜你喜欢
NFT insider 64: e-commerce giant eBay submitted an NFT related trademark application, and KPMG will invest $30million in Web3 and metauniverse
Redis入门完整教程:GEO
Unity修仙手游 | lua动态滑动功能(3种源码具体实现)
Sobel filter
Redis入门完整教程:有序集合详解
Detailed explanation of heap sort code
攻防世界 MISC 高手进阶区 001 normal_png
MySQL Architecture - user rights and management
[roommate learned to use Bi report data processing in the time of King glory in one game]
Redis introduction complete tutorial: slow query analysis
随机推荐
Common methods in string class
Li Kou 98: verify binary search tree
Redis introduction complete tutorial: slow query analysis
通过Go语言创建CA与签发证书
Sword finger offer 65 Add without adding, subtracting, multiplying, dividing
微信小程序显示样式知识点总结
串口数据帧
sobel过滤器
Redis démarrer le tutoriel complet: Pipeline
Notepad++--编辑的技巧
Redis: redis configuration file related configuration and redis persistence
Redis入门完整教程:列表讲解
SHP data making 3dfiles white film
Redis入门完整教程:HyperLogLog
Business is too busy. Is there really no reason to have time for automation?
Tla+ introductory tutorial (1): introduction to formal methods
剑指 Offer 65. 不用加减乘除做加法
Attack and Defense World MISC Advanced Area Erik baleog and Olaf
模拟摇杆控制舵机
新版判断PC和手机端代码,手机端跳转手机端,PC跳转PC端最新有效代码