Five basic data structures of Redis

Types of Introduction characteristic Scenes

String

(string)

binary safe Can contain any data, such as jpg images or serialized objects, a key can store up to 512M --

Hash

(dictionary)

A collection of key-value pairs, the Map type in programming languages It is suitable for storing objects, and can only modify a certain attribute value like updating an attribute in the database (Memcached needs to take out the entire string, deserialize it into an object, and then serialize it and save it back) Store, read, and modify user attributes

List

(list)

Linked List (Doubly Linked List)

LinkedList in java

Add and delete fast, provides an API for manipulating a certain segment of elements 1, the latest news ranking and other functions (such as the timeline of the circle of friends) 2, the message queue

Set

(gather)

Hash table implementation, elements are not repeated

1, the complexity of adding, deleting, and searching is O(1)

2. Provides operations such as intersection, union, and difference for sets

1, mutual friends

2. Use uniqueness to count all the independent IPs that visit the website

3. When the recommendation is easy to use, find the intersection according to the tag, if it is greater than a certain threshold, it can be recommended

Sorted Set Add a weight parameter score to the elements in the Set, and the elements are arranged in order by score When data is inserted into the collection, it has been naturally sorted

1, leaderboard

2, weighted message queue

 

Other usage scenarios

Types of characteristic Scenes
Subscription and publishing system Publish and subscribe, you can publish and subscribe to a key value. When a key value is published, all clients that subscribe to it will receive the message. Used as a real-time messaging system, such as ordinary instant chat, group chat and other functions
affairs

1. The Transactions of Redis are not strictly ACID (atomicity, consistency, isolation, durability) transactions, but provide basic command packaging and execution functions

2, Watch function, watch a key, and then execute Transactions. During this process, if the value of Watched is modified, Transactions will find and refuse to execute

--
Expired Set the expiration time of the key, after which the data will be automatically cleared login session or token

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324897041&siteId=291194637