当前位置:网站首页>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 :

  1. key Don't be too long. , Better not to exceed 1024 Bytes , This not only consumes memory, but also reduces lookup efficiency
  2. key Don't be too short. , If it's too short, it will decrease key Readability
  3. 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 :

  1. 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 :

  2. 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 :

  3. 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 :

  4. Ordered string collection  sorted sets
     
    1. 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 .

    2. for example : Game ranking 、 Microblog hot topics and other use scenarios .

    Pictured :

  5. 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 :

linke:Redis thing

原网站

版权声明
本文为[Scale biubiu]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202130600283291.html