Movatterモバイル変換


[0]ホーム

URL:


CN108563744A - Slow querying method, device and terminal device based on Redis databases - Google Patents

Slow querying method, device and terminal device based on Redis databases
Download PDF

Info

Publication number
CN108563744A
CN108563744ACN201810327855.3ACN201810327855ACN108563744ACN 108563744 ACN108563744 ACN 108563744ACN 201810327855 ACN201810327855 ACN 201810327855ACN 108563744 ACN108563744 ACN 108563744A
Authority
CN
China
Prior art keywords
slow
record
redis databases
mysql database
stored
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN201810327855.3A
Other languages
Chinese (zh)
Other versions
CN108563744B (en
Inventor
陈阳
陈少杰
张文明
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shanghai Jiuyan Information Technology Co.,Ltd.
Original Assignee
Wuhan Douyu Network Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Wuhan Douyu Network Technology Co LtdfiledCriticalWuhan Douyu Network Technology Co Ltd
Priority to CN201810327855.3ApriorityCriticalpatent/CN108563744B/en
Publication of CN108563744ApublicationCriticalpatent/CN108563744A/en
Application grantedgrantedCritical
Publication of CN108563744BpublicationCriticalpatent/CN108563744B/en
Activelegal-statusCriticalCurrent
Anticipated expirationlegal-statusCritical

Links

Landscapes

Abstract

The present invention relates to Internet technical fields, and in particular to a kind of slow querying method, device and terminal device based on Redis databases, the Redis databases are connect with the MySQL database being stored in storage device.The slow querying method based on Redis databases includes:It detects and stores whether the list length that slow inquiry records reaches predetermined length in the Redis databases, if reaching, then by all slow inquiry record storages in MySQL database, the html page paging built in advance is called to show all slow inquiry records stored in MySQL database in turn, and user can search corresponding slow inquiry record according to the search strategy of input in MySQL database, and be shown in html page.It can be seen that in the present solution, by the way that all slow inquiry record timing in Redis databases to be stored in MySQL database, and user is showed in by html page so that user easily can be inquired and used by search strategy.

Description

Translated fromChinese
基于Redis数据库的慢查询方法、装置及终端设备Slow query method, device and terminal equipment based on Redis database

技术领域technical field

本发明涉及互联网技术领域,具体而言,涉及一种基于Redis数据库的慢查询方法、装置及终端设备。The present invention relates to the technical field of the Internet, in particular, to a slow query method, device and terminal equipment based on a Redis database.

背景技术Background technique

该Redis数据库用于存储慢查询记录,目前的Redis数据库的慢查询的方法为,给该Redis数据库设置一个时间阈值,进而该Redis数据库将丢弃超过该时间阈值的数据,以腾出空间保留新的慢查询记录,由此用户无法查询较早的数据;另一方面,若用户想在Redis数据库查询记录,一般需使用Redis数据库的查询指令去Redis数据库中进行查找,且只有特定权限的人才能查找。由此,Redis数据库中的数据对于用户而言,查找和使用都不方便。The Redis database is used to store slow query records. The slow query method of the current Redis database is to set a time threshold for the Redis database, and then the Redis database will discard data exceeding the time threshold to make room for new ones. Slow query records, so users cannot query earlier data; on the other hand, if users want to query records in the Redis database, they generally need to use the query commands of the Redis database to search in the Redis database, and only people with specific permissions can search . Therefore, the data in the Redis database is inconvenient for users to find and use.

发明内容Contents of the invention

本发明的目的在于提供一种基于Redis数据库的慢查询方法,以方便用户查找和使用。The object of the present invention is to provide a kind of slow query method based on Redis database, to facilitate users to find and use.

本发明的另一目的在于提供一种基于Redis数据库的慢查询装置,以方便用户查找和使用。Another object of the present invention is to provide a slow query device based on a Redis database to facilitate users to find and use.

本发明的另一目的在于提供一种终端设备,以方便用户查找和使用。Another object of the present invention is to provide a terminal device, which is convenient for users to find and use.

为了实现上述目的,本发明实施例采用的技术方案如下:In order to achieve the above object, the technical solution adopted in the embodiment of the present invention is as follows:

第一方面,本发明实施例提供了一种基于Redis数据库的慢查询方法,所述Redis数据库与存储于存储装置中的MySQL数据库连接,所述方法包括:检测所述Redis数据库中存储慢查询记录的列表长度是否达到预定长度,若达到,则将所有慢查询记录存储于所述MySQL数据库中;调用预先构建的HTML页面分页展示所述MySQL数据库中存储的所有慢查询记录;响应用户输入的检索策略在所述MySQL数据库中查找对应的慢查询记录,并显示于所述HTML页面。In the first aspect, the embodiment of the present invention provides a kind of slow query method based on Redis database, and described Redis database is connected with the MySQL database stored in storage device, and described method comprises: detecting and storing slow query record in described Redis database Whether the length of the list reaches the predetermined length, if so, then store all the slow query records in the MySQL database; call the pre-built HTML page pagination to display all the slow query records stored in the MySQL database; respond to user input retrieval The strategy searches the corresponding slow query records in the MySQL database and displays them on the HTML page.

第二方面,本发明实施例还提供了一种基于Redis数据库的慢查询装置,所述Redis数据库与存储于存储装置中的MySQL数据库连接,所述装置包括:检测模块,用于检测所述Redis数据库中存储慢查询记录的列表长度是否达到预定长度,若达到,则将所有慢查询记录存储于所述MySQL数据库中;展示模块,用于调用预先构建的HTML页面分页展示所述MySQL数据库中存储的所有慢查询记录;查找模块,用于响应用户输入的检索策略在所述MySQL数据库中查找对应的慢查询记录,并显示于所述HTML页面。In a second aspect, the embodiment of the present invention also provides a slow query device based on a Redis database, the Redis database is connected to a MySQL database stored in a storage device, and the device includes: a detection module for detecting the Redis Whether the list length of storing slow query records in the database reaches a predetermined length, if reached, then all slow query records are stored in the MySQL database; the display module is used to call pre-built HTML pages to display the stored in the MySQL database All slow query records; a search module, configured to search for corresponding slow query records in the MySQL database in response to the retrieval strategy input by the user, and display them on the HTML page.

第三方面,本发明实施例还提供了一种终端设备,所述终端设备包括存储器和处理器,所述存储器用于存储计算机程序代码,所述处理器用于执行存储于所述存储器中的计算机程序代码以实现所述的基于Redis数据库的慢查询方法。In the third aspect, the embodiment of the present invention also provides a terminal device, the terminal device includes a memory and a processor, the memory is used to store computer program codes, and the processor is used to execute the computer code stored in the memory The program code is to realize the described slow query method based on the Redis database.

本发明实施例提供的一种基于Redis数据库的慢查询方法、装置及终端设备,该Redis数据库与存储于存储装置中的MySQL数据库连接。该基于Redis数据库的慢查询方法包括:检测该Redis数据库中存储慢查询记录的列表长度是否达到预定长度,若达到,则将所有慢查询记录存储于MySQL数据库中,进而调用预先构建的HTML页面分页展示MySQL数据库中存储的所有慢查询记录,且用户可根据输入的检索策略在MySQL数据库中查找对应的慢查询记录,并显示于HTML页面中。由此可见,本方案中,通过将Redis数据库中所有的慢查询记录定时的存储于MySQL数据库中,且通过HTML页面展示于用户,使得用户可通过检索策略方便地进行查询和使用。Embodiments of the present invention provide a slow query method, device and terminal equipment based on a Redis database, where the Redis database is connected to a MySQL database stored in a storage device. The slow query method based on the Redis database includes: detecting whether the length of the list of stored slow query records in the Redis database reaches a predetermined length, if reached, storing all the slow query records in the MySQL database, and then calling the pre-built HTML page pagination Displays all slow query records stored in the MySQL database, and users can search the corresponding slow query records in the MySQL database according to the entered search strategy, and display them on the HTML page. It can be seen that in this solution, all the slow query records in the Redis database are stored in the MySQL database at regular intervals, and displayed to users through HTML pages, so that users can conveniently query and use them through retrieval strategies.

附图说明Description of drawings

为了更清楚地说明本发明实施例的技术方案,下面将对实施例中所需要使用的附图作简单地介绍。In order to illustrate the technical solutions of the embodiments of the present invention more clearly, the following will briefly introduce the drawings used in the embodiments.

图1示出了本发明实施例提供的一种终端设备的结构示意图。Fig. 1 shows a schematic structural diagram of a terminal device provided by an embodiment of the present invention.

图2示出了本发明实施例提供的一种基于Redis数据库的慢查询方法的流程示意图。FIG. 2 shows a schematic flowchart of a slow query method based on a Redis database provided by an embodiment of the present invention.

图3示出了本发明实施例提供的另一种基于Redis数据库的慢查询方法的流程示意图。FIG. 3 shows a schematic flowchart of another slow query method based on a Redis database provided by an embodiment of the present invention.

图4示出了本发明实施例提供的一种基于Redis数据库的慢查询装置的功能模块示意图。FIG. 4 shows a schematic diagram of functional modules of a Redis database-based slow query device provided by an embodiment of the present invention.

图示:100-终端设备;110-基于Redis数据库的慢查询装置;120-存储器;130-存储控制器;140-处理器;150-外设接口;160-输入输出单元;170-音频单元;180-显示单元;111-配置模块;112-检测模块;113-清空模块;114-展示模块;115-查找模块。Illustration: 100-terminal equipment; 110-slow query device based on Redis database; 120-memory; 130-storage controller; 140-processor; 150-peripheral interface; 160-input and output unit; 170-audio unit; 180-display unit; 111-configuration module; 112-detection module; 113-clearing module; 114-display module; 115-finding module.

具体实施方式Detailed ways

下面将结合本发明实施例中附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本发明一部分实施例,而不是全部的实施例。The following will clearly and completely describe the technical solutions in the embodiments of the present invention with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only some, not all, embodiments of the present invention.

应注意到:相似的标号和字母在下面的附图中表示类似项,因此,一旦某一项在一个附图中被定义,则在随后的附图中不需要对其进行进一步定义和解释。同时,在本发明的描述中,术语“第一”、“第二”等仅用于区分描述,而不能理解为指示或暗示相对重要性。It should be noted that like numerals and letters denote similar items in the following figures, therefore, once an item is defined in one figure, it does not require further definition and explanation in subsequent figures. Meanwhile, in the description of the present invention, the terms "first", "second", etc. are only used to distinguish descriptions, and cannot be understood as indicating or implying relative importance.

该Redis数据库为一个整套的缓存系统,其主要用于缓存慢查询记录。对Redis数据库进行查找数据的过程称之为查询,将该对Redis数据库查找数据的过程减慢就是慢查询,换句话说,慢查询也是数据查询的一种方式,但是其用时较于普通的查询用时更长。该慢查询记录为慢查询过程所产生的数据,如用户发起了一个订单,为了更快地响应用户,系统将该订单加入消息队列中,实际上该消息队列是存储于Redis数据库这一缓存中,进而将该订单信息称之为一个慢查询记录。The Redis database is a complete caching system, which is mainly used to cache slow query records. The process of finding data on the Redis database is called query. Slowing down the process of finding data on the Redis database is slow query. In other words, slow query is also a way of data query, but it takes more time than ordinary query Takes longer. The slow query record is the data generated during the slow query process. If a user initiates an order, in order to respond to the user faster, the system adds the order to the message queue. In fact, the message queue is stored in the cache of the Redis database. , and then call the order information a slow query record.

在现有技术中,该Redis数据库存储多个慢查询记录后,将自动覆盖时间期限较早的记录,使得用户不便于查找早期的记录。同时,只有特定权限的人员才能通过Redis命令在Redis数据库查找相关记录,其使用非常不方便。由此,本发明实施例提供一种基于Redis数据库的慢查询方法,以实现通过提供可视化的界面方便用户查找和使用。In the prior art, after the Redis database stores a plurality of slow query records, it will automatically cover records with an earlier time limit, making it inconvenient for users to search for earlier records. At the same time, only personnel with specific permissions can search for relevant records in the Redis database through Redis commands, which is very inconvenient to use. Therefore, the embodiment of the present invention provides a slow query method based on the Redis database, so as to provide a visual interface to facilitate user search and use.

该基于Redis数据库的慢查询方法应用于终端设备中,该终端设备可以是,但不限于,电脑、平板电脑等智能电子设备。请参照图1,是本发明实施例提供的一种终端设备100的结构示意图,该终端设备100包括基于Redis数据库的慢查询装置110、存储器120、存储控制器130、处理器140、外设接口150、输入输出单元160、音频单元170以及显示单元180。The slow query method based on the Redis database is applied to a terminal device, and the terminal device may be, but not limited to, an intelligent electronic device such as a computer or a tablet computer. Please refer to FIG. 1 , which is a schematic structural diagram of a terminal device 100 provided by an embodiment of the present invention. The terminal device 100 includes a slow query device 110 based on a Redis database, a memory 120, a storage controller 130, a processor 140, and a peripheral interface. 150 , an input and output unit 160 , an audio unit 170 and a display unit 180 .

所述存储器120、存储控制器130、处理器140、外设接口150、输入输出单元160、音频单元170、显示单元180各元件相互之间直接或间接地电性连接,以实现数据的传输或交互。例如,这些元件相互之间可通过一条或多条通讯总线或信号线实现电性连接。所述基于Redis数据库的慢查询装置110包括至少一个可以软件或固件(firmware)的形式存储于所述存储器120中或固化在所述终端设备100的操作系统(operating system,OS)中的软件功能模块。所述处理器140用于执行存储器120中存储的可执行模块,例如所述基于Redis数据库的慢查询装置110包括的软件功能模块或计算机程序。The memory 120, storage controller 130, processor 140, peripheral interface 150, input and output unit 160, audio unit 170, and display unit 180 are electrically connected to each other directly or indirectly to realize data transmission or interact. For example, these components can be electrically connected to each other through one or more communication buses or signal lines. The slow query device 110 based on the Redis database includes at least one software function that can be stored in the memory 120 in the form of software or firmware (firmware) or solidified in the operating system (operating system, OS) of the terminal device 100 module. The processor 140 is configured to execute executable modules stored in the memory 120 , such as software function modules or computer programs included in the Redis database-based slow query device 110 .

其中,存储器120可以是,但不限于,随机存取存储器(Random Access Memory,RAM),只读存储器(Read Only Memory,ROM),可编程只读存储器(Programmable Read-OnlyMemory,PROM),可擦除只读存储器(Erasable Programmable Read-Only Memory,EPROM),电可擦除只读存储器(Electric Erasable Programmable Read-Only Memory,EEPROM)等。其中,存储器120用于存储程序,所述处理器140在接收到执行指令后,执行所述程序,本发明实施例任一实施例揭示的流过程定义的终端设备100所执行的方法可以应用于处理器140中,或者由处理器140实现。Wherein, memory 120 can be, but not limited to, random access memory (Random Access Memory, RAM), read-only memory (Read Only Memory, ROM), programmable read-only memory (Programmable Read-OnlyMemory, PROM), erasable In addition to read-only memory (Erasable Programmable Read-Only Memory, EPROM), electrically erasable read-only memory (Electric Erasable Programmable Read-Only Memory, EEPROM), etc. Wherein, the memory 120 is used to store a program, and the processor 140 executes the program after receiving an execution instruction. The method performed by the terminal device 100 defined by the flow process disclosed in any embodiment of the present invention can be applied to In the processor 140, or implemented by the processor 140.

处理器140可能是一种集成电路芯片,具有信号的处理能力。上述的处理器140可以是通用处理器,包括中央处理器(Central Processing Unit,简称CPU)、网络处理器(Network Processor,简称NP)等;还可以是数字信号处理器(DSP)、专用集成电路(ASIC)、现场可编程门阵列(FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件。可以实现或者执行本发明实施例中的公开的各方法、步骤及逻辑框图。通用处理器可以是微处理器或者该处理器140也可以是任何常规的处理器140等。The processor 140 may be an integrated circuit chip with signal processing capability. The above-mentioned processor 140 can be a general-purpose processor, including a central processing unit (Central Processing Unit, referred to as CPU), a network processor (Network Processor, referred to as NP) etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), Field Programmable Gate Array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components. Various methods, steps and logic block diagrams disclosed in the embodiments of the present invention may be implemented or executed. A general purpose processor may be a microprocessor or the processor 140 may be any conventional processor 140 or the like.

所述外设接口150将各种输入/输出装置耦合至处理器140以及存储器120。在一些实施例中,外设接口150,处理器140以及存储控制器130可以在单个芯片中实现。在其他一些实例中,他们可以分别由独立的芯片实现。The peripherals interface 150 couples various input/output devices to the processor 140 and the memory 120 . In some embodiments, peripheral interface 150, processor 140, and memory controller 130 may be implemented in a single chip. In some other instances, they can be implemented by independent chips respectively.

输入输出单元160用于提供给用户输入数据实现用户与所述终端设备100的交互。所述输入输出单元160可以是,但不限于,鼠标和键盘等。The input and output unit 160 is used to provide the user with input data to realize the interaction between the user and the terminal device 100 . The input and output unit 160 may be, but not limited to, a mouse and a keyboard.

音频单元170向用户提供音频接口,其可包括一个或多个麦克风、一个或者多个扬声器以及音频电路。The audio unit 170 provides an audio interface to the user and may include one or more microphones, one or more speakers, and audio circuitry.

显示单元180在终端设备100与用户之间提供一个交互界面(例如用户操作界面)或用于显示图像数据给用户参考。在本实施例中,所述显示单元180可以是液晶显示器或触控显示器。若为触控显示器,其可为支持单点和多点触控操作的电容式触控屏或电阻式触控屏等。支持单点和多点触控操作是指触控显示器能感应到来自该触控显示器上一个或多个位置处同时产生的触控操作,并将该感应到的触控操作交由处理器140进行计算和处理。The display unit 180 provides an interactive interface (such as a user operation interface) between the terminal device 100 and the user or is used to display image data for the user's reference. In this embodiment, the display unit 180 may be a liquid crystal display or a touch display. If it is a touch display, it can be a capacitive touch screen or a resistive touch screen supporting single-point and multi-touch operations. Supporting single-point and multi-touch operations means that the touch display can sense simultaneous touch operations from one or more locations on the touch display, and hand over the sensed touch operations to the processor 140 Perform calculations and processing.

请参照图2,是本发明实施例提供的一种基于Redis数据库的慢查询方法的流程示意图,该方法包括:Please refer to Fig. 2, which is a schematic flow diagram of a slow query method based on a Redis database provided by an embodiment of the present invention, the method comprising:

步骤S110,检测所述Redis数据库中存储慢查询记录的列表长度是否达到预定长度,若达到,则将所有慢查询记录存储于所述MySQL数据库中。Step S110, detecting whether the length of the list storing slow query records in the Redis database reaches a predetermined length, and if so, storing all slow query records in the MySQL database.

具体为,使用慢查询记录检查函数通过slowlog len命令检测Redis数据库中存储慢查询记录的列表长度是否达到预定长度,该预定长度可自定义设置,如该预定长度可以为1024。如果达到这个预定长度,则表明当前Redis数据库存储已满,则将Redis数据库中所有的慢查询记录查找出来后,存储于关系数据库MySQL数据库中。更进一步地,调用Django-celery任务调度函数定时调度慢查询记录检查函数,去检测该Redis数据库中存储慢查询记录的列表长度是否达到预定长度,如每五分钟调度一次,使得Redis数据库不至于数据过满,影响响应速度。Specifically, use the slow query record check function to detect whether the length of the list of slow query records stored in the Redis database reaches a predetermined length through the slowlog len command. The predetermined length can be customized, for example, the predetermined length can be 1024. If the predetermined length is reached, it indicates that the current Redis database storage is full, and all slow query records in the Redis database are found and stored in the relational database MySQL database. Furthermore, call the Django-celery task scheduling function to regularly schedule the slow query record checking function to detect whether the length of the list of slow query records stored in the Redis database reaches the predetermined length, such as scheduling once every five minutes, so that the Redis database will not be full of data Too full will affect the response speed.

需要说明的是,该Redis数据库为一个缓存系统,通常情况下,将用户的慢查询记录存储于Redis数据库中,以便于对用户的操作进行快速响应。该MySQL数据库为存储于存储装置(如硬盘)中的关系数据库,通常用于存储需长期保存的数据,以便于数据的查询。此外,将慢查询记录存储于MySQL数据库的格式为:该MySQL数据库中将预先定义数据表,每个数据表中将定义数据类型,如该数据类型包括字符串类型ip、数字类型port、日期类型query_time、数字类型execute_time、字符串类型query、日期类型create_time等。其中,字符串类型ip用来存放Redis数据库的ip地址,数字类型port用来存放Redis数据库的端口,日期类型query_time用来存放慢查询发生的时间,数字类型execute_time用来存放慢查询运行的时间长度,单位为微秒,字符串类型query用来存放具体慢查询的语句,日期类型create_time用来存放具体插入这条记录的时间。It should be noted that the Redis database is a cache system. Usually, the user's slow query records are stored in the Redis database, so as to respond quickly to the user's operations. The MySQL database is a relational database stored in a storage device (such as a hard disk), and is usually used to store data that needs to be stored for a long time, so as to facilitate data query. In addition, the format for storing slow query records in the MySQL database is: the MySQL database will pre-define the data table, and each data table will define the data type, such as the data type includes string type ip, number type port, date type query_time, number type execute_time, string type query, date type create_time, etc. Among them, the string type ip is used to store the ip address of the Redis database, the number type port is used to store the port of the Redis database, the date type query_time is used to store the time when the slow query occurs, and the number type execute_time is used to store the running time of the slow query , the unit is microseconds, the string type query is used to store the specific slow query statement, and the date type create_time is used to store the specific insertion time of this record.

步骤S120,调用预先构建的HTML页面分页展示所述MySQL数据库中存储的所有慢查询记录。Step S120, calling a pre-built HTML page to display all slow query records stored in the MySQL database by paging.

具体为,为了使得用户便于查询存储于MySQL数据库中的慢查询记录,故利用django框架预先构建HTML页面,以分页展示MySQL数据库中存储的所有慢查询记录,并提供各种条件维度的筛选功能,如通过字符串类型ip、数字类型port、日期类型query_time、数字类型execute_time等对慢查询记录进行筛选。换句话说,用户可根据自己的需求选取相应的关键词对目标慢查询记录进行筛选。Specifically, in order to make it easier for users to query the slow query records stored in the MySQL database, the django framework is used to pre-build HTML pages to display all the slow query records stored in the MySQL database by paging, and provide filtering functions for various conditional dimensions. For example, filter slow query records by string type ip, number type port, date type query_time, number type execute_time, etc. In other words, users can select corresponding keywords to filter target slow query records according to their needs.

步骤S130,响应用户输入的检索策略在所述MySQL数据库中查找对应的慢查询记录,并显示于所述HTML页面。Step S130, searching the corresponding slow query record in the MySQL database in response to the retrieval strategy input by the user, and displaying it on the HTML page.

具体为,该检索策略为用户构建的满足SQL语言的检索式,以通过该检索式在MySQL数据库中查找对应的慢查询记录,同时查询得到的慢查询记录将实时展现于HTML页面。该检索过程具体为:将用户在前端HTML页面中选取的条件纬度,通过ajax post传递到后端,再利用Python的pymysql模块连接后端存储数据库的MySQL数据库,把查询出对应的数据用Python的json模块封装成json的格式,返回到前端页面展示出来。Specifically, the retrieval strategy is a retrieval formula that satisfies the SQL language constructed by the user, so that the corresponding slow query records can be found in the MySQL database through the retrieval formula, and the slow query records obtained by the query will be displayed on the HTML page in real time. The retrieval process is as follows: transfer the conditional latitude selected by the user in the front-end HTML page to the back-end through ajax post, and then use Python's pymysql module to connect to the MySQL database of the back-end storage database, and query the corresponding data with Python's The json module is packaged in json format and returned to the front-end page to display.

由此可见,本发明实施例提供的基于Redis数据库的慢查询方法,可使得用户直接通过web页面访问长期存储于MySQL数据库中的慢查询记录,其访问和查询方便,避免了用户直接通过Redis命令访问Redis数据库对Redis产生的安全隐患。同时,该MySQL数据库中的慢查询记录可长期保存,用户可以根据自己的需求查找到早期的慢查询记录,所有的慢查询记录都能永久保存,不易丢失。It can be seen that the slow query method based on the Redis database provided by the embodiment of the present invention can make the user directly access the slow query record stored in the MySQL database for a long time through the web page, which is convenient for access and query, and avoids the user directly passing the Redis command. Access to the Redis database poses a security risk to Redis. At the same time, the slow query records in the MySQL database can be stored for a long time, and users can find early slow query records according to their own needs. All slow query records can be stored permanently and are not easy to lose.

请参照图3,是本发明实施例提供的另一种基于Redis数据库的慢查询方法的流程示意图,该方法包括:Please refer to FIG. 3 , which is a schematic flow diagram of another slow query method based on a Redis database provided by an embodiment of the present invention, the method comprising:

步骤S210,配置所述Redis数据库中记录查询时间大于预定时间的记录为慢查询记录。Step S210, configuring records in the Redis database whose record query time is longer than a predetermined time as slow query records.

即是说,为每一个Redis数据库开启慢查询配置,具体包括两方面的配置,一方面为配置预定时间,当记录的查询时间大于预定时间,则认定该条记录为慢查询记录,另一方面为配置记录条数,当Redis数据库中的慢查询记录多于这个记录条数时,则将Redis数据库中所有慢查询记录存储入MySQL数据库中。具体的配置方式为:config set slowlog-log-slower-than 20000config set slowlog-max-len 1024该条语句配置了Redis数据库最多能记录1024条,且当查询时间大于20000微秒的查询为慢查询。That is to say, the slow query configuration is enabled for each Redis database, which specifically includes two aspects of configuration. One is to configure the scheduled time. When the query time of the record is greater than the scheduled time, the record is considered to be a slow query record. To configure the number of records, when the number of slow query records in the Redis database exceeds this number of records, all slow query records in the Redis database will be stored in the MySQL database. The specific configuration method is: config set slowlog-log-slower-than 20000config set slowlog-max-len 1024 This statement configures the Redis database to record up to 1024 entries, and when the query time is greater than 20000 microseconds, it is a slow query.

步骤S220,调用任务调度函数定时调度慢查询记录检查函数,检查所述Redis数据库中存储慢查询记录的列表长度是否达到预定长度,若达到,则将所有慢查询记录存储于所述MySQL数据库中。Step S220, calling the task scheduling function to regularly schedule the slow query record checking function to check whether the length of the list of stored slow query records in the Redis database reaches a predetermined length, and if so, store all the slow query records in the MySQL database.

具体为,使用慢查询记录检查函数通过slowlog len命令检测Redis数据库中存储慢查询记录的列表长度是否达到预定长度,该预定长度可自定义设置,如该预定长度可以为1024。如果达到这个预定长度,则表明当前Redis数据库存储已满,则将Redis数据库中所有的慢查询记录查找出来后,存储于关系数据库MySQL数据库中。更进一步地,调用Django-celery任务调度函数定时调度慢查询记录检查函数,去检测该Redis数据库中存储慢查询记录的列表长度是否达到预定长度,如每五分钟调度一次,使得Redis数据库不至于数据过满,影响响应速度。Specifically, use the slow query record check function to detect whether the length of the list of slow query records stored in the Redis database reaches a predetermined length through the slowlog len command. The predetermined length can be customized, for example, the predetermined length can be 1024. If the predetermined length is reached, it indicates that the current Redis database storage is full, and all slow query records in the Redis database are found and stored in the relational database MySQL database. Furthermore, call the Django-celery task scheduling function to regularly schedule the slow query record checking function to detect whether the length of the list of slow query records stored in the Redis database reaches the predetermined length, such as scheduling once every five minutes, so that the Redis database will not be full of data Too full will affect the response speed.

步骤S230,清空当前的Redis数据库,以便于所述Redis数据库能继续存储新的慢查询记录。Step S230, clearing the current Redis database, so that the Redis database can continue to store new slow query records.

即是说,将当前Redis数据库中所有的慢查询记录查找出来,存储于关系数据库MySQL数据库中后,需使用slowlog reset清空当前Redis数据库,以便于Redis数据库能继续存储新的慢查询记录。That is to say, after finding all the slow query records in the current Redis database and storing them in the relational database MySQL database, you need to use slowlog reset to clear the current Redis database so that the Redis database can continue to store new slow query records.

步骤S240,调用预先构建的HTML页面分页展示所述MySQL数据库中存储的所有慢查询记录。Step S240, calling a pre-built HTML page to display all slow query records stored in the MySQL database by paging.

具体为,为了使得用户便于查询存储于MySQL数据库中的慢查询记录,故利用django框架预先构建HTML页面,以分页展示MySQL数据库中存储的所有慢查询记录,并提供各种条件维度的筛选功能,如通过字符串类型ip、数字类型port、日期类型query_time、数字类型execute_time等对慢查询记录进行筛选。换句话说,用户可根据自己的需求选取相应的关键词对目标慢查询记录进行筛选。Specifically, in order to make it easier for users to query the slow query records stored in the MySQL database, the django framework is used to pre-build HTML pages to display all the slow query records stored in the MySQL database by paging, and provide filtering functions for various conditional dimensions. For example, filter slow query records by string type ip, number type port, date type query_time, number type execute_time, etc. In other words, users can select corresponding keywords to filter target slow query records according to their needs.

步骤S250,响应用户输入的检索策略在所述MySQL数据库中查找对应的慢查询记录,并显示于所述HTML页面。Step S250, searching for the corresponding slow query record in the MySQL database in response to the retrieval strategy input by the user, and displaying it on the HTML page.

具体为,该检索策略为用户构建的满足SQL语言的检索式,以通过该检索式在MySQL数据库中查找对应的慢查询记录,同时查询得到的慢查询记录将实时展现于HTML页面。该检索过程具体为:将用户在前端HTML页面中选取的条件纬度,通过ajax post传递到后端,再利用Python的pymysql模块连接后端存储数据库的MySQL数据库,把查询出对应的数据用Python的json模块封装成json的格式,返回到前端页面展示出来Specifically, the retrieval strategy is a retrieval formula that satisfies the SQL language constructed by the user, so that the corresponding slow query records can be found in the MySQL database through the retrieval formula, and the slow query records obtained by the query will be displayed on the HTML page in real time. The retrieval process is as follows: transfer the conditional latitude selected by the user in the front-end HTML page to the back-end through ajax post, and then use Python's pymysql module to connect to the MySQL database of the back-end storage database, and query the corresponding data with Python's The json module is encapsulated into json format, and returned to the front-end page to display it

请参照图4,是本发明实施例提供的一种基于Redis数据库的慢查询装置110的功能模块示意图,该装置包括配置模块111、检测模块112、清空模块113、展示模块114以及查找模块115。Please refer to FIG. 4 , which is a schematic diagram of functional modules of a slow query device 110 based on a Redis database provided by an embodiment of the present invention.

配置模块111,用于配置所述Redis数据库中记录查询时间大于预定时间的记录为慢查询记录。The configuration module 111 is configured to configure records in the Redis database whose record query time is longer than a predetermined time as slow query records.

在本发明实施例中,步骤S210可以由配置模块111执行。In the embodiment of the present invention, step S210 may be executed by the configuration module 111 .

检测模块112,用于检测所述Redis数据库中存储慢查询记录的列表长度是否达到预定长度,若达到,则将所有慢查询记录存储于所述MySQL数据库中。The detection module 112 is configured to detect whether the length of the list storing slow query records in the Redis database reaches a predetermined length, and if so, store all slow query records in the MySQL database.

在本发明实施例中,步骤S110和步骤S220可以由检测模块112执行。In the embodiment of the present invention, step S110 and step S220 may be executed by the detection module 112 .

清空模块113,用于清空当前的Redis数据库,以便于所述Redis数据库能继续存储新的慢查询记录。Empty module 113 is used for emptying the current Redis database, so that the Redis database can continue to store new slow query records.

在本发明实施例中,步骤S230可以由清空模块113执行。In the embodiment of the present invention, step S230 may be executed by the emptying module 113 .

展示模块114,用于调用预先构建的HTML页面分页展示所述MySQL数据库中存储的所有慢查询记录。The display module 114 is configured to call a pre-built HTML page to display all slow query records stored in the MySQL database by paging.

在本发明实施例中,步骤S120和步骤S240可以由展示模块114执行。In the embodiment of the present invention, step S120 and step S240 may be performed by the presentation module 114 .

查找模块115,用于响应用户输入的检索策略在所述MySQL数据库中查找对应的慢查询记录,并显示于所述HTML页面。The search module 115 is configured to search the corresponding slow query record in the MySQL database in response to the search strategy input by the user, and display it on the HTML page.

在本发明实施例中,步骤S130和步骤S250可以由查找模块115执行。In the embodiment of the present invention, step S130 and step S250 may be executed by the search module 115 .

由于在基于Redis数据库的慢查询方法中已经详细描述,在此不再赘述。Since it has been described in detail in the slow query method based on Redis database, it will not be repeated here.

综上所述,本发明实施例提供的一种基于Redis数据库的慢查询方法、装置及终端设备,该Redis数据库与存储于存储装置中的MySQL数据库连接。该基于Redis数据库的慢查询方法包括:检测该Redis数据库中存储慢查询记录的列表长度是否达到预定长度,若达到,则将所有慢查询记录存储于MySQL数据库中,进而调用预先构建的HTML页面分页展示MySQL数据库中存储的所有慢查询记录,且用户可根据输入的检索策略在MySQL数据库中查找对应的慢查询记录,并显示于HTML页面中。由此可见,本方案中,通过将Redis数据库中所有的慢查询记录定时的存储于MySQL数据库中,且通过HTML页面展示于用户,使得用户可通过检索策略方便地进行查询和使用。In summary, the embodiments of the present invention provide a slow query method, device and terminal equipment based on a Redis database. The Redis database is connected to a MySQL database stored in a storage device. The slow query method based on the Redis database includes: detecting whether the length of the list of stored slow query records in the Redis database reaches a predetermined length, if reached, storing all the slow query records in the MySQL database, and then calling the pre-built HTML page pagination Displays all slow query records stored in the MySQL database, and users can search the corresponding slow query records in the MySQL database according to the entered search strategy, and display them on the HTML page. It can be seen that in this solution, all the slow query records in the Redis database are stored in the MySQL database at regular intervals, and displayed to users through HTML pages, so that users can conveniently query and use them through retrieval strategies.

在本申请所提供的几个实施例中,应该理解到,所揭露的装置和方法,也可以通过其它的方式实现。以上所描述的装置实施例仅仅是示意性的,例如,附图中的流程图和框图显示了根据本发明的多个实施例的装置、方法和计算机程序产品的可能实现的体系架构、功能和操作。在这点上,流程图或框图中的每个方框可以代表一个模块、程序段或代码的一部分,所述模块、程序段或代码的一部分包含一个或多个用于实现规定的逻辑功能的可执行指令。也应当注意,在有些作为替换的实现方式中,方框中所标注的功能也可以以不同于附图中所标注的顺序发生。例如,两个连续的方框实际上可以基本并行地执行,它们有时也可以按相反的顺序执行,这依所涉及的功能而定。也要注意的是,框图和/或流程图中的每个方框、以及框图和/或流程图中的方框的组合,可以用执行规定的功能或动作的专用的基于硬件的系统来实现,或者可以用专用硬件与计算机指令的组合来实现。In the several embodiments provided in this application, it should be understood that the disclosed devices and methods may also be implemented in other ways. The device embodiments described above are only illustrative. For example, the flowcharts and block diagrams in the accompanying drawings show the architecture, functions and possible implementations of devices, methods and computer program products according to multiple embodiments of the present invention. operate. In this regard, each block in a flowchart or block diagram may represent a module, program segment, or part of code that includes one or more Executable instructions. It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks in succession may, in fact, be executed substantially concurrently, or they may sometimes be executed in the reverse order, depending upon the functionality involved. It should also be noted that each block of the block diagrams and/or flowchart illustrations, and combinations of blocks in the block diagrams and/or flowchart illustrations, can be implemented by a dedicated hardware-based system that performs the specified function or action , or may be implemented by a combination of dedicated hardware and computer instructions.

另外,在本发明各个实施例中的各功能模块可以集成在一起形成一个独立的部分,也可以是各个模块单独存在,也可以两个或两个以上模块集成形成一个独立的部分。In addition, each functional module in each embodiment of the present invention can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.

所述功能如果以软件功能模块的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本发明的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本发明各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,Random Access Memory)、磁碟或者光盘等各种可以存储程序代码的介质。需要说明的是,在本文中,诸如第一和第二等之类的关系术语仅仅用来将一个实体或者操作与另一个实体或操作区分开来,而不一定要求或者暗示这些实体或操作之间存在任何这种实际的关系或者顺序。If the functions are implemented in the form of software function modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the essence of the technical solution of the present invention or the part that contributes to the prior art or the part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including Several instructions are used to make a computer device (which may be a personal computer, a server, or a network device, etc.) execute all or part of the steps of the methods described in various embodiments of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), magnetic disk or optical disk and other media that can store program codes. . It should be noted that in this article, relational terms such as first and second are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply that there is a relationship between these entities or operations. There is no such actual relationship or order between them.

以上所述,仅为本发明的具体实施方式,但本发明的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本发明揭露的技术范围内,可轻易想到变化或替换,都应涵盖在本发明的保护范围之内。The above is only a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Anyone skilled in the art can easily think of changes or substitutions within the technical scope disclosed in the present invention. Should be covered within the protection scope of the present invention.

Claims (10)

CN201810327855.3A2018-04-122018-04-12 Slow query method, device and terminal device based on Redis databaseActiveCN108563744B (en)

Priority Applications (1)

Application NumberPriority DateFiling DateTitle
CN201810327855.3ACN108563744B (en)2018-04-122018-04-12 Slow query method, device and terminal device based on Redis database

Applications Claiming Priority (1)

Application NumberPriority DateFiling DateTitle
CN201810327855.3ACN108563744B (en)2018-04-122018-04-12 Slow query method, device and terminal device based on Redis database

Publications (2)

Publication NumberPublication Date
CN108563744Atrue CN108563744A (en)2018-09-21
CN108563744B CN108563744B (en)2021-07-23

Family

ID=63534822

Family Applications (1)

Application NumberTitlePriority DateFiling Date
CN201810327855.3AActiveCN108563744B (en)2018-04-122018-04-12 Slow query method, device and terminal device based on Redis database

Country Status (1)

CountryLink
CN (1)CN108563744B (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN109656959A (en)*2018-12-242019-04-19拉扎斯网络科技(上海)有限公司Data query method and device, electronic equipment and storage medium
CN111258973A (en)*2020-01-172020-06-09广州虎牙科技有限公司Storage and display method, device, equipment and medium of Redis slow log
CN111752975A (en)*2020-05-282020-10-09中国平安财产保险股份有限公司Data loading method and device based on Redis, computer equipment and storage medium

Citations (5)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN103838867A (en)*2014-03-202014-06-04网宿科技股份有限公司Log processing method and device
CN105243147A (en)*2015-10-222016-01-13浪潮(北京)电子信息产业有限公司Slow query log management method and system of MySQL database
CN105446893A (en)*2014-07-142016-03-30阿里巴巴集团控股有限公司Data storage method and device
CN107220304A (en)*2017-05-102017-09-29杭州铭师堂教育科技发展有限公司The slow Log Administration Systems of magnanimity mongodb based on salt
WO2017166898A1 (en)*2016-03-282017-10-05北京京东尚科信息技术有限公司Method and system for matching multi-dimensional data units in electronic information system

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN103838867A (en)*2014-03-202014-06-04网宿科技股份有限公司Log processing method and device
CN105446893A (en)*2014-07-142016-03-30阿里巴巴集团控股有限公司Data storage method and device
CN105243147A (en)*2015-10-222016-01-13浪潮(北京)电子信息产业有限公司Slow query log management method and system of MySQL database
WO2017166898A1 (en)*2016-03-282017-10-05北京京东尚科信息技术有限公司Method and system for matching multi-dimensional data units in electronic information system
CN107220304A (en)*2017-05-102017-09-29杭州铭师堂教育科技发展有限公司The slow Log Administration Systems of magnanimity mongodb based on salt

Cited By (3)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN109656959A (en)*2018-12-242019-04-19拉扎斯网络科技(上海)有限公司Data query method and device, electronic equipment and storage medium
CN111258973A (en)*2020-01-172020-06-09广州虎牙科技有限公司Storage and display method, device, equipment and medium of Redis slow log
CN111752975A (en)*2020-05-282020-10-09中国平安财产保险股份有限公司Data loading method and device based on Redis, computer equipment and storage medium

Also Published As

Publication numberPublication date
CN108563744B (en)2021-07-23

Similar Documents

PublicationPublication DateTitle
US20180232438A1 (en)Title display method and apparatus
CN106951148B (en)Page switching method and device
CN108874289B (en)Application history record viewing method and device and electronic equipment
CN104899220B (en)Application program recommendation method and system
US9299098B2 (en)Systems for generating a global product taxonomy
TWI621062B (en) Method and device for searching message record in touch screen terminal
CN106991179B (en) Data deletion method, device and mobile terminal
US20150022482A1 (en)Multi-touch management for touch screen displays
CN106610988B (en)Webpage recommendation method and recommendation device
CN107612908B (en) Web page tampering monitoring method and device
JP7021292B2 (en) User-recommended methods and equipment
CN105095423B (en)Enumeration data wiring method and device
CN108563744A (en)Slow querying method, device and terminal device based on Redis databases
WO2019042165A1 (en)Search result optimization method and apparatus, server, and readable storage medium
CN108304274A (en) A method for information interaction, server and computer-readable medium
CN111782953A (en) Recommended method, apparatus, equipment and storage medium
CN106528889B (en) A kind of information search method and terminal
CN105378604B (en)Trend suggestion
CN103914519A (en)Recommendation method and device
CN111783410A (en) Form field screening method, device, computer equipment and storage medium
CN113094224B (en) Server asset management method, apparatus, computer equipment and storage medium
CN107480240B (en)Database system and data processing method thereof
CN106325684B (en)Operation item selection state display method and device
WO2019001333A1 (en)Application interface display method, apparatus and electronic device
CN110851346B (en)Query statement boundary problem detection method, device, equipment and storage medium

Legal Events

DateCodeTitleDescription
PB01Publication
PB01Publication
SE01Entry into force of request for substantive examination
SE01Entry into force of request for substantive examination
GR01Patent grant
GR01Patent grant
TR01Transfer of patent right

Effective date of registration:20241213

Address after:Building 8, No. 33, Guangshun Road, Changning District, Shanghai 200050

Patentee after:Shanghai Jiuyan Information Technology Co.,Ltd.

Country or region after:China

Address before:11 / F, building B1, phase 4.1, software industry, No. 1, Software Park East Road, Wuhan, Hubei 430000

Patentee before:WUHAN DOUYU NETWORK TECHNOLOGY Co.,Ltd.

Country or region before:China

TR01Transfer of patent right

[8]ページ先頭

©2009-2025 Movatter.jp