Redis set type, hash type, Zset (ordered set)-commonly used commands

Posted Jun 15, 20201 min read


  1. sadd myset "str"-insert data
  2. smenbers myset--View all data
  3. sismenber myset "str"--Check if str belongs to myset, return 1 if yes, 0 if no
  4. scard myset--returns the number of elements in myset
  5. srandmenber myset--randomly returns an element in myset
  6. srandmenber myset n--return n elements randomly
  7. Spop randomly deletes an element in myset
  8. smove myset myset "str"--Move the str element in myset to myset2
  9. sdiff myset myset2 - returns different elements in two sets
  10. sinter myset myste2 - returns the same element in two sets
  11. sunion myset myset2-returns the total elements of the two sets after merging



  1. hset myhash field value1 - add a data
  2. hget myhash field - get the value of the field
  3. hmset myhash field1 value1 field2 value2 - bulk insert data
  4. hmget mthash field1 field2 - batch get data
  5. hgetall myhash - get all field1 and value
  6. hdel myhash field1 - delete the specified hash field
  7. hlen myhash-returns how many values are in the hash
  8. hexists myhash field1 - determine whether field1 in myhash exists
  9. hkeys myhash - returns all fields
  10. hvals myhash - returns all values
  11. hincrby myshash field1 1--field1 increments by 1
  12. hdecrby myhash field1 1 --field1 decrement by 1
  13. hsetnx myshash field1 va1 - if field1 does not exist, add it, if it does, it cannot be added

Zset(ordered set)

  1. zadd myset 1 val1 - add data
  2. zrangebyscore myset -inf +inf --Display all data, from small to large
  3. zrangebyscore myset -inf +inf withscore-carry data
  4. To be continued. . . . .