In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the example analysis of redis entry knowledge points, which has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, let the editor take you to understand it.
A preface
Let's first introduce the concept of redis:
Redis is an open source key-value storage system that belongs to NoSQL (Not Only SQL), not just a relational database.
Take a look at the advantages of redis:
Rich data types
Support for key expiration feature
Each instruction is an atomic operation.
Extremely high read and write performance
Get a preliminary understanding of the additional features of redis
Can be primary storage and secondary storage, master-slave replication
Support for persistent data storage
Linux installation redis link: https://www.jianshu.com/p/bc84b2b71c1c
Windows installation redis link: https://www.jianshu.com/p/e16d23e358c0
Docker installation redis Link https://juejin.im/post/5ca59dece51d4508b32a1292
Finally, it is recommended that you install redis 5.0.5 stable version in the production environment.
Two and five basic data types 2.1 strings
String data is stored in the form of key-val (key-value pair), that is, each key has a corresponding unique value; as shown in the following figure, if age is key, the corresponding unique value is 18
The command is described as follows
Get: gets the value that stores the given key
Set: sets the value of a given storage key
Del: deletes the value of a given key
Incr: count, add 1 at a time
Incrby: calculation, addition or subtraction of a given value
Mset: setting multiple key values
Mget: gets the values of multiple given keys
Expire: set expiration time (for all types)
Exists: whether there is a key
Example of storage string
Set key value
127.0.0.1 purl 6379 > set zszxz 666OK
Get string example
Get key
127.0.1 6379 > get zszxz "666"
Delete string exampl
Del key [key...]
127.0.0.1 6379 > del zszxz (integer) 1
Example of counting:
Incr key
127.0.0.1 set age 100OK127.0.0.1:6379 > incr age (integer) 101127.0.0.1 integer 6379 > incr age (integer) 102127.0.0.1 integer 6379 > get age "102" 127.0.1
Incrby key increment
127.0.0.1 set age 100OK127.0.0.1:6379 > incrby age 5 (integer) 105127.0.0.1 integer 6379 > incrby age-2 (integer) 103127.0.1 integer 6379 > get age "103" 127.0.1
Example of multi-key value pair
Mset key value [key value...]
Mget key [key...]
127.0.0.1 you1 6379 > mset U1 you1 U2 you2OK127.0.0.1:6379 > mget U1 U21) "you1" 2) "you2" 127.0.0.1 you2OK127.0.0.1:6379 >
Set expiration time
Expire key seconds
127.0.0.1 expire 6379 > get U1 1 (integer) 1127.0.1 get U1 (nil) 127.0.0.1 get 6379 >
There are examples
Exists key [key...]
127.0.0.1 integer 6379 > set age 100OK127.0.0.1:6379 > exists age (integer) 1127.0.1 VR 6379 > 2.2
A list is actually a linked list. A list has a key, and a key corresponds to multiple values. The values can be repeated. When taking values, you can take values according to the index.
Rpush: push values to the right end of the list
Lrange: gets all the values in the given range of the list
Lindex: gets a single element at a given location on the list
Lpop: a value pops up from the left end of the list
Example of listing values
Rpush key value [value...]
127.0.0.1 rpush list-zszxz 6379 > rpush list-zszxz a (integer) 1127.0.0.1 integer 6379 > rpush list-zszxz c (integer) 3
Example of range value
Lrange key start stop
127.0.0.1 lrange list-zszxz 6379 > 0-11) "a" 2) "b" 3) "c"
Example of a given index value
Lindex key index
127.0.0.1 6379 > lindex list-zszxz 1 "b"
Left pop-up example
Lpop key
127.0.0.1 lpop list-zszxz 6379 > lrange list-zszxz 0-11) "b" 2) "c" 2.3 collection
A collection is similar to a list, except that the collection is unordered and each value is unique and cannot be repeated.
Sadd: adds a given value to the collection
Smembers: returns all the elements of the collection
Sismember: checks whether a given element exists in the collection
Srem: remove the element if it exists in the collection
Add exampl
Sadd key member [member...]
127.0.0.1 sadd set-zszxz 6379 > sadd set-zszxz a (integer) 1127.0.0.1 integer 6379 > sadd set-zszxz c (integer) 1
Returns examples of all elements
Smembers key
127.0.0.1 smembers set-zszxz1 6379) "c" 2) "b" 3) "a"
There are examples
Sismember key member
127.0.0.1 6379 > sismember set-zszxz c (integer) 1
Delete exampl
Srem key member [member...]
127.0.0.1 srem set-zszxz 6379 > smembers set-zszxz1 (a (integer) 1127.0.0.1) smembers set-zszxz1) "c" 2) "b" 2.4 hash
Hash points are like dictionaries in map,python in java; multiple key-value pairs are stored in a hash
Hset: the key-value pair of a given hash
Hget: gets the value of the specified hash key
Hetall: gets the key-value pairs of all hashes
Hdel: if the key exists in the hash, remove the key
Example of setting hash key value pair
Hset key field value
127.0.0.1 hset hash-key key1 6379 > hset hash-key key2 a (integer) 1127.0.0.1 integer 6379 > hset hash-key key3 c (integer) 1127.0.1
Example of getting a hash given key
Hget key field
127.0.0.1 6379 > hget hash-key key1 "c"
Get an example of all hash key-value pairs
Hgetall key
127.0.1 key3 6379 > hgetall hash-key1) "key1" 2) "c" 3) "key2" 4) "b" 5) "key3" 6) "c"
Delete hash key exampl
Hdel key field [field...]
127.0.0.1 hdel hash-key key1 (integer) 1127.0.0.1 hgetall hash-key1) "key2" 2) "b" 3) "key3" 4) "c" 127.0.1 > 2.5 ordered set
The redis ordered set is similar to the hash, except that the key is called member and value is called score. It is sorted according to the score.
Zadd: adds members with a given score to an ordered set
Zrange: gets elements based on the index of an ordered collection
Zrangebyscore: gets all elements within a given score range in an ordered collection
Zrem: if the member exists in an ordered collection, remove it
Add member exampl
Zadd key score member [score member...]
127.0.0.1 zadd zset-key member1 (integer) 1127.0.0.1 member2 (integer) 1127.0.0.1 member2 6379 > zadd zset-key 680 member3 (integer) 1127.0.0.1 integer 6379 >
Gets an example of a member within the specified index range
Zrange key start stop [WITHSCORES]
Without score
127.0.0.1 zrange zset-key 6379 > member3 0-11) "member1" 2) "member2" 3) "member3"
Bring score.
127.0.1 zrange zset-key 6379 > member3 0-1 withscores1) "member1" 2) "600" 3) "member2" 4) "650" 5) "member3" 6) "680"
Gets an example of a member within the specified score range
Zrangebyscore key min max [WITHSCORES] [LIMIT offset count]
127.0.0.1 member1 6379 > zrangebyscore zset-key 600 650 withscores1) "member1" 2) "600" 3) "member2" 4) "650"
Remove member exampl
Zrem key member [member...]
127.0.0.1 zrem zset-key member1 (integer) 1127.0.0.1 withscores1 6379 > zrange zset-key 0-1 withscores1) "member2" 2) "650" 3) "member3" 4) "680" 127.0.1
Shorthand method:
String, key-value
Lists and collections, similar to linked lists, an ordered, an unordered, a key stores multiple values
Hash and ordered sets, similar to dictionaries, map; stores multiple key-value; ordered sets with key as member and value as score, sorted by score
Thank you for reading this article carefully. I hope the article "sample Analysis of introductory knowledge points of redis" shared by the editor will be helpful to you. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.