I. GENERAL Command
1. Keys traverses all keys
Generally not used in production environments
2, the total number of Dbsize key
3. Exists key
4. del key Delete specified key-value
5, expire key secods set how many seconds expired
How many seconds of TTL are left to expire
Persist Cancel Expiration Time
6. Type Return key
Second, single thread
Only one command can be executed at a time
Reject long slow commands (keys, etc.)
Why is a single thread so fast?
1, pure memory (main)
2. Non-blocking IO
3. Avoid thread switching and race consumption
Third, the data type
1. String
Type: Can save string, Integer, binary, JSON, etc.
Size: Can save 512M
Scenario: Cache, counter
Command:
1.1, get, set, Del
1.2. Set K v whether or not K exists, all sets
Setnx K v K does not exist before setting
Set K v xx k exists only setting
1.3. mset Batch Setup
Mget Bulk Acquisition
1.5
Getset key NewValue sets a new key and returns the old value
Append key value appends value to the old value
Strlen Key returns the length of the string (note Chinese)
1.6
Incrbyfloat increasing floating-point numbers
GetRange get string to make all values subscript
SetRange sets the value of the specified subscript
1.7, suitable for doing counter, single process without competition
INCR self-increment 1 if key does not exist for 1
DECR minus 1 If key does not exist as-1
Incrby self-increment k, if key does not exist for K
Decrby-minus key if key does not exist as-K
Usage Scenarios: Caching apps
2. Hash
A key that corresponds to the structure of multiple key values can be understood as a small redis
The hash API operation starts with H
2.1, Hset, Hget, Hdel
2.2
Hexists Key Exists field
Total number of field in Hlen key
2.3
Hmget Bulk Acquisition
Hmser Batch Setup
2.4
Hgetall
2.5, Hsetnx, Hincrby, hincrbyfloat
Usage Scenarios
Count the number of visits per user's personal page
Hincrby User:1:info PageView Count
Cache Storage Video Basic information
Programming Comparison:
First: Serialize the whole data into a string
The second type: Store data in a string, respectively
The third type: depositing data into a hash
4. List
Orderly, repeatable, left and right sides can be inserted pop-up
The list API starts with L
4.1, increase
Rpush Insert from right
Lpush Insert from left
Linsert key Before|after value newvalue inserting data before and after the specified value
4.2. By deleting
Lpop Popup from left
Rpop from right.
Lrem Key count value removes all values equal to Balue from the list, based on the count values
4.3. Check
Lrange
Lindex
Llen
4.4, change
LSet
4.5. Leak-Checking and vacancy
Blpop
Brpop
4.6. Usage Scenarios
Weibo timeline
4.7. TIPS
1, Stack
2. Queue
3, a fixed number of lists
5. Collection
Cannot repeat, unordered, and support inter-collection operations within a collection
5.1. Inside the Set
Usage Scenarios
Can be used in the likes, the lottery.
5.2. Inter-Collection
Usage scenarios:
Common concern, common fans
6. Ordered set
Characteristics:
Api
6.1. Zadd add Element
6.2. Zrem Delete Element
6.3, Zscore get the score
6.4. Zincrby increase or decrease the score
6.5, Zcard returns the total number of elements
Instance:
6.6. Zrange returns the ascending element in the specified index range
6.7. Zrangebyscore returns the ascending element that formulates the fractional range
6.8, Zermrangebyrank
6.9, Zremrangbyscore Delete the ascending element of the specified fraction
Usage Scenarios: Leaderboards
Common APIs for Redis data types and usage scenarios