• 周六. 10 月 5th, 2024

5G编程聚合网

5G时代下一个聚合的编程学习网

热门标签

Redis learning notes (4) list data type

King Wang

1 月 3, 2022

 

Catalog

One .list The introduction and basic operation of types

Two .redis in list Storage structure of type

3、 … and .list Basic operation of type data

Four .list Type data extension operations

5、 … and .list Type of business scenarios using ( One )         

6、 … and .list Implementing business scenarios ( Two )           

7、 … and . list Type common solutions :


 

One .list The introduction and basic operation of types

       1.list type

                  Data storage requirements : Store multiple data , Also on The order in which data enters storage space Distinguish .

                  The required storage structure : A storage space needs to hold multiple data , And through the data can reflect Entry order

                  list type : Save multiple data , The bottom layer uses two-way linked list Storage structure implementation

       2. Array , Linked list , The concept of bidirectional linked list

              Array : Quick query , Slow insertion

              Linked list : Slow query , Insert fast

               One way linked list :

               

              Double linked list :

               

              If you come to a new node , The order of relevance :

              

             

              list It’s a two-way linked list structure

 

  Two .redis in list Storage structure of type

         1. Data storage requirements : Store multiple data , And the storage space order of data is distinguished

              redis Storage space

                  

                    Bi directional lists help build special businesses

                   ————————————–

 

                   —————————————

 

                  You can go left or right

                  Left and left out === Stack

                  Right in left out === queue

3、 … and .list Basic operation of type data

               ( Left head right tail )

       1. add to / Modifying data

                lpush key value1  value2 …            left Left precession

           

                rpush key value1 value2 …             right Right in

          

           2. get data

               lrange key  start  stop

            

               lindex  key index    Check the number of entries , From the index 0 Start

            

               LLEN    key Query queue list length

           

         3. Get and remove data

             lpop key  Get and remove a , Left out

            

             rpop  key  Get and remove a right out

            

      Example : Right in left out

            

   lrange list 0 -1 Show all the information

          

  Four .list Type data extension operations

        1. Get and remove data within a specified period of time

           blpop  key1 [key2]    timeout  Take left     If the list No element blocks the list until the wait times out or Until pop-up elements are found .

            If the list is empty , Return to one nil . otherwise , Returns a list of two elements , The first element is to be ejected The element belongs to key , The second element is The value of the ejected element .

             

           brpop  key1  [key2]    timeout On the right    If no element is ejected within the specified time , Returns a nil And waiting time .

          conversely , Returns a list of two elements , The first element is the one to which the pop-up element belongs key , The second element is the value of the element being popped .

             

           summary : Blocking version

            You can wait for data to be fetched , When there is data, it will return , When there is no data, it will be returned outside the specified time

    5、 … and .list Type of business scenarios using ( One )

            Business scenario 1:

                        Wechat friends praise , requirement In like order give the thumbs-up Show like friends information

                        If you cancel, like , Remove the corresponding friend’s information

                        Existing problems : how Take the data out of the middle

          Solution :

                      Remove the data from the specified location

                      lrem  key count value

                              key Team name    count Remove a few    value Which element to delete

                             

     tips 6: redis Application of data control with sequence of operations

    6、 … and .list Implementing business scenarios ( Two )

             ( One ).list Type data operation considerations

                  1.list The data stored in is Limited , And Are all String type , most 2^32  -1 Elements

                  2.list have Indexes The concept of , But when it comes to manipulating data , Usually in the form of a queue The team , Out of the team Operation or stack In the stack out of the stack The operation of

                  3.list Data can be paging , Usually The information on the first page comes from list. The second page and more information in the form of a database load

           ( Two ) Business scenario

                  1.twitter, Sina weibo , Tencent micro-blog , The attention of individual users The order To display , The fan list needs to put the most recent fans at the top of the list

                  2. News information website according to what happened Time sequence Exhibition

                  3. In the process of enterprise operation , Enterprises will produce a lot of operational data , How to guarantee the operation log of multiple servers Unified order Output

                Example :ELK Log system

              

           tips7:redis Apply to the display of the latest news

   

7、 … and . list Type common solutions :

           1. utilize list Data has a type of Sequence special To manage information

           2. Use queue The model solves multiple paths Information aggregation and consolidation The problem of

           3. Use Stack resolves the latest news The problem of

       

 

 

 

 

 

 

 

               

           

           

            

 

 

 

 

 

 

     

发表回复