当前位置:网站首页>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 512M
Pictured :
- 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 expenses
Pictured :
- 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?
- It's no exaggeration to say that this is the most user-friendly basic tutorial of pytest I've ever seen
- Line test - graphic reasoning - 3 - symmetric graphic class
- Brush question 3
- Debezium series: binlogreader for source code reading
- 行测-图形推理-7-相异图形类
- 双非大厂测试员亲述:对测试员来说,学历重要吗?
- Sword finger offer 63 Maximum profit of stock
- Understand the session, cookie and token at one time, and the interview questions are all finalized
- oc 可变參数传递
猜你喜欢
CTF exercise
Anta DTC | Anta transformation, building a growth flywheel that is not only FILA
行测-图形推理-8-图群类
行测-图形推理-2-黑白格类
Unity and webgl love each other
【刷题记录】3. 无重复字符的最长子串
ArcGIS:字段赋值_属性表字段计算器(Field Calculator)依据条件为字段赋值
行测-图形推理-6-相似图形类
ASEMI整流桥KBPC1510的型号数字代表什么
LeetCode206. Reverse linked list [double pointer and recursion]
随机推荐
De la famille debezium: SET ROLE statements supportant mysql8
iNFTnews | Web5 vs Web3:未来是一个过程,而不是目的地
数据库每日一题---第22天:最后一次登录
6-3 find the table length of the linked table
Are the microorganisms in the intestines the same as those on the skin?
Cascade-LSTM: A Tree-Structured Neural Classifier for Detecting Misinformation Cascades-KDD2020
Advantages and disadvantages of rest ful API
网络安全-安装CentOS
oc 可变參数传递
行测-图形推理-4-字母类
一次搞明白 Session、Cookie、Token,面试问题全稿定
2021-01-12
行测-图形推理-9-线条问题类
CTF exercise
定位到最底部[通俗易懂]
LeetCode203. Remove linked list elements
Txt file virus
About idea cannot find or load the main class
微信论坛交流小程序系统毕业设计毕设(1)开发概要
Line test - graphic reasoning - 2 - black and white lattice class