The basic syntax of Redis data types

Redis data types

Redis data type-string

string

string: The simplest string type key-value pair cache, but also the most basic

key related

keys *: view all keys (not recommended for use in production, because of performance impact)
type key: the type of key

string type

get/set/del: query/set/delete
set rekey data: set the existing key, will overwrite
setnx rekey data: set the existing key, will not overwrite
set key value ex time: set the data with expiration time
expire key : Set the expiration time
ttl: view the remaining time, -1 never expires, -2 expires
append key: combined string
strlen key: string length
incr key: accumulate 1
decr key: class minus 1
incrby key num: accumulate a given value
decrby key num: decrement the given value
getrange key start end: intercept data, end=-1 means to the end
setrange key start newdata: replace data from the start position
mset: set the value
continuously mget: set the value continuously
msetnx: set continuously, Don't set if it exists

other

select index: switch database, a total of 16
flushdb by default : delete the data in the current lower db
flushall: delete all the data in the db

Redis data type-hash

hash

hash: similar to map, storing structured data structures, such as storing an object (cannot have nested objects)

use

hset key property value:
-> hset user name pqq
-> Create a user object, this object contains the name attribute, the name value is pqq
hget user name: get the value of name in the user object
hmset: set multiple key values ​​in the object on
-> User HSET Phone 139 123 123 Age 18 is
hmsetnx: setting a plurality of key-value pairs of objects, there are not added
-> User HSET Phone 139 123 123 Age 18 is
hmget: obtaining a plurality of object attributes
-> User Age hmget Phone
hgetall User : Get the content of the entire object
hincrby user age 2: Accumulate attribute
hincrbyfloat user age 2.2: Accumulate attribute
hlen user: How many attributes
hexists user age: Determine whether the attribute exists
hkeys user: Get all attributes
hvals user: Get all values
hdel user: Delete object

Redis data type-list

list

list: list, [a, b, c, d, …]

use

lpush userList 1 2 3 4 5: Build a list, store data from the left
rpush userList 1 2 3 4 5: Build a list, store data from the right
lrange list start end: Get data
lpop: start from the left
Take out a data rpop: take out a data from the right side
pig cow sheep chicken duck
llen list: list length
lindex list index: get the value of the
list subscript lset list index value: replace the value of a certain subscript with
linsert list before/after value : Insert a new value
lrem list num value: delete several identical data
ltrim list start end: intercept the value and replace the original list

Redis data type-zset

sorted set

sorted set: The sorted set can be sorted by removing duplicates. For example, it can be ranked according to user points, and the points can be sorted according to the value. Each memeber in the set has a

use

zadd zset 10 value1 20 value2 30 value3: set the member and the corresponding score
zrange zset 0 -1: view the content in all zset
zrange zset 0 -1 withscores: with score
zrank zset value: get the corresponding subscript
zscore zset value: Obtain the corresponding score
zcard zset: count the number
zcount zset score 1 score 2: count the number
zrangebyscore zset score 1 score 2: query the member between scores (including score 1 score 2)
zrangebyscore zset (score 1 (score 2: query) Member between scores (not including score 1 and score 2)
zrangebyscore zset score 1 score 2 limit start end: query the member between scores (including score 1 score 2), and the obtained result set is again based on the subscript interval to query
zrem zset value: delete member

Guess you like

Origin blog.csdn.net/pengyiccb/article/details/107118848