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

Posted Jun 15, 2020 • 1 min read

## set

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

## Hash

Format:key-field-value

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

## Zset(ordered set)

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

Related Posts