This article takes you to the Redis operation guide

Abstract: Redis is a storage system that supports multiple data structures such as Key-Value.

Redis is a storage system that supports multiple data structures such as Key-Value. It can be used for caching, event publishing or subscription, high-speed queues and other scenarios. The database is written in ANSI C language, supports the network, provides direct access to strings, hashes, lists, queues, and collection structures, based on memory, and can be persisted.

Redis has three main features that make it superior to other key-value data storage systems: Redis stores its database completely in memory and only uses disk for persistence; compared with other key-value data storage, Redis has a relatively rich set of data Type; Redis can copy data to any number of slaves.

Redis supports a total of five data types: string (string), hash (hash), list (list), set (collection) and zset (sorted set). These data types support push/pop, add/remove and intersection, union and difference, and richer operations, and these operations are all atomic.

Redis is an open source written in C language (more than 30,000 lines of code), supports the network, can be based on memory and can be persisted log type, Key-Value database, and provides APIs in multiple languages. The emergence of Redis software has made up for the lack of key-value memory caching services such as memcached to a certain extent, and can play a very good role in supplementing relational databases in some cases. Redis provides Python, Ruby, Erlang, and PHP clients. Next, I will bring you a guide to Redis.

1. Start and close

  • Load the configuration file to start
    Redis-server Redis.conf
  • Close Redis, the Redis server will disconnect from the client, generate a persistent file, and close it smoothly. The kill pid number is the same.
    Do not use kill -9 to force a kill. This will not make persistence, and it will also cause the buffer and other resources to not be gracefully shut down. In extreme cases, AOF and replication will lose data.
    Redis-cli shutdown
  • Link to Redis server -h address -p port -c means to link to a cluster
    Redis-cli -h 127.0.0.1 -p 7000
  • Link to Redis server, non-interactive operation. Add the command at the end to get name
    Redis-cli get name
  • Display the key value of the big one
    Redis-cli --bigkeys
  • View statistics
    Redis-cli --stat

2. Basic operation

  • The query displays all keys. Only valid data, not expired. If the amount of data is very large, do not use this command, it will cause the memory to be stuck.
    keys *
  • Query the number of all keys, not destroyed. (Expired ones are counted)
    dbsize
  • View the
    client list of linked clients
  • Kill client link
    client kill 127.0.0.1:52343
  • View
    1. The current number of client connections
    2. The current maximum number of queue objects in all output buffers
    3. The current maximum capacity occupied in all input buffers
    4. Blocking commands (such as blpop, brpop, brpoplpush) are being executed The number of clients.
    info clients
  • View various detailed information
    info
  • Query storage file directory
    CONFIG GET dir
  • Check if the key exists. Exists 1, does not exist 0
    exists key
  • Delete key, you can delete multiple keys at the same time
    del key
  • Set the expiration time for the key value. Unit second, 1 is successful, 0 is unsuccessful
    expire key 10
  • View the remaining expiration time of the key. Return -2 key does not exist, -1 is not set, more than 0 is the remaining time
    ttl key
  • View the key data structure type. Return none is the key does not exist
    type key
  • Check the internal encoding format
    object encoding key
  • Rename the key. If newkey already exists, the value will be overwritten.
    rename key newkey
  • Rename the key. If the newkey already exists, the operation will fail, return 0 and do nothing.
    renamenx key newkey
  • If there are 1000 key:values, a key
    randomkey will be returned randomly

Recently, Huawei Cloud Database released GaussDB (for Redis) for commercial use. GaussDB (for Redis) is a cloud-native NoSQL database based on Huawei’s self-developed computing and storage separation architecture, compatible with the Redis ecosystem, and strong consistency among multiple copies based on shared storage pools. Mechanism to ensure the safety and reliability of data. GaussDB (for Redis) can be widely used in games, Internet, e-commerce and other scenarios.

#DevRunDeveloper Salon# On October 27, 20:00-21:00, Huawei Cloud Database Technical Expert Wenlong & Ecological Director Zhang Yiyi are specially invited to create a special live broadcast "When Redis Meets Computing and Storage Separation" for you ! Huawei Cloud GaussDB (for Redis) utilizes advanced technology concepts such as separation of storage and computing, multi-mode architecture, and strong consistency to provide a set of industry-leading advanced solutions.

Community interactions are gifted, don’t miss it!

 

Click to follow and learn about Huawei Cloud's fresh technology for the first time~

Guess you like

Origin blog.csdn.net/devcloud/article/details/109284286