Home > Database > Redis > Common commands for redis database

Common commands for redis database

下次还敢
Release: 2024-04-19 18:03:17
Original
848 people have browsed it

Commonly used commands in Redis include: data operations: SET, GET, DEL, INCR, DECR set operations: SADD, SMEMBERS, SREM, SUNION, SINTER list operations: LPUSH, LPOP, RPUSH, RPOP, LRANGE hash Operations: HSET, HGET, HDEL, HGETALL, HMGET Transaction commands: MULTI, EXEC, DISCARD Other common commands: PING, INFO, CONFIG GET/SET, FLUSHALL

Common commands for redis database

Redis Common Commands

Redis database is widely used for caching, messaging and database operations. The following are some commonly used Redis commands:

Data operation commands

  • SET key value: Set a key value pair.
  • GET key: Get the value of the specified key.
  • DEL key: Delete the specified key.
  • INCR key: Increment the value of the specified key by 1.
  • DECR key: Decrement the value of the specified key by 1.

Collection operation commands

  • SADD key member: Add a member to the collection.
  • SMEMBERS key: Returns all members in the collection.
  • SREM key member: Remove a member from the collection.
  • SUNION key1 key2: Returns the union of multiple sets.
  • SINTER key1 key2: Returns the intersection of multiple sets.

List operation commands

  • LPUSH key value: Push an element to the beginning of the list.
  • LPOP key: Pops an element from the beginning of the list.
  • RPUSH key value: Push an element to the end of the list.
  • RPOP key: Pops an element from the end of the list.
  • LRANGE key start stop: Returns the elements in the specified range in the list.

Hash operation command

  • HSET key field value: Set a key-value pair in the hash.
  • HGET key field: Get the value of the specified key from the hash.
  • HDEL key field: Removes the specified key from the hash.
  • HGETALL key: Returns all key-value pairs in the hash.
  • HMGET key field1 field2: Get the values ​​of multiple keys in the hash at the same time.

Transaction Command

  • MULTI: Start a transaction.
  • EXEC: Execute all operations in the transaction.
  • DISCARD: Discard all operations in the transaction.

Other commonly used commands

  • PING: Check whether the server is available.
  • INFO: Get server information.
  • CONFIG GET/SET: Get or set server configuration.
  • FLUSHALL: Clear all data in the database.

The above is the detailed content of Common commands for redis database. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template