Understanding of redis and key value data types supported by redis

Posted by dnast on Mon, 17 Jan 2022 21:22:32 +0100

  • redis is a high-performance NOSQL series non relational database

NosQL(Not only sQL), "not just sQL", is a new database concept, which generally refers to non relational databases.
With the development of internet web2 With the rise of 0 website, the amount of data is becoming larger and larger, especially the super large-scale and highly concurrent SNS type pure dynamic website, which has exposed many insurmountable problems, while the non relational database has developed very rapidly due to its own characteristics.
The generation of NoSQL database is to solve the challenges brought by large-scale data collection and multiple data types, especially the big data application problems of Gongshe.

  • Comparison between NOSQL and relational database r

advantage:
1) Cost: nosql database is simple and easy to deploy. It is basically open source software. It does not need to spend a lot of cost to buy and use like using oracle. It is cheaper than relational database. 2) Query speed: nosq1 database stores the data in the cache, while relational database stores the data in the hard disk. Naturally, the query speed is far lower than that of nosq1 database.
3) Format of stored data: nosql is stored in key, value, document, picture and other formats, so it can store basic types, objects or collections. 4) scalability: relational databases are limited by multi table query mechanisms such as join, which makes it difficult to expand.
Disadvantages:
1) The tools and materials for maintenance are limited, because nosq1 is a new technology, which can not be compared with the technology of relational database for more than 10 years. 2) It does not support sq1. If it does not support industrial standards such as sq1, it will cost users to learn and use.
3) Transaction processing by relational database is not provided.

  • redis high performance and usage scenarios

Redis is an open-source high-performance key value database developed in c language. There are 50 official test data
Execute 10000o requests concurrently The read speed is 110000 times / s. The write speed is 81000 times / s
Redis provides a variety of key value data classes
Type to meet the storage requirements in different scenarios. So far, Redis supports the following key value data types:
1) String type string
2) Hash type hash
3) List type list

4) Set type set
5) Ordered set type sortedset

 

  • redis application scenario

Cache (data query, short connection, news content, product content, etc.) online friend list of chat room
Task queue. (second kill, rush purchase, 12306, etc.) application ranking
common
Website access statistics
Data expiration processing can be accurate to session separation in haos distributed cluster architecture
 

 

  1. String type string
127.0.0.1:6379> set userName xiao         ---------> establish String Type: userName
OK
127.0.0.1:6379> select 1                  ---------> Change database to database 1
OK
127.0.0.1:6379[1]> set userName xiao      ---------> Create in database 1 String type
OK
127.0.0.1:6379[1]> get userName           ---------> Get the type value just created
"xiao"

design sketch:

2. hash type

127.0.0.1:6379[1]> hset myHasp userName pretty            --------> establish hash Type: uesrName
(integer) 1
127.0.0.1:6379[1]> hset myHasp password 123456            --------> establish hash Type: password
(integer) 1
127.0.0.1:6379[1]> hget myHsap            
(error) ERR wrong number of arguments for 'hget' command  --------> Wrong message
127.0.0.1:6379[1]> hget myHasp userName                   --------> obtain hash Type: uesrName value
"pretty"
127.0.0.1:6379[1]> hget myHasp password                   --------> obtain hash Type: password value
"123456"
127.0.0.1:6379[1]> hgetAll myHasp                         --------> obtain hash Type all values
1) "userName"
2) "pretty"
3) "password"
4) "123456"

design sketch:

3. list type

127.0.0.1:6379[1]> lpush myList a            -----------> establish list Type: myList Value of a((left)
(integer) 1
127.0.0.1:6379[1]> lpush myList b            -----------> establish list Type: myList Value of b((left)
(integer) 2
127.0.0.1:6379[1]> lpush myList c            -----------> establish list Type: myList Value of c((left)
(integer) 3
127.0.0.1:6379[1]> rpush myList1 a           -----------> establish list Type: myList1 Value of a((right)
(integer) 1
127.0.0.1:6379[1]> rpush myList1 b           -----------> establish list Type: myList1 Value of b((right)
(integer) 2
127.0.0.1:6379[1]> rpush myList1 c           -----------> establish list Type: myList1 Value of c((right)
(integer) 3
127.0.0.1:6379[1]> lrange myList 0 -1        -----------> obtain myList All values in (0): from the first 
                                                                            At the beginning,-1 (read all)
1) "c"
2) "b"
3) "a"
127.0.0.1:6379[1]> lrange myList1 0 -1       -----------> lpush:from a Start saving to the left in turn, rpush from a 
                                                          Start saving to the right. ( lpush Equivalent to number axis 0~ 
                                                          Negative segments, rpush Is 0~(to positive segment)
1) "a"
2) "b"
3) "c"

design sketch:

 

 4. Set type set

127.0.0.1:6379[1]> sadd mySet a         ----------> add to set Type: mySet Value is a
(integer) 1
127.0.0.1:6379[1]> sadd mySet b         ----------> add to set Type: mySet Value is b
(integer) 1
127.0.0.1:6379[1]> sadd mySet c         ----------> add to set Type: mySet Value is c
(integer) 1
127.0.0.1:6379[1]> smembers mySet       ----------> Full check set Type: mySet value
1) "a"
2) "b"
3) "c"
127.0.0.1:6379[1]> srem mySet a         ----------> delete set Type: mySet Value is a
(integer) 1
127.0.0.1:6379[1]> smembers mySet       ----------> Full check set Type: mySet Value is a
1) "b"
2) "c"

design sketch:

 5. Ordered set type sortedset

127.0.0.1:6379[1]> zadd mySort 25 cat             ----------> add to sortedset type mySort: 
                                                               25(Random values for easy sorting) cat
(integer) 1
127.0.0.1:6379[1]> zadd mySort 15 dog
(integer) 1
127.0.0.1:6379[1]> zadd mySort 30 pig
(integer) 1
127.0.0.1:6379[1]> zrange mySort 0 -1             ----------> see sortedset type mySort value
1) "dog"
2) "cat"
3) "pig"
127.0.0.1:6379[1]> zrange mySort 0 -1 withscores  ----------> Full check sortedset type mySort
1) "dog"
2) "15"
3) "cat"
4) "25"
5) "pig"
6) "30"

design sketch:

 

Topics: Redis ci