“This is the second day of my participation in the Gwen Challenge in November. See details: The Last Gwen Challenge in 2021”
String type (string)
- String type use
set
Run the following command to execute the command- Store the string set
"juejin" "xiaoff"
- When you want to look up strings
get "juejin"
- We can also use internally wrapped functions such as
STRLEN
STRLEN "juejin"
— > 6
- Store the string set
redis
The string itself can be thought of as an array that can be dynamically expanded- For example you can see that
java
In theArrayList
In fact, it’s still space for time - A fixed length of capacity is allocated first
capacity
- The length of the string is called
length
whenlength
Is greater thancapacity
forresize
capacity - At most, each expansion will be expanded
1MB
The size of the space, but does not exceed the length of the string512MB
- For example you can see that
- You can also set the expiration time
- if
key
Will not automatically delete the expiration time - It can effectively control cache and improve efficiency
expire "juejin" 5
- Also can use
SETEX "juejin" 5 "xiaoff"
- A little
tips
Is that when thek-v
In thevalue
If it is an integer, increment is supported - Using the
incr {value}
- if
- In the elimination mechanism itself, all the Settings have been set
Time-out
Key ‘in a dictionary- Lazy delete: Delete it if it expires
- whileTime to deleteExpired scans are performed every 10 seconds
- I’ll pick a random number at a time
key
To delete - Actually on the inside
redis
Can do oneLRU
algorithm - Using linked lists will
key
Elements are sorted by time
- I’ll pick a random number at a time
Expired policies will be explained later in conjunction with asynchronous queues and Flush, which are currently described as the base type