This is the fifth day of my participation in the November Gwen Challenge. Check out the details: The last Gwen Challenge 2021.
Redis uses visual tools to connect
1. Download the visualization tool
Download Redis Desktop Manager this is my web disk
Link: pan.baidu.com/s/1DsIXeM2M…
Extract code: 45JO Copy this section of content after opening Baidu web disk mobile App, more convenient operation oh
2. Centos open port
- Open port
firewall-cmd --zone=public --add-port=6379/tcp --permanent
Copy the code
- restart
firewall-cmd --reload
Copy the code
- Check the enabled port
firewall-cmd --list-ports
Copy the code
3. Set a password
- Open the redis. Conf
vim ./redis.conf
Copy the code
- Find a requirepass
/requirepass
Copy the code
- Add a password
requirepass 123456
Copy the code
- Attention!!!!!
Be sure to comment out the bind attribute
4. Connect
Address fill in the address, auth fill in the password, test the connection first, and then click OK
Redis command about key
- keys
Function: Returns the key that meets the condition, which can be used for fuzzy matching (the string of fuzzy matching can be added before and after *).
Keys * Fuzzy query criteriaCopy the code
- exists key
Returns 1 if the specified key exists, and 0 if the specified key does not exist.
The name of the exists keyCopy the code
- expire key second
Function: Set the key expiration time, in seconds.
Expire key name in how many secondsCopy the code
- PEXPIRE key milliseconds
Used to set the key expiration time in milliseconds:
Pexpire key name in how many millisecondsCopy the code
- del key
Delete the specified key using:
delKey the name of theCopy the code
- ttl key
If the key does not exist, -2 is returned. If the key exists and the expiration time is not set, -1 is returned. If the expiration time is set and the key exists, the remaining time is returned.
TTL key nameCopy the code
- persist key
Function: Cancel expiration time use:
The name of the persist keyCopy the code
- select
Select database, starting from 0, default is the 0th database used:
select 0
Copy the code
- move key dbindex
Transfer a key from the current database to another database for use:
moveKey the name of the0
Copy the code
- randomkey
Returns a random key using:
randomkey
Copy the code
- rename key1 key2
Rename key using:
Rename Key Name Indicates the new name of the keyCopy the code
- dbsize
To view the number of keys in the current data, use:
dbsize
Copy the code
- info
Function: View database information using:
info
Copy the code
- flushdb
Action: Empty the current database using:
flushdb
Copy the code
- flushall
Action: Empty all databases using:
flushall
Copy the code
- config get *
Get database configuration using:
config get *
Copy the code
Redis transactions
A brief introduction.
Redis transactions can execute multiple commands at a time, sequential execution, execution is not allowed to insert other commands do not support transaction rollback encountered syntax error, will skip the error command, continue to execute other commands encountered command error (input command does not exist), will cancel the transaction
Common commands
- Multi: Marks the start of a transaction
- Exec: Executes all transaction inland commands
- Discard: Cancels a transaction
- Watch Key: Monitors the key and interrupts the transaction if it is changed by another command before the transaction executes
- Unwatch: Unwatches the key
3. Using commands
watch key# listen on a key and cancel it automatically after the transaction ends
unwatch key# unlisten on a key
mutil# start transaction
Enter some commands for data manipulation
exec# commit transaction
Or discard cancel transaction
Copy the code
4. Application scenarios
A set of commands is required to execute simultaneously, or no shopping is performed