当前位置:网站首页>Redis basic commands and types

Redis basic commands and types

2022-06-25 01:20:00 Lutrra

Basic commands

keys *
type name 
set name lutrra
get name 
mv name 1
ttl 
exist name 
expire name 10
flashdb

type

String

append name "hello"  # Append string 
srtlen name # Check the length 

# Addition and subtraction 
set views 0
incr views # Add 
decr view # reduce 

incrby views 10# Add 10
decr views 10 # reduce 10

# String range 
set name "lutrra"
getrange name 0 3 #0-3
getrange name 0 -1 # Intercept all 


# Replace 
setrange name 1 xx # hold key by name  Replace 1 Starting string 

#
setex #( There is )  Set it up 
setnx #( non-existent )  Set up 

# Set multiple values 
mset k1  v1 k2 v2 k3 v3 
mget k1 k2 k3 
msetnx k1 v1 k4 v4 # Or make it together , Or fail together 

# object 
set user:1 {
    name:zhang,age:3} # Set an object   The value is json  preservation 

mset user:1:name zhangsan user:1:age 2
mget user:1:name user:1:age

#key The design of the 
#user:{id}:{filed}

# Combination order 
getset # First get Again set 
getset db redsi

list

lpush list one # Place one or more values from the left 
lrange list 0 -1
lrange list 0 1

rpush list right # Put... From the right 

lpop list # Remove the first... In the current list 
rpop list # Remove the last element of the list 

lindex list 1 # Get the first value by subscript 
rindex list 1 

Llenlist # Return length 

lrem list 1 one # Remove the specified value   Remove one of them one 

trim # trim  
ltrim list 1 2

rpoplpush  list otherlist# Move to new list 

exist list 

lset # Replace the value of the list subscript with another value 

linsert  list before "hh" # Insert forward 
linest list after "jj" # Insert after 

set

sadd myset hello # Additive elements 
smembers myset  # Check all values 
smember myset hello # Judge whether it is set in 

scard myset # obtain set The number of elements in the collection 

srem myset hello # remove 

set# Disorder does not repeat 

srandmember myset # Random sampling 
srandmember myset 2# Random sampling 2 individual 

# Delete specified key
spop myset # Random delete 
smove myset myset2 "kuangshen"#  Move the specified element 

# Difference set 
sdiff key1 key2
# intersection 
sinter key1 key2
# Combine 
sunion key1 key2

Hash

hset myhash filed1 lutrra # Storage 
hget myhash filed1 # Value 
mset muhash filed1 hello filed2 world #hmset 4.0 obsolete 
hgetall myhash # Query all 
hdel myhsah filed # Delete specified key

hlen myhash # Get the number of hash tables 
hexist myhash  filed1# Determine whether the specified field of the hash exists 
hincr hdecr 
hsetnx

hset user:1

zset

# stay set Add sorting on the basis of 
zadd myzset 1 one 
zadd myzset 2 two 
zrange myset 0 -1
# Sort 
zadd salary 2500 zs
zadd salary 5000 xh
zadd salary 100 xx
#min max
zrangebyscore salary -inf +inf 
zrangescore salary -inf +inf withscores
# Remove elements 
zrange salary 0 -1
zrem salary xx
# Check out the elements   Get the number of ordered sets 
zcard salary
# reverse 
zrevrange salary 0 -1
# Get the number of members in the specified interval 
zcount salary 1100 6000

geospatial

# Determination of geographical location 
# longitude , latitude 
geoadd china:city 116.40 39.90 beijing
geoadd china:city 121.47 31.23 shanghai
geoadd china:city 106.50 29.53 chongqing
# Get the longitude and latitude of the specified city 
geops china:city beijing 
# The distance between the two 
geodist china:city beijing shanghai km
# The man near the   Centered on a given latitude and longitude , A radius search  withcoord count 
georadius china:city  110 30 1000 km
georadiusbymember china:city beijing 100km 
# return hash  length   Convert two-dimensional latitude and longitude to one-dimensional string 
geohash china:city beijing shanghai
# see 
zrange china:city 0 -1
zrem china:city beijing

hyperloglog

# Base Statistics 
pfadd mykey a b c d
PFCOUNT mykey
PFadd mykey2 i j k
PFMERGE mykey3 mykey mykey2

bitmaps

# Bit storage   Count the number of people  01 Statistics 
# Monday to Sunday  0 1 2 3 4 5 6 
setbit sign 0 0
setbit sign 1 1
setbit sign 2 0
setbit sign 3 0
setbit sign 4 0
setbit sign 5 0
setbit sign 6 0

# see 
getbit sign 6
# Statistics 
bitcount sign

原网站

版权声明
本文为[Lutrra]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202210541309530.html