Redis beginners: 4 (Common Redis commands)

Redis commonly used commands

View all keys

keys *

As shown below:

Insert picture description here

Insert key

set key value

As shown below:

Insert picture description here

Take out the value corresponding to the key

get key

As shown below:

Insert picture description here

Check whether a key exists

exists key

As shown in the figure below:

Insert picture description here


1 This key exists in the table, 0 means it does not exist

Determine what type of key is

type key

As shown below:

Insert picture description here

Delete the specified key data

  1. Regular deletion
del key

As shown below:

Insert picture description here
  1. Unconventional deletion
    Select non-blocking deletion based on value
unlink key

Function: Only delete the keys from the keyspace metadata, and the actual deletion will be performed in the subsequent asynchronous operation

Set expiration time for a given key

expire key 过期时间

As shown below:

Insert picture description here

Check how many seconds are left for the specified key to expire

ttl key

As shown in the figure below:

Insert picture description here


Final value: -1 means never expire, -2 means expired

Switch the database used

select 数据库名

As shown below:

Insert picture description here

Check how many keys are in the database

dbsize

As shown below:

Insert picture description here

Dedicated for deleting library and running road

  1. Clear all the contents of the current database
flushdb

As shown below:

Insert picture description here
  1. Clear the contents of all databases
flushall