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

  1. Open port
firewall-cmd --zone=public --add-port=6379/tcp --permanent
Copy the code
  1. restart
firewall-cmd --reload
Copy the code
  1. Check the enabled port
firewall-cmd --list-ports
Copy the code

3. Set a password

  1. Open the redis. Conf
vim ./redis.conf
Copy the code
  1. Find a requirepass
/requirepass
Copy the code
  1. Add a password
requirepass 123456
Copy the code
  1. 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

  1. 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
  1. 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
  1. expire key second

Function: Set the key expiration time, in seconds.

Expire key name in how many secondsCopy the code
  1. PEXPIRE key milliseconds

Used to set the key expiration time in milliseconds:

Pexpire key name in how many millisecondsCopy the code
  1. del key

Delete the specified key using:

delKey the name of theCopy the code
  1. 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
  1. persist key

Function: Cancel expiration time use:

The name of the persist keyCopy the code
  1. select

Select database, starting from 0, default is the 0th database used:

select 0
Copy the code
  1. move key dbindex

Transfer a key from the current database to another database for use:

moveKey the name of the0
Copy the code
  1. randomkey

Returns a random key using:

randomkey
Copy the code
  1. rename key1 key2

Rename key using:

Rename Key Name Indicates the new name of the keyCopy the code
  1. dbsize

To view the number of keys in the current data, use:

dbsize
Copy the code
  1. info

Function: View database information using:

info
Copy the code
  1. flushdb

Action: Empty the current database using:

flushdb
Copy the code
  1. flushall

Action: Empty all databases using:

flushall
Copy the code
  1. 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

  1. Multi: Marks the start of a transaction
  2. Exec: Executes all transaction inland commands
  3. Discard: Cancels a transaction
  4. Watch Key: Monitors the key and interrupts the transaction if it is changed by another command before the transaction executes
  5. 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