当前位置:网站首页>Introduction to redis and jedis and redis things
Introduction to redis and jedis and redis things
2022-07-07 23:08:00 【Scale biubiu】
Redis brief introduction :
A relational database is a database based on a relational table , Eventually, data will be persisted to disk , and nosql The database is based on a special structure , And store the data in the memory database . In terms of performance ,nosql Database is better than relational database , In terms of security, relational database is better than nosql database , So in the actual development of a project nosql Will be used with relational databases , Achieve double guarantee of performance and safety .
Redis Precautions for :
redis It's a kind of advanced key-value Storage system
Among them key It's a string type , Try to meet the following points :
- key Don't be too long. , Better not to exceed 1024 Bytes , This not only consumes memory, but also reduces lookup efficiency
- key Don't be too short. , If it's too short, it will decrease key Readability
- In the project ,key It's better to have a uniform naming convention ( According to the needs of the enterprise )
among value Five data types are supported :
- String type string
The string type is Redis The most basic data storage type in , It's in Redis Is binary safe , This means that the type can accept data in any format , Such as JPEG Image data or Json Object description information, etc . stay Redis Of string type Value The maximum length of data that can be held is 512MPictured :

- String list lists
stay Redis in ,List The type is a list of strings in insertion order . It is the same as the common linked list in data structure , We can have it on the head (left) And the tail (right) Add new elements . When inserting , If the key doesn't exist ,Redis A new linked list will be created for the key . On the contrary , If all elements in the list are removed , Then the key will also be removed from the database .List The maximum number of elements that can be contained in is 4294967295. From the efficiency perspective of element insertion and deletion , If we insert or delete elements at both ends of the list , This will It will be a very efficient operation , Even if millions of records have been stored in the linked list , This can also be done in constant time . However, it should be noted that , If the element insert or delete operation is applied to the middle of the list , That would be very inefficient . I believe that for developers with good data structure foundation , It's not hard to understand .Pictured :

- String collection sets
stay Redis in , We can Set Type as a character set without sorting , and List Same type , We can also add data values of this type 、 Delete or determine whether an element exists, etc . It should be noted that , The time of these operations is constant .Set The maximum number of elements that can be included is 4294967295. and List The difference in type is ,Set Duplicate elements are not allowed in the collection . and List Type comparison ,Set class Type also has a very important feature in function , That is, to complete multiple on the server side Sets Aggregate computing operations between , Such as unions、intersections and differences. Because these operations are completed on the server side , So it's very efficient , And it also saves a lot of network IO expensesPictured :

- Ordered string collection sorted sets
Sorted-Sets and Sets The type is very similar , They are all sets of strings , Duplicate members are not allowed to come out Now one. Set in . The main difference between them is Sorted-Sets Each member in will have a score (score) Associated with it ,Redis It's the scores that sort the members of a collection from small to large . However, it should be noted that , Even though Sorted-Sets The members of must be the only , But the score (score) But it can be repeated . stay Sorted-Set Add 、 Deleting or updating a member is a very fast operation , Its time complexity is the logarithm of the number of members in the set . because Sorted-Sets The positions of the members in the collection are ordered , therefore , Even accessing members in the middle of a collection is still very efficient . in fact ,Redis This feature is difficult to implement in many other types of databases , let me put it another way , At this point to achieve and Redis Equally efficient , Modeling in other databases is very difficult .for example : Game ranking 、 Microblog hot topics and other use scenarios .
Pictured :

- Hash type hashs
Redis Medium Hashes Type can be seen as having String Key and String Value Of map Containers . So this type is very suitable for storing information of value objects . Such as Username、Password and Age etc. . If Hash It contains very few fields , Then this type of data will only occupy a small amount of disk space . every last Hash Can be stored 4294967295 Key value pairs .Pictured :

Jedis brief introduction AND Use :
that jedis It's the integration of redis Some command operations of , Encapsulates the redis Of java client . Provides connection pool management . Generally, it is not used directly jedis, But on top of it, there is a layer of encapsulation , Use as a business . If you use spring Words , You can see spring Packaged redis Spring Data Redis
Easy to use :

Jedis Connection pool Code demonstration :

Redis thing :
边栏推荐
- How to operate DTC community?
- 双非大厂测试员亲述:对测试员来说,学历重要吗?
- Online interview, how to better express yourself? In this way, the passing rate will be increased by 50%~
- 微信论坛交流小程序系统毕业设计毕设(6)开题答辩PPT
- What is ADC sampling rate (Hz) and how to calculate it
- What does the model number of asemi rectifier bridge kbpc1510 represent
- Txt file virus
- 数据库每日一题---第22天:最后一次登录
- [network] Introduction to C language
- Line test - graphic reasoning -7- different graphic classes
猜你喜欢

微信论坛交流小程序系统毕业设计毕设(8)毕业设计论文模板

Transform XL translation

Are the microorganisms in the intestines the same as those on the skin?

Line test - graphic reasoning - 3 - symmetric graphic class

行测-图形推理-9-线条问题类

Innovation today | five key elements for enterprises to promote innovation

Two minutes, talk about some wrong understandings of MySQL index

Unity与WebGL的相爱相杀

微信论坛交流小程序系统毕业设计毕设(7)中期检查报告

Cascade-LSTM: A Tree-Structured Neural Classifier for Detecting Misinformation Cascades-KDD2020
随机推荐
行測-圖形推理-4-字母類
Transform XL translation
网络安全-钓鱼
一次搞明白 Session、Cookie、Token,面试问题全稿定
网络安全-安装CentOS
Early childhood education industry of "screwing bar": trillion market, difficult to be a giant
Force deduction - question 561 - array splitting I - step by step parsing
[language programming] exe virus code example
[network] Introduction to C language
Byte hexadecimal binary understanding
LeetCode142. Circular linked list II [two pointers, two methods for judging links in the linked list and finding ring points]
Cascade-LSTM: A Tree-Structured Neural Classifier for Detecting Misinformation Cascades-KDD2020
Database daily question --- day 22: last login
行测-图形推理-3-对称图形类
[record of question brushing] 3 Longest substring without duplicate characters
每日一题——PAT乙级1002题
Sword finger offer 27 Image of binary tree
Online interview, how to better express yourself? In this way, the passing rate will be increased by 50%~
行测-图形推理-1-汉字类
Years of summary, some core suggestions for learning programming




