Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Summary of common commands in redis

2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

Start redis:

Redis-server / etc/redis/redis-6379.conf

/ etc/init.d/redis start-- > binary installation

Turn off redis:

Redis-cli-p 6379 shutdown

You can also execute the shutdown command after entering redis-cli

Cluster View commands:

Cluster info: view information about this cluster

Cluster nodes: view the details of each node in this cluster

Other common commands:

Del: deletes the specified key

Flushdb: deletes all key in the current library

Flushall: clear all key of all databases

Keys *: displays all key in the current database and supports regular matching

Regular usage: * means to match any character,? It means to match one character, and [] means to match some characters.

Do not use this command when there is a large amount of key in a production environment, as it will cause redis blocking

Scan cursor: traversing all key progressively

When there are a large number of key,keys * commands in redis that may cause redis blocking, there is scan.

Usage: scan cursor [match pattern] [count number]

Cursor: is a required parameter, which is actually a cursor. The first traversal starts at 0 and returns the value of the cursor after traversal.

Match pattern: is an optional parameter that serves as pattern matching, similar to keys matching patterns

Count number: is an optional parameter. Its function is to indicate the number of keys to be traversed each time. Default is 10, which can be adjusted by itself.

When the final returned result is 0, the traversal ends

Scan effectively solves the problem of redis blocking.

Info: view information related to the current redis server

Dbsize: shows how many key are in the current database

Monitor: real-time monitor the request information of redis

Shutdown: after synchronizing the data to disk, close redis

Expire key seconds: sets the expiration time of a key (in seconds)

Persist key: clear the expiration time of key

Time: displays the current time

Ttl key_name: view the expiration time of the specified key:

-2: return-2 indicates that the key does not exist

-1: return-1 indicates that the key has not set the expiration time.

Greater than or equal to 0: returns greater than 0 indicates how many seconds it will expire

Pttl key_name:

-2: return-2 indicates that the key does not exist

-1: return-1 indicates that the key has not set the expiration time.

Greater than or equal to 0: returns greater than 0 indicates how many milliseconds will expire

Rename: rename the key. If the key of the new name already exists, the contents of the new key will be forced to be overwritten.

Example: set python jedis, set java redis.py

> rename python java-- > then the value of python is empty, and the value of java is jedis

Renamenx: if the name of the new key already exists, 0 is returned, which means the renaming is not successful, that is, the value of the existing key will not be overwritten

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report