当前位置:网站首页>Introduction to redis and explanation of data types
Introduction to redis and explanation of data types
2022-07-03 05:09:00 【amateur12】
Official website
Official website :http://www.redis.cn/
Concept
Open source high performance key value pair database
16 A database
Port number 6379
( The range of port numbers is from 0 To 65535
1023 The following ports have been assigned to some commonly used applications )
Enter the client
redis-cli
password
Check the password :CONFIG get requirepass
Set the password :CONFIG set requirepass "123456"
Input password :AUTH "123456"
data type
Basic data type :string,hash,list,set,zset
Special data types :Geo,Bitmap,Hyperloglog
character string :string
It's simple. Key-Value type
What is the maximum storage capacity of a string type value ? 512M
scene : Distributed lock , Distributed session, seckill , Count
set key val
get key
mget key key key
del key
incr key: Self increasing
decr key: Self reduction
incrby key 3: Self increasing 3
decrby key 3: Self reduction 3
keys *: View all key
Hash :hash
yes string Type of key and val Mapping table , Hash hash hash table
scene : Store object data ( User information )
hset Hash name Key name value
hget Hash name Key name
hmset Hash name Key name value Key name value
hmget Hash name Key name Key name
hgetall Hash name : Get all the key names and values in this hash
hkeys Hash name : Get all the key names in this hash
hvals Hash name : Get all the values in this hash
hdel Hash name Key name
hexists Hash name Key name : Does the key exist , return 1 or 0
hincryby Hash name Key name 3: Self increasing 3
list :list
Store multiple ordered strings
scene : Render article list , In general, each user will have their own list of published articles , If you need to show a list of articles , You can use List data type , Not only can the list of articles be ordered but also can be queried according to the index range .
rpush List name value value : take One or Multiple value push list Of Right end
lpush List name value value : take One or Multiple value push list Of Left side
rpop List name : move except and return list most Right end Of Elements
lpop List name : move except and return list most Left side Of Elements
lindex List name Subscript : Returns the value of the specified subscript in the list ( Subscript from 0 Start )
lrange List name Start subscript End subscript : Returns the value of the specified subscript range in the list
ltrim List name Start subscript End subscript : Only keep the value of the subscript range
blpop List name List name Number of seconds : Move at the specified time except and return The first non empty list most Left side Of Elements
rpoplpush List name List name : Pop up the right most element from the first list , Put this element Push the leftmost end of the second list
brpoplpush List name List name Number of seconds :rpoplpush Blocking version of , It will not end until the specified number of seconds
unordered set :set
Duplicate elements are not allowed , And it's out of order
scene : Record unique value : For example, login. ip, ID number . Add tags : Calculate user preferences and other data through the intersection and union of labels , Common friends .
sadd Collection name value value
srem Collection name value value : Delete one or more values
sismember Collection name value : Check whether the value exists in the set
scard Collection name : Returns the number of values in the set
smembers Collection name : Return all values in the set
srandmember Collection name 3: Return randomly from the set 3 Elements .(3 Is a positive number , The returned element will not repeat ; If it is -3, The random elements returned may be repeated )
spop Collection name : Delete one at random
smove Collection name Collection name value : Move a value from the first set to the second set
sdiff Collection name Collection name Collection name : Get existence and the first set , But there is no value with other sets ( Subtraction operation )
sdiffstore Specify the collection name Collection name Collection name Collection name : Will exist with the first set , But there is no value with other sets moved to the specified set
sinter Collection name Collection name Collection name : Get the values of all sets that exist at the same time ( Intersection operation )
sinterstore Specify the collection name Collection name Collection name Collection name : Move the values of all sets that exist at the same time to the specified set
sunion Collection name Collection name Collection name : Get the values of all sets ( Union operation )
sunionstore Specify the collection name Collection name Collection name Collection name : Move the values of all sets to the specified set
Ordered set :zset
A set of ordered data with unique key value pairs
scene : Ranking List : According to the integral order from small to large . Get a range of data : The test 80-100 Minute data
zadd Collection name score value value score value value
zrem Collection name value value : Delete
zremrangebyrank Collection name End value Starting value : Delete the value of the set ranking between a certain range
zremrangebyscore Collection name End value Starting value : Delete the collection score Values between certain ranges
zincrby Collection name 3 value : Give a set of values score Add 3
zcard Collection name : Number
zcount Collection name Starting value End value : Get a collection score The number of values in a certain range
zscore Collection name value : Get a value in the set score value
zrank Collection name value : Get the ranking of a value in the set ( from 0 Start )( The smallest ranking is 0)
zrevrank Collection name value : Press score Values range from large to small , Get the ranking of a certain value
zrange Collection name Starting value End value withscores: Get the value of the set ranking between a certain range ( From small to large ), If you add withscores, Will also get score value
zrevrange Collection name Starting value End value withscores: Get the value of the set ranking between a certain range ( From big to small ), If you add withscores, Will also get score value
zrangebyscore Collection name Starting value End value withscores limit Start subscript End subscript : aggregate score Values between certain ranges ( From small to large ), If you add withscores, Will also get score value , If you add limit Start subscript End subscript , Is to get the value of a range based on the order , You can perform paging query
zrevrangebyscore Collection name End value Starting value withscores Start subscript End subscript : aggregate score Values between certain ranges ( From big to small ), If you add withscores, Will also get score value , If you add limit Start subscript End subscript , Is to get the value of a range based on the order , You can perform paging query
zinterstore Specify the collection name The number of subsequent set names Collection name Collection name : Intersection of evaluation , Then save the intersection result in the specified set (score Values are added )
zunionstore Specify the collection name The number of subsequent set names Collection name Collection name : Evaluation union , Then save the union result to the specified set (score Values are added )
Location :Geo(Geospatical)( Version for :Redis3.2)
GEO The underlying implementation principle is actually Zset, We can use Zset Command to operate GEO
scene : location 、 Check out the people around 、 Friends' positioning 、 Taxi distance calculation
geoadd Collection name longitude dimension Place names longitude dimension Place names
geopos Collection name Place names : Returns the position of all the given location elements ( Longitude and latitude )
geodist Collection name Place names Place names Company : Returns the linear distance between two given positions ( The default unit is m, The unit also has km mi( miles ) ft( Inch ))
georadius Collection name longitude latitude radius Company withdist withcoord withhash asc/desc count 2: Centered on a given latitude and longitude , Find the elements in a certain radius (withdist Is to return the distance between the position element and the center )(withcoord Is to return the longitude and dimension of the location element together , That is, display the location information of others )(withhash In order to 52 Bit signed integer form , Return the location element through the original geohash Encoded ordered set score . This option is mainly used for underlying applications or debugging , It doesn't really work .)(asc/desc:asc According to the position of the center , Return the location element in a near to far way ,desc According to the position of the center , Return the location elements from far to near )(count 2 Is to designate several places to return )
georadiusbymember Collection name Place names radius Company : Find the elements in the specified range , The center point is determined by a given location element ( Take the current place name as the center , Find the elements within the radius )
geohash Collection name Place names Place names : Returns the... Of one or more positional elements Geohash character string ( Convert two-dimensional latitude and longitude into one-dimensional string , If the two strings are closer , So the closer we get )(11 Characters )
Bitmap scene :Bitmap
Bitmap It's a bitmap , data structure , It's all operating bits to record , Only 0 and 1 Two states
scene : Statistics user information 、 active 、 Inactive 、 Sign in 、 Not logged in 、 Punch in and wait … Both states can be used Bitmap
setbit Collection name Key name value :( The value can only be 0 perhaps 1)
getbit Collection name Key name : Get the value of a key in the collection
bitcount Collection name : Get the value in the set as 1 The number of keys of
Base Statistics :Hyperloglog
The number of non repeating elements in a repeatable set is the cardinality
The traditional way : Use set Protect the user's ID, And then you can count set The number of elements in as a standard judgment , This way, if you save a large number of users id, It will be more troublesome . Our purpose is to count , Instead of storing users id.
advantage : The memory occupied is fixed ,2^64 Technology of different elements , It only costs 12KB Memory . If you want to compare from the memory point of view ,Hyperloglog First choice
If fault tolerance is allowed , Then be sure to use Hyperloglog; If fault tolerance is not allowed , Just use set Or your own data type .( Fault tolerance is when data appears in the system for various reasons 、 When the file is damaged or lost , The system can automatically restore these damaged or lost files and data to the state before the accident , A technology that enables a system to operate continuously and normally , It's very simple )
scene : Page Statistics , Web page UV( A person visits a website many times , But still count as a person )
pfadd Collection name value value : Add one or more elements
pfcount Collection name : Count the number of cardinalities in the set
pfmerge New collection name Collection name Collection name : Merge the elements of the collection , And eliminate the repeated elements , Generate a new set
边栏推荐
- "Hands on deep learning" pytorch edition Chapter II exercise
- Do you know UVs in modeling?
- [backtrader source code analysis 5] rewrite several time number conversion functions in utils with Python
- Force GCC to compile 32-bit programs on 64 bit platform
- Audio Focus Series: write a demo to understand audio focus and audiomananger
- Current market situation and development prospect prediction of global direct energy deposition 3D printer industry in 2022
- [research materials] 2022q1 game preferred casual game distribution circular - Download attached
- [backtrader source code analysis 4] use Python to rewrite the first function of backtrader: time2num, which improves the efficiency by 2.2 times
- ZABBIX monitoring of lamp architecture (2): ZABBIX basic operation
- RT thread flow notes I startup, schedule, thread
猜你喜欢

Coordinatorlayout appbarrayout recyclerview item exposure buried point misalignment analysis

Compile and decompile GCC common instructions

How to connect the network: Chapter 2 (Part 1): a life cycle of TCP connection | CSDN creation punch in

(subplots用法)matplotlib如何绘制多个子图(轴域)

Learn to use the idea breakpoint debugging tool

Concurrent operation memory interaction

Thesis reading_ Tsinghua Ernie

appium1.22.x 版本後的 appium inspector 需單獨安裝
![[research materials] annual report of China's pension market in 2021 - Download attached](/img/24/622aeeb38de16ac84128b362ceeddb.jpg)
[research materials] annual report of China's pension market in 2021 - Download attached

Handler understands the record
随机推荐
Concurrent operation memory interaction
On typescript and grammar
Gbase8s unique index and non unique index
Caijing 365 stock internal reference: what's the mystery behind the good father-in-law paying back 50 million?
Introduction to deep learning - definition Introduction (I)
leetcode406. Rebuild the queue based on height
[basic grammar] Snake game written in C language
Oracle SQL table data loss
Maximum continuous sub segment sum (dynamic programming, recursive, recursive)
[Yu Yue education] basic reference materials of interchangeability and measurement technology of Zhongyuan Institute of Technology
Esp32-c3 learning and testing WiFi (II. Wi Fi distribution - smart_config mode and BlueIf mode)
Webapidom get page elements
Yolov5 network structure + code + application details | CSDN creation punch in
Current market situation and development prospect forecast of global UV sensitive resin 3D printer industry in 2022
1118 birds in forest (25 points)
Thesis reading_ Chinese medical model_ eHealth
Online VR model display - 3D visual display solution
5-36v input automatic voltage rise and fall PD fast charging scheme drawing 30W low-cost chip
1110 complete binary tree (25 points)
Silent authorization login and registration of wechat applet