当前位置:网站首页>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
边栏推荐
- Basic use of Metasploit penetration testing framework
- 1095 cars on campus (30 points)
- 1086 tree traversals again (25 points)
- Thesis reading_ Tsinghua Ernie
- Kept hot standby and haproxy
- RT thread flow notes I startup, schedule, thread
- Problems encountered in fuzzy query of SQL statements
- Yolov5 input (I) -- mosaic data enhancement | CSDN creative punch in
- ZABBIX monitoring of lamp architecture (2): ZABBIX basic operation
- [set theory] relation properties (transitivity | transitivity examples | transitivity related theorems)
猜你喜欢
Cross platform plug-in flutter for displaying local notifications_ local_ notifications
微服务常见面试题
Web APIs exclusivity
Burp suite plug-in based on actual combat uses tips
ZABBIX monitoring of lamp architecture (3): zabbix+mysql (to be continued)
Esp32-c3 learning and testing WiFi (II. Wi Fi distribution - smart_config mode and BlueIf mode)
Review the configuration of vscode to develop golang
音频焦点系列:手写一个demo理解音频焦点与AudioMananger
Basic use of Metasploit penetration testing framework
Thesis reading_ ICD code_ MSMN
随机推荐
Market status and development prospect forecast of global button dropper industry in 2022
50 practical applications of R language (36) - data visualization from basic to advanced
Use posture of sudo right raising vulnerability in actual combat (cve-2021-3156)
Current market situation and development prospect prediction of global direct energy deposition 3D printer industry in 2022
Learn to use the idea breakpoint debugging tool
Yolov5 network structure + code + application details | CSDN creation punch in
Handler understands the record
1119 pre- and post order traversals (30 points)
Literature reading_ Research on the usefulness identification of tourism online comments based on semantic fusion of multimodal data (Chinese Literature)
[backtrader source code analysis 4] use Python to rewrite the first function of backtrader: time2num, which improves the efficiency by 2.2 times
(完美解决)matplotlib图例(legend)如何自由设置其位置
[Yu Yue education] basic reference materials of interchangeability and measurement technology of Zhongyuan Institute of Technology
Chapter II program design of circular structure
1099 build a binary search tree (30 points)
1114 family property (25 points)
appium1.22.x 版本後的 appium inspector 需單獨安裝
[set theory] relation properties (transitivity | transitivity examples | transitivity related theorems)
Maximum continuous sub segment sum (dynamic programming, recursive, recursive)
The principle is simple, but I don't know how to use it? Understand "contemporaneous group model" in one article
Notes | numpy-11 Array operation