Redis common commands (five basic types)

Database switching
select 16 ## A total of 16 libraries 0-15
view the current database
set table name value ## add a data
get table name ## value
keys * ## view all keys
flushdb delete the current library – the premise is to enter the current database
flushall delete all libraries
set expiration time expire table name seconds
check expiration time ttl
check key
type type key
check if key exists
exists key

String type
Value: set get append strlen
Addition and subtraction operations: incr auto increment 1 decr auto decrement 1
incrby fixed increment custom
decrby fixed decrement custom
Example: incr table name
decr table name
incrby table name fixed value
decrby table name fixed Value
range operation: getrange key index1 index2 Get the current specified range if the maximum length index2 can be replaced by -1
Replacement operation: setrange key offset index content ##offset The offset specifies the position to start replacement
Judging whether it exists: exists t6
setex key time v both It can increase the expiration time and re-assign a new value. If the current key does not exist, create a new key and value and specify the
expiration time.
Batch operation: more set
mset k1 v1 k2 v2
mget k1 k2
Example: mset b 123 c 123 d 123
mget abcd
storage object: set user {id: 1, name: zhangsan, age: 40}
value assignment operation: getset first fetches value, then assigns value
Floating point type increase and decrease operation: add byfloat
table name floating point number after incr decr
to delete Data: del key

List type
left insertion value: lpush
right insertion value: rpush
query data: lrange key start end
acquisition length: llen key
deletion: del key
left popup: lopo count
right popup: ropo count
delete specified value: list remove
intercept part of the list value: ltrim key start end
get index data: index key index
replacement value: lset key serial number replacement name

Set
added value: sadd key v...
Query value: smember member, composition
Delete specified element: srem key value
Judging whether the specified value exists in the current set: sismember key v
View the number of current set: scard key
Random deletion: spop key count
difference set :

127.0.0.1:6379> sadd zb1 xiaozhi dasima caixukun lijiaqi
4
127.0.0.1:6379> sadd zb2 liziqi xiaozhi dasima wangdaxian xuxubaobao
5
127.0.0.1:6379> sdiff zb1 zb2
caixukun
lijiaqi
127.0.0.1:6379> sdiff zb2 zb1
wangdaxian
liziqi
xuxubaobao
127.0.0.1:6379>

intersection sinter

127.0.0.1:6379> sinter zb2 zb1
dasima
xiaozhi

union

127.0.0.1:6379> sunion zb1 zb2
lijiaqi
dasima
xuxubaobao
xiaozhi
caixukun
wangdaxian
liziqi

Zset type
Add and query
zadd
Example: 127.0.0.1:6379> zadd emps 8000 {id:1,name:zhangsan,sal:8000}
Delete: del key
Complex query: #Display all information, from small to large (range) -inf Negative infinity + inf positive infinity
Syntax: ** z range by score ** key min max — min max uses the value of the sort field

127.0.0.1:6379> zrangebyscore emps 8000 10000
{
    
    id:1,name:zhangsan,sal:8000}
127.0.0.1:6379> zrangebyscore emps -inf +inf
{
    
    id:2,name:lisi,sal:5000}
{
    
    id:1,name:zhangsan,sal:8000}
{
    
    id:3,name:wangwu,sal:12000}

Guess you like

Origin blog.csdn.net/weixin_52859229/article/details/129867086