Home >Java >javaTutorial >What is the method for integrating Redis in java SpringBoot project?
Redis is completely open source, complies with the BSD protocol, and is a high-performance key-value database.
Redis has the following three characteristics with other key-value cache products:
Redis supports data persistence. It can save the data in the memory to the disk and load it again for use when restarting.
Redis not only supports simple key-value type data, but also provides storage of data structures such as list, set, zset, and hash.
Redis supports data backup, that is, data backup in master-slave mode.
Extremely high performance– Redis can read at a speed of 110,000 times/s and write at a speed of 81,000 times/s s
Rich data types - Redis supports String, List, Hash, Set and zset data type operations in binary cases.
Atomic – All operations of Redis are atomic, which means that they are either executed successfully or not executed at all. Individual operations are atomic. Multiple operations also support transactions, that is, atomicity, wrapped by the MULTI and EXEC instructions.
Rich features– Redis also supports publish/subscribe, notification, key expiration and other features
Redis is single-threaded, 6.0 This version supports enabling multi-threading.
Decompress the downloaded compressed file. The decompressed file list is as follows:
Use cmd window to open Redis
redis-server.exe redis.windows.conf #加载配置文件启动
Note: After starting, do not close the window, the service will stop when you close the window!
Install the Redis database client
##Library related instructions:
flushdb 清空当前库 flushall 清空所有库 select 1 切换库
Key related instructions
Function | Syntax | |
---|---|---|
del | Delete one or more keysdel keyname | |
exists | Determine whether one or more keys exist. If one of multiple keys exists, 1 will be returned.exists keyname | |
expire | Set the key survival time unit: secondsexpire keyname seconds | |
keys | Query all keys matching the pattern? Match one character * Match 0-n characters [] Meet one of thekey * key h?llo | |
move | Move the key to the specified librarymove keyname db | |
Set the key's survival time Unit: millisecond setting returns 1 if successful, otherwise returns 0 | pexpire keyname milliseconds | |
Return key in seconds The remaining survival time, returns -1 for permanent storage, -2 for key does not exist | ttl keyname | |
Return a random key from the current database | randomkey | |
Rename the key and return ok successfully. Otherwise, an error message is returned. | rename key newkey | |
Return the type of value stored in key | type keyname |
Command | Description |
---|---|
SET | Set the value of the specified key |
GET | Get Specify the value of key. |
GETRANGE | Returns the subcharacters of the string value in key |
GETSET | Set the value of the given key to value and return the old value of the key. |
SETEX | Associate value value to key and set key's expiration time to seconds (in seconds). |
SETNX | Set the value of key only when the key does not exist |
STRLEN | Returns the length of the string value stored in key. |
MSET | Set one or more key-value pairs at the same time. |
MSETNX | Set one or more key-value pairs simultaneously, if and only if all given keys do not exist |
INCR | Increase the numerical value stored in the key by one |
INCRBY | Add the given increment value (increment) to the value stored in the key |
##INCRBYFLOAT | Add the key The stored value is added to the given floating point increment value (increment)|
DECR | Decrease the numeric value stored in key one.|
DECRBY | The stored value minus the given decrement|
APPEND | If the key already exists and is a string, the APPEND command will append the specified value to the end of the original value of the key
Description | |
---|---|
Set a key/value pair | |
Get the value corresponding to the key | |
Get all key/value pairs | |
Delete a key/value pair | |
Determine whether a key exists | |
Get all keys | |
Get all values | |
Set multiple key/value | |
Get the value of multiple keys | |
Set the value of a non-existent key | |
Perform addition operation for value value | |
Perform addition operation for floating point type value for value value |
Command | Description |
---|---|
##LINDEX | Get the elements in the list by index lindex lists 0|
LINSERT key BEFORE|AFTER | Insert elements before or after the elements in the list|
LLEN | Get the length of the list|
LPOP | Move out and get the first element of the list|
LPUSH | Insert one or more values into the head of the list|
LPUSHX | Insert a value into theexisting list header |
LRANGE | Get the elements within the specified range of the list (0 -1)|
LREM | Remove duplicate elements from the list|
LSET | Set the value of the list element through the index, but the index must exist. The essence is to modify the value based on the index|
LTRIM | Trim a list, that is, let the list only retain elements within the specified range, and elements that are not within the specified range will be deleted|
RPOP | Remove the last element of the list, the return value is the removed element|
RPOPLPUSH | Remove the last element of the list and add that element to another list and return|
RPUSH | Add in list One or more values|
RPUSHX | Add a value to an existing list
Description | |
---|---|
Add elements to the collection | |
Display all elements in the collection (unordered) | |
Return the number of elements in the collection | |
Return an element randomly and delete this element | |
Transfer elements from a set to a set | |
From a set Delete an element from | |
Determine whether the set contains this element | |
Randomly Return an element | |
Find the intersection | |
Find the sum set |
Redis ZSet and Set It is also a collection of String type elements, and duplicate members are not allowed.
double type of score. Redis It is through scores that the members in the set are sorted from small to large. The members of
ZSet are unique, but the scores can be repeated.
Description | |
---|---|
Add an ordered set element | |
Return the number of elements in the set | |
Return elements within a range | |
Find elements within a range by score | |
Return to ranking | |
Flashback ranking | |
Display the score of an element | |
Remove an element | |
Add points to a specific element |
The above is the detailed content of What is the method for integrating Redis in java SpringBoot project?. For more information, please follow other related articles on the PHP Chinese website!