当前位置:网站首页>Redis related-01
Redis related-01
2022-06-25 03:44:00 【legend_ go】
Redis Basic relevance -01
One 、 What is? Redis?
Official description :
Redis It's open source (BSD The license ) Of , Data structure storage system in memory , It can be used as a database 、 Caching and message middleware . It supports multiple types of data structures , Such as character string (strings), hash (hashes), list (lists), aggregate (sets), Ordered set (sorted sets) And scope query , bitmaps, hyperloglogs and Geographical space (geospatial) Index radius query . Redis Built in Copy (replication),LUA Script (Lua scripting), LRU Driving events (LRU eviction), Business (transactions) And different levels of Disk persistence (persistence), And pass Redis sentry (Sentinel) And automatic Partition (Cluster) Provide high availability (high availability).
Personal understanding :
- It can be used as a database
- Used as a cache , Finally, it is persisted to the database
- Message oriented middleware implements the subscription and publication of messages
- Very fast read speed
Two 、Linux Lower installation Redis
1、 stay Redis Download the compressed package on the official website

2、 utilize XFTP The tool is uploaded to a folder on the remote server
Execute the following command :
# Unzip the file
tar -zxvf redis-6.2.6.tar.gz
# Enter the unzipped folder
cd redis-6.2.6
# compile
make
make install
# Get into src Folder
cd src
# start-up Redis
./redis-server ../redis.conf
# start-up Redis client
./redis-cli
Deployment success
3、 ... and 、Redis Common commands and basic data types
1、Redis key
| 1 | DEL key This command is used in key Delete... When it exists key. |
|---|---|
| 2 | DUMP key Serialization given key , And return the serialized value . |
| 3 | EXISTS key Check the given key Whether there is . |
| 4 | EXPIRE key seconds For a given key Set expiration time , In seconds . |
| 5 | EXPIREAT key timestamp EXPIREAT Function and EXPIRE similar , All for key Set expiration time . Difference is that EXPIREAT The time parameter accepted by the command is UNIX Time stamp (unix timestamp). |
| 6 | PEXPIRE key milliseconds Set up key In milliseconds . |
| 7 | PEXPIREAT key milliseconds-timestamp Set up key Time stamp of expiration time (unix timestamp) In milliseconds |
| 8 | KEYS pattern Find all that match the given pattern ( pattern) Of key . |
| 9 | MOVE key db Will be the current database of key Move to a given database db among . |
| 10 | PERSIST key remove key The expiration time of ,key Will last . |
| 11 | PTTL key Returns... In milliseconds key The remaining expiration time of . |
| 12 | TTL key In seconds , Return to a given key The remaining lifetime of (TTL, time to live). |
| 13 | RANDOMKEY Returns a random... From the current database key . |
| 14 | RENAME key newkey modify key The name of |
| 15 | RENAMENX key newkey Only when the newkey When there is no , take key Renamed as newkey . |
| 16 | [SCAN cursor MATCH pattern] [COUNT count] Iterate the database keys in the database . |
| 17 | TYPE key return key The type of value stored . |
2、String type
| 1 | SET key value Set the specified key Value |
|---|---|
| 2 | GET key Get specified key Value . |
| 3 | GETRANGE key start end return key The child character of the string value in |
| 4 | GETSET key value Will be given key The value of the set value , And back to key The old value (old value). |
| 5 | GETBIT key offset Yes key String value stored , Gets the bit on the specified offset (bit). |
| 6 | [MGET key1 key2…] Get all ( One or more ) Given key Value . |
| 7 | SETBIT key offset value Yes key String value stored , Sets or clears the bit on the specified offset (bit). |
| 8 | SETEX key seconds value Will value value Related to key , And will key The expiration time of is set to seconds ( In seconds ). |
| 9 | SETNX key value Only in key Set when not present key Value . |
| 10 | SETRANGE key offset value use value Parameter override given key String value stored , From the offset offset Start . |
| 11 | STRLEN key return key The length of the stored string value . |
| 12 | [MSET key value key value …] Set one or more... At the same time key-value Yes . |
| 13 | [MSETNX key value key value …] Set one or more... At the same time key-value Yes , If and only if all given key It doesn't exist . |
| 14 | PSETEX key milliseconds value This command and SETEX Command similar , But it's set in milliseconds key Survival time , Not like it SETEX Order that , In seconds . |
| 15 | INCR key take key The value of the number stored in is increased by one . |
| 16 | INCRBY key increment take key The stored value plus the given increment value (increment) . |
| 17 | INCRBYFLOAT key increment take key The stored value plus the given floating-point delta value (increment) . |
| 18 | DECR key take key Subtract one from the number stored in . |
| 19 | DECRBY key decrement key The stored value minus the given decrement value (decrement) . |
| 20 | APPEND key value If key Already exists and is a string , APPEND The order will specify value Append to the key Original value (value) At the end of . |
3、List type
| 1 | BLPOP key1 key2 ] timeout Move out and get the first element of the list , If there are no elements in the list, it will block the list until the wait timeout or pop-up elements are found . |
|---|---|
| 2 | BRPOP key1 key2 ] timeout Move out and get the last element of the list , If there are no elements in the list, it will block the list until the wait timeout or pop-up elements are found . |
| 3 | BRPOPLPUSH source destination timeout Pop up a value... From the list , Insert the pop-up element into another list and return it ; If there are no elements in the list, it will block the list until the wait timeout or pop-up elements are found . |
| 4 | LINDEX key index Get the elements in the list by index |
| 5 | LINSERT key BEFORE|AFTER pivot value Insert an element before or after a list element |
| 6 | LLEN key Get list length |
| 7 | LPOP key Move out and get the first element of the list |
| 8 | [LPUSH key value1 value2] Insert one or more values into the list header |
| 9 | LPUSHX key value Insert a value into the existing list header |
| 10 | LRANGE key start stop Get the elements in the specified range of the list |
| 11 | LREM key count value Remove list elements |
| 12 | LSET key index value Set the value of the list element through the index |
| 13 | LTRIM key start stop Trim a list (trim), That is to say , Let the list keep only the elements in the specified range , Elements that are not in the specified range will be removed . |
| 14 | RPOP key Remove the last element of the list , The return value is the removed element . |
| 15 | RPOPLPUSH source destination Remove the last element of the list , And add the element to another list and return |
| 16 | [RPUSH key value1 value2] Add one or more values... To the list |
| 17 | RPUSHX key value Add value to existing list |
4、Set type
| 1 | SADD key member1 member2] Add one or more members to the collection |
|---|---|
| 2 | SCARD key Get the number of members of the collection |
| 3 | [SDIFF key1 key2] Returns the difference between the first set and the others . |
| 4 | [SDIFFSTORE destination key1 key2] Returns the difference set of a given set and stores it in destination in |
| 5 | [SINTER key1 key2] Returns the intersection of a given set |
| 6 | [SINTERSTORE destination key1 key2] Returns the intersection of a given set and stores it in destination in |
| 7 | SISMEMBER key member Judge member Is the element a collection key Members of |
| 8 | SMEMBERS key Returns all members of the collection |
| 9 | SMOVE source destination member take member Elements from source The assembly moves to destination aggregate |
| 10 | SPOP key Remove and return a random element from the collection |
| 11 | [SRANDMEMBER key count] Returns one or more random numbers in a set |
| 12 | [SREM key member1 member2] Remove one or more members of the collection |
| 13 | [SUNION key1 key2] Returns the union of all given sets |
| 14 | [SUNIONSTORE destination key1 key2] The union of all given sets is stored in destination Collection |
| 15 | [SSCAN key cursor MATCH pattern] [COUNT count] Iterate over the elements in the collection |
5、Hash type
| 1 | [HDEL key field1 field2] Delete one or more hash table fields |
|---|---|
| 2 | HEXISTS key field Look at the hash table key in , Whether the specified field exists . |
| 3 | HGET key field Gets the value of the specified field stored in the hash table . |
| 4 | HGETALL key Gets the specified in the hash table key All fields and values of |
| 5 | HINCRBY key field increment Hash table key The integer value of the specified field in plus the increment increment . |
| 6 | HINCRBYFLOAT key field increment Hash table key The floating-point value of the specified field in plus the increment increment . |
| 7 | HKEYS key Get all the fields in the hash table |
| 8 | HLEN key Get the number of fields in the hash table |
| 9 | [HMGET key field1 field2] Get the value of all the given fields |
| 10 | [HMSET key field1 value1 field2 value2 ] There will be more than one field-value ( Domain - value ) Set to hash table key in . |
| 11 | HSET key field value Hash table key In the field field The value of the set value . |
| 12 | HSETNX key field value Only in the fields field When there is no , Set the value of the hash table field . |
| 13 | HVALS key Get all values in hash table . |
| 14 | [HSCAN key cursor MATCH pattern] [COUNT count] Iterate over the key value pairs in the hash table . |
6、 Ordered set ZSet
| 1 | [ZADD key score1 member1 score2 member2] Add one or more members... To an ordered collection , Or update scores of existing members |
|---|---|
| 2 | ZCARD key Get the number of members of the ordered set |
| 3 | ZCOUNT key min max Calculates the number of members of a specified interval fraction in an ordered set |
| 4 | ZINCRBY key increment member Add the increment... To the score of the specified member in the ordered set increment |
| 5 | [ZINTERSTORE destination numkeys key key …] Calculates the intersection of a given ordered set or sets and stores the result set in a new ordered set destination in |
| 6 | ZLEXCOUNT key min max Computes the number of members in the specified dictionary interval in an ordered collection |
| 7 | [ZRANGE key start stop WITHSCORES] Return the members in the specified interval of the ordered set through the index interval |
| 8 | [ZRANGEBYLEX key min max LIMIT offset count] Returns the members of an ordered set through a dictionary interval |
| 9 | [ZRANGEBYSCORE key min max WITHSCORES] [LIMIT] Returns the members of an ordered set in a specified interval through scores |
| 10 | ZRANK key member Returns the index of a specified member in an ordered collection |
| 11 | [ZREM key member member …] Remove one or more members of an ordered collection |
| 12 | ZREMRANGEBYLEX key min max Remove all members of a given dictionary interval from an ordered set |
| 13 | ZREMRANGEBYRANK key start stop Remove all members of a given rank range from an ordered set |
| 14 | ZREMRANGEBYSCORE key min max Remove all members of a given fraction interval from an ordered set |
| 15 | [ZREVRANGE key start stop WITHSCORES] Returns the members of a specified interval in an ordered set , Through the index , Scores go from high to low |
| 16 | [ZREVRANGEBYSCORE key max min WITHSCORES] Returns the members of the specified score range in an ordered set , Rank scores from high to low |
| 17 | ZREVRANK key member Returns the rank of a specified member in an ordered set , Members of an ordered set are decremented by fractions ( From big to small ) Sort |
| 18 | ZSCORE key member Back to the ordered set , The score of a member |
| 19 | [ZUNIONSTORE destination numkeys key key …] Computes the union of a given ordered set or sets , And store it in the new key in |
| 20 | [ZSCAN key cursor MATCH pattern] [COUNT count] Iterate over elements in an ordered set ( Include element members and element scores ) |
Four 、 Three special types
- Geospatial
- Hyperloglog
- Bitmap
1、Geospatial
- GEOADD
- GEODIST
- GEORADIUS
- GEOHASH
- GEOPOS
- GEORADIUSBYMMBER
Application scenarios : The man near the 、 Straight line distance, etc
2、Hyperloglog
| 1 | [PFADD key element element …] Add specified elements to HyperLogLog in . |
|---|---|
| 2 | [PFCOUNT key key …] Return to a given HyperLogLog The base estimate of . |
| 3 | [PFMERGE destkey sourcekey sourcekey …] Will be multiple HyperLogLog Merge into one HyperLogLog |
Application scenarios : Website UV(User View) User access , Available cardinality statistics
3、Bitmap
SETBIT
GETBIT
Application scenarios : User clocks in
Related articles :
- Redis-01
- What is? Redis
- stay Linux Lower installation Redis
- Redis Common commands and basic data types
- Three special types
- Redis-02
- Redis Implement basic transaction operations
- Redis Achieve optimistic lock
- adopt Jedis operation Redis
- adopt Jedis Understand the business
- SpringBoot Integrate Redis
- Customize RedisTemplate
- Redis-03
- Redis Configuration file details
- Persistence ——RDB operation
- Persistence ——AOF operation
- Redis Subscription Publishing
- Redis Cluster environment construction
- Master slave copy
- Manually configure the host during downtime
- Sentinel mode
- Cache penetration and avalanche
Reference link :
【 Madness theory Java】Redis The latest super detailed version of the tutorial is easy to understand
边栏推荐
- The release function completed 02 "IVX low code sign in system production"
- x86 CPU,危!最新漏洞引发热议,黑客可远程窃取密钥,英特尔“全部处理器”受影响...
- 陆奇首次出手投资量子计算
- Tianshu night reading notes - 8.4 diskperf disassembly
- 存算一体芯片离普及还有多远?听听从业者怎么说 | 对撞派 x 后摩智能
- 你真的需要自动化测试吗?
- Is it safe to open an account online? Online and other answers
- 单例的饥饿、懒汉模式案例
- Zuckerberg's latest VR prototype is coming. It is necessary to confuse virtual reality with reality
- Li Kou daily question - day 26 -506 Relative rank
猜你喜欢

Musk: Twitter should learn from wechat and make 1billion people "live on it" into a super app

Two way combination of business and technology to build a bank data security management system

Xidian AI ranked higher than Qingbei in terms of AI majors, and Nantah ranked the first in China in 2022 in terms of soft science majors

程序员真人秀又来了!呼兰当主持挑灯狂补知识,SSS大佬本科竟是药学,清华朱军张敏等加入导师团...

x86 CPU,危!最新漏洞引发热议,黑客可远程窃取密钥,英特尔“全部处理器”受影响...

騰訊開源項目「應龍」成Apache頂級項目:前身長期服務微信支付,能hold住百萬億級數據流處理...

Does it count as staying up late to sleep at 2:00 and get up at 10:00? Unless you can do it every day

Redis related-02

完美洗牌问题

AI writes its own code to let agents evolve! The big model of openai has the flavor of "human thought"
随机推荐
Void* pointer
ICML 2022 | ByteDance AI Lab proposes a multimodal model: x-vlm, learning multi granularity alignment of vision and language
腾讯开源项目「应龙」成Apache顶级项目:前身长期服务微信支付,能hold住百万亿级数据流处理...
1-6 build win7 virtual machine environment
跨境电商新手如何防止店铺关联?用什么工具好?
MySQL installation tutorial
Seata四大模式之TCC模式详解及代码实现
马斯克被诉传销索赔2580亿美元,台积电公布2nm制程,中科院发现月壤中含有羟基形式的水,今日更多大新闻在此...
Is it safe to open an account online? Online and other answers
股票开户用客户经理发的开户链接安全吗?知道的给说一下吧
Demonstration of combination of dream CAD cloud map and GIS
DateTimeFormat放到@RequestBody下是无效的
支付宝被风控7天怎么办?付解决方案
Is it safe to open an account on your mobile phone?
Is it safe to open an account on the compass? Is it reliable?
Before the age of 36, Amazon transgender hackers were sentenced to 20 years' imprisonment for stealing data from more than 100million people!
签到功能完成03《ivx低代码签到系统制作》
站在风暴中心:如何给飞奔中的腾讯更换引擎
可能是拿反了的原因
论一个优秀红队人员的自我修养