Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Detailed solution of Redis database and parameter tuning of centos 7 (built in

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Blog catalogue:

First, the difference between relational database and non-relational database.

Second, the introduction of Redis database.

Third, installation and deployment of Redis.

4. Redis command tools and common commands

Fifth, Redis cluster configuration instance.

First, the difference between relational database and non-relational database:

Redis database is a non-relational database, which is not the same type as oracle, mysql, sql server and other relational databases. NoSQL is the general name of non-relational database, and the mainstream NoSQL databases are redis, MongBD and so on. The storage method, storage structure, and usage scenarios of NoSQL are completely different. NoSQL database is considered as the next generation database product because of its advantages such as non-relational, distributed, open source and horizontal expansion.

NoSQL can solve the three high problems caused by relational databases:

High concurrent read and write requirements for the database. The demand for efficient storage and access of massive data. The demand for high scalability and high availability of database.

Both relational database and non-relational database have their own characteristics and application scenarios. The precise combination of the two will bring new ideas to the development of Web 2.0database. Let relational databases focus on relationships, while non-relational databases focus on storage.

2. Introduction to redis database:

Redis is an open source, written in C language, supports the network, memory-based and persistent log type, key-value (key-value pair) database, is an indispensable part of the current distributed architecture.

Redis server is a single-process model, that is, multiple Redis processes can be started on one server at the same time, while the actual processing speed of Redis depends entirely on the execution efficiency of the main process. If only one Redis process is running on the server, the server's processing capacity will decrease to a certain extent when multiple client are accessed at the same time; if multiple Redis processes are started on the same server, Redis will cause great pressure on the server's CPU while improving the concurrent processing capacity. In other words, in the actual production environment, you need to decide how many Redis processes to start according to the actual needs. If you have a higher requirement for high concurrency, you may consider starting multiple processes on the same server; if CPU resources are tight, you can use a single process.

Redis has the following advantages:

It has a very high reading and writing speed, the maximum data reading speed can reach 110000 times / s, and the maximum data writing speed can reach 81000 times / s. Support rich data types, not only support simple key-value data types, but also support strings, lists, hashes, sets and ordered sets data type operations. Data persistence is supported. The data in memory can be saved on disk and can be loaded and used again when rebooting. Atomicity, all operations of Redis are atomic. Data backup is supported, that is, data backup in master-salve mode.

Redis is a memory-based database, and caching is one of its common application scenarios. In addition, Redis common application scenarios also include operations to obtain the latest N data, ranking applications, counter applications, storage relationships, real-time analysis systems, logging and so on.

3. Installation and deployment of Redis:

You need to go to the Redis official website to download the corresponding source code package or download directly from this Redis download link (extraction code: z0da).

[root@redis ~] # tar zxf redis-5.0.5.tar.gz-C / usr/src/ # unpack [root@redis ~] # cd / usr/src/redis-5.0.5/ # change to the extracted directory [root@redis redis-5.0.5] # make & & make install # without. / configure configuration, you can install it directly. [root@redis redis-5.0.5] # cd / usr/src/redis-5.0.5/utils/ # set the related configuration file [root@redis utils] #. / install_server.sh # execute the script file, and the relevant configuration file is generated. # the next step is to specify the storage directory of various configuration files, and press enter all the way to confirm. [root@redis utils] # cd / etc/init.d/ # Optimization Control Service start and stop [root@redis init.d] # mv redis_6379 redis [root@redis init.d] # chkconfig-- add redis # is added as a system service. [root@redis init.d] # systemctl restart redis [root@redis init.d] # netstat-anpt | grep redis # redis default listening 6379 and cluster port 16379tcp 0127.0.0.1root@redis init.d 6379 0.0.0.0 LISTEN 7098/redis-server 1 # now only redis is installed and clustering is not configured, so port 16379 is not listening. [root@redis init.d] # vim / etc/redis/6379.conf # View the redis configuration file bind 127.0.0.1 192.168.1.1 # change the listening host address appendonly yes # to "yes" for logging after each update operation Write data synchronously to port 6379 # listening port daemonize yes # enable daemon pidfile / var/run/redis_6379.pid # specify PID file loglevel notice # log level logfile / var/log/redis_6379.log # specify log file

The above are some configuration parameters, and there are many more configuration parameters in the main configuration. For more information, please see:

4. Redis command tools and common commands:

Redis software provides many command tools. When you install Redis, the included software tools are also installed on the system and can be used directly in the system. The functions of these command tools are as follows:

Redis-server: the tool used to launch Redis. Redis-benchmark: used to test the running efficiency of Redis on this machine. Redis-check-aof: fix AOF persistence files. Redis-check-rdb: fix RDB persistence files. Redis-cli:Redis command line tool.

Here is the use of the redis-cli and redis-benchmark tools:

1. Redis-cli command line tool:

The redis-cli command can connect to the specified database and specify the remote host with "- h"; "- p" specifies the port number of the service. If the password is set, you can use "- a" to specify the password, and if you do not set the connection password, you can omit the "- a" option. As follows:

[root@redis redis] # redis-cli-h 192.168.1.1-p 6379 # if the port number listens to 6379 by default, the-p option can also be omitted. 192.168.1.1purl 6379 >

In the database operating environment, use the help command to get help on the command type. There are three ways to get command help.

Help @: gets the list of commands in. Help: get help for a command. Help: get a list of topics that may help.

Examples are as follows:

192.168.1.1 BLPOP key 6379 > help @ list # View all commands related to the list data type BLPOP key [key...] Timeout summary: ck until one is available since: 2.0.0 BRPOP key [key...] Timeout summary: block until one is available since: 2.0.0.. 192.168.1.1: 6379 > help set # View the command help for the set command. SET key value [expiration EX seconds | PX milliseconds] [NX | XX] summary: Set the string value of a key since: 1.0.0 group: string

2. Redis-benchmark stress testing tool:

Redis-benchmark is the official Redis performance testing tool, which can effectively test the performance of Redis services. Common options for this tool are as follows:

Usage example:

[root@redis redis] # redis-benchmark-h 192.168.1.1-p 6379-c 100-n 10000 requests send 100 concurrent connections and 100000 requests to the Redis server at the specified IP address and port to test performance. . = MSET (10 keys) = 100000 requests completed in 1.74 seconds 100 parallel clients 3 bytes payload keep alive: 123.94% type lv # get the value type string corresponding to the key "lv"

The rename command can rename an existing key, and a renamed command is renamenx. The difference between the two is that the former changes the target key value regardless of whether it exists or not, directly overwriting the data of the target key value; the latter renamenx command checks whether the target key value exists when it is changed, and discards the change if it exists.

127.0.0.1 get lvjian 6379 > set liuyi 30 # insert a data OK127.0.0.1:6379 > renamenx lvjian liuyi # change "lvjian" to "liuyi" (integer) 0 # "liuyi" exists Discard the change 127.0.0.1 OK127.0.0.1:6379 6379 > rename lvjian liuyi # use the rename command to change OK127.0.0.1:6379 > get liuyi # directly overwrite the target data "23" 127.0.1 OK127.0.0.1:6379 6379 > dbsize # View the number of key in the current database (integer) 5

Commands commonly used in multiple databases

Redis supports multiple databases, and Redis contains 16 databases by default without any changes, and the database names are named in turn using the number 0Mur15. The data in each library is independent, that is, there is no data in the 0 library in the 10 libraries.

127.0.0.1 select 6379 > move liuyi 10 # switch to library number 10 OK127.0.0.1:6379 [10] > select 15 # switch to library number 15 OK127.0.0.1:6379 [15] > select 0 # switch to library number 0 OK127.0.0.1:6379 > move liuyi 10 # move the data in the library to library 10 (integer) 1127.0.0 .1 get liuyi 6379 > select 10 # switch to library number 10 OK127.0.0.1:6379 [10] > get liuyi # to view the moved library "23" # now the data of "liuyi" can no longer be found in the 0 library.

Clear the data in the database:

The deletion of the whole database of Redis database is mainly divided into two parts: clearing the data in the current database, using the flushdb command to achieve; emptying all the data in the database, using the flushall command. Database emptying operation is more dangerous, use it cautiously in the production environment!

5. Redis cluster configuration example:

Principle and configuration of Redis Cluster based on centos 7

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.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report