Although relational database is widely used, its performance is relatively poor in the face of current data access. At this time, his good friend non relational database appeared. Enterprise development generally combines the two. Next, we will introduce the non relational database Redis (it is said that Redis was originally developed to kill MySQL, but it obviously failed)
Tip: the following is the main content of this article. The following cases can be used for reference
1, What is Redis?
Redis (Remote Dictionary Server), that is, remote dictionary service, is an open-source log type and key value database written in ANSI C language, supporting network, memory based and persistent, and provides API s in multiple languages. Redis is a NOSQL database, but don't understand NOSQL as no database. Its original meaning is a non relational database.
It can be used as a combination of relational databases to help us store some data that are not particularly important and need to be queried frequently. It can be used as a database, cache and message agent. Redis provides data structures, such as string, hash, list, collection, sorted collection with range query, bitmap, super log, geospatial index and stream. Redis has built-in replication, Lua script, LRU expulsion, transaction and different levels of disk persistence, and provides high availability through Redis Sentinel and Redis Cluster automatic partition. Reduce the pressure of relational database. According to the official test results, the reading speed of redis is 110000 times / s and the writing speed is 81000 times / s.
2, Installation and use of Redis
1. Download the redis source code installation package on the official website. Official website
2. The environment required to install redis.
yum install -y gcc-c++
3. Unzip to the specified directory
tar -zxvf redis-5.0.8.tar.gz -C catalogue
4. Enter the redis directory and execute the compile install command make install
5. Enter the installation directory and find redis conf
6. Enable redis service
7. If you use an Xshell connection, you can create a new session. Otherwise, there will be problems in the operation on the current page. You can also modify redis Conf configuration file
# Indicates that the redis server is started in the background. daemonize yes # The default port number. port 6379 # The default port number for running binding is HTTP protocol~~~~~~~~~~~~~~~~~ # bind 127.0.0.1 # 0.0.0.0 means broadcast mode, which means that everyone can connect. 127.0.0.1 bind 0.0.0.0
III. common redis commands
1. Data types supported by redis
- String string type
- Hash hash type
- list queue
- Set set
- sorted set ordered set.
2. Commands for key operation
keys *: Query all key； del key....:Delete the specified key expire key seconds: For the specified key Set the expiration time in seconds ttl key: Query assignment key Survival time of
3. Operation commands for database
flushdb: Clear the data in the current database. select index: Select database flushall: Clear all data in the database.
4.String type value value is a string type
set key value: String value Store in the corresponding key Come on. get key: According to the specified key Get the corresponding string value mset key value key value key value....: Storing multiple strings at a time value To the corresponding key upper mget key key...: According to multiple specified key Get the corresponding string value setnx key value: Put the designated value Store in the corresponding key On, if the corresponding key If it already exists, it will not be stored. If it does not exist, it is stored. Return 0 or 1 incr key: For the specified key of value Value is incremented. Application scenario: ordering likes, receiving meals, forwarding, etc decr key: Diminishing
4.Hash value is of hash type
hset key field value: Store a specified key of field-value Database of hget key field:Get specified key of field Field corresponding value Value. hkeys key: Get specified key All field Field name hvals key: Get specified key All value Value. hgetall key: Get specified key All of field and value Value. HDEL key field: Delete assignment key of field Field.
5.List queue type
lpush: Set one or more values value Insert into list key Header of. lpop: Remove and return to list key The header element of the. lrange: Return to list key The element within the specified interval in, and the interval is offset start and stop appoint.
sadd key value.....: One or more member Add element to collection key among, Already exists in the of the collection member Element will be ignored.
7.sortSet ordered set.
zadd key score value score value ....:Add ordered collection elements. zrange key start end: Gets the element returned by the specified.
For more detailed commands, please refer to: