Knowledge fast indexing method of data interoperation test knowledge base based on Redis cache
Technical Field
The invention belongs to the field of data interoperability test processing, and particularly relates to a knowledge fast indexing method of a data interoperability test knowledge base based on Redis cache.
Background
With the development of information technology, a large amount of knowledge data needs to be quickly retrieved and returned to a user. In the process of carrying out data interoperation test, a large amount of knowledge experiences are formed, and the knowledge is summarized and sorted to form a knowledge base, so that the method has great research value. How to quickly retrieve the corresponding knowledge data becomes a difficulty. Each search request of the traditional knowledge base needs to directly operate the database, so that the retrieval efficiency is low directly, and by utilizing the memory-based characteristic of Redis, hot spot data can be preloaded in advance. The retrieval efficiency can be effectively improved. Redis is used as a key-value store database. It supports relatively more stored value types, including string, list, set, zset and hash. These data types all support push/pop, add/remove, and intersect union and difference, and richer operations, and these operations are all atomic. On this basis, Redis supports various different ways of ordering. To ensure efficiency, data is cached in memory. This also creates the fast read and write feature of Redis.
Since Redis stores all data in memory, its read and write performance is very dramatic. Redis also has a persistent characteristic, and can store memory data on a hard disk in the form of snapshots and logs, so that the problem of data loss in the memory when power is cut off or a machine fails is avoided.
The Redis database is written by C language and is relatively close to the operating system, so that the performance is higher on reading and writing data, and the problem of searching efficiency can be solved. And Redis is single-threaded in the framework, so that the problem of multi-thread competition is avoided, and the method can be well applied to the knowledge search scene with large concurrency.
Disclosure of Invention
The present invention is directed to solving the above problems of the prior art. The knowledge fast indexing method for the data interoperation test knowledge base based on the Redis cache is provided, multi-thread competition is avoided, and searching efficiency is improved. The technical scheme of the invention is as follows:
a knowledge fast indexing method of a data interoperability test knowledge base based on Redis cache comprises the following steps:
a. establishing a Redis memory database and an associated operation rule of the Redis memory database and a Mysql database, wherein the Redis memory database is a Key-Value database, the Mysql database is a relational database, and the associated operation rule is mainly used for associating the Redis memory database with the Mysql in a Key-Value storage mode when the Redis memory database and the Mysql database are established and referred;
b. caching the knowledge data with the searching times ranked at the top n bits in the database into Redis in advance;
c. acquiring knowledge data related to keywords input by a user from a database according to search conditions of the user;
d. if the searching times of the knowledge data enter the first n bits, adding the knowledge data into a Redis cache, and deleting the knowledge data originally stored in the Redis cache;
e. returning the knowledge data read from the Redis cache;
f. and taking the corresponding knowledge id from the knowledge data, searching the knowledge data of the corresponding id in the Mysql database, and returning.
Further, a Redis memory database is created in the step a, and the association operation rule with the Mysql database is mainly created, and the key: knowledge id, value, knowledge title.
Further, when n in step b is 1000, caching the knowledge id and the knowledge title of the knowledge data with the search times ranked at the top 1000 in the database into Redis in advance, and the main steps are as follows:
2.1) firstly judging whether 1000 hot spot data exist in the Redis cache, if not, adding the hot spot data from the Mysql database, wherein the adding rule is that the hot spot data are sorted according to the searching times and added from front to back until the 1000 hot spot data are added into the cache;
2.2) adding the knowledge id and the knowledge header in the knowledge data into the cache.
Furthermore, in the step c, knowledge data related to the keywords input by the user are obtained from the database according to the search conditions of the user, and the main steps are as follows:
3.1) firstly judging the knowledge data, judging whether the knowledge data is ranked in the top 1000 for the number of search times, if so, firstly finding out from a Redis cache, judging whether the knowledge data exists, if so, returning the knowledge data, if not, searching from a Mysql database, adding the Mysql database into the Redis cache, and adding 1 to the number of search times;
3.2) if the number of searches is not top 1000, look up directly from Mysql database.
Further, the step e returns the knowledge data read from the Redis cache, and specifically includes:
returning the matched knowledge data, and adding 1 to the count field data of the knowledge data.
Further, in the step f, the corresponding knowledge id is taken from the knowledge data, the knowledge data of the corresponding id is inquired in the Mysql database and returned, and the main steps are as follows:
6.1) acquiring the knowledge id of each data in the set;
6.2) inquiring a Mysql database according to the knowledge id;
6.3) returning the matched knowledge data to the user.
The invention has the following advantages and beneficial effects:
the invention has the innovative points that the hot spot knowledge data n before the search ranking is pre-loaded in advance by utilizing the memory-based characteristics of Redis, so that the efficiency of knowledge indexing can be effectively improved, and the direct access times to Mysql are reduced.
Drawings
FIG. 1 is a flow chart of the operation of the knowledge fast indexing method of the preferred embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be described in detail and clearly with reference to the accompanying drawings. The described embodiments are only some of the embodiments of the present invention.
The technical scheme for solving the technical problems is as follows:
the invention provides a knowledge fast indexing method of a data interoperability test knowledge base based on Redis cache, which is characterized in that the fast indexing of knowledge data is realized by utilizing the characteristic that Redis is high in memory read-write efficiency. The present invention will be described in further detail with reference to the accompanying drawings and specific embodiments.
The first figure shows a flow chart of the knowledge fast indexing method of the data interoperability test knowledge base based on Redis cache, which is specifically realized as follows:
1) establishing a Redis memory database, mainly establishing an associated operation rule with the Mysql database, and key: knowledge id, value, knowledge title;
2) the method comprises the following steps of caching knowledge id and knowledge title of knowledge data with the search times ranked at the top 1000 in a database into Redis in advance, and mainly performing intelligent optimization on high-frequency hot spot data to improve the index efficiency, wherein the method mainly comprises the following steps:
2.1) firstly judging whether 1000 hot spot data exist in the Redis cache, if not, adding the hot spot data from the Mysql database, wherein the adding rule is that the hot spot data are sorted according to the searching times and are added from front to back. Until 1000 hot spot data are added to the cache;
2.2) adding the knowledge id and the knowledge header in the knowledge data into the cache.
3) In the step c, knowledge data related to the keywords input by the user are obtained from the database according to the search conditions of the user, and the method mainly comprises the following steps:
3.1) firstly judging the knowledge data, judging whether the knowledge data is ranked in the top 1000 for the number of search times, if so, firstly finding out from a Redis cache, judging whether the knowledge data exists, if so, returning the knowledge data, if not, searching from a Mysql database, adding the Mysql database into the Redis cache, and adding 1 to the number of search times;
3.2) if the number of searches is not top 1000, look up from Mysql database directly
4) In step d, if the search times of the knowledge data enter the top 1000, adding the knowledge data into the Redis cache, and deleting the knowledge data originally stored in the Redis cache.
5) Step e, returning the knowledge data returned from the Redis cache, and mainly comprising the following steps:
and 5.1) adding the returned data into a list set for unified management.
6) And f, taking the corresponding knowledge id from the knowledge data, inquiring the knowledge data of the corresponding id in the Mysql database and returning, and mainly comprising the following steps:
6.1) acquiring the knowledge id of each data in the set;
6.2) inquiring a Mysql database according to the knowledge id;
6.3) returning the matched knowledge data to the user.
The above examples are to be construed as merely illustrative and not limitative of the remainder of the disclosure. After reading the description of the invention, the skilled person can make various changes or modifications to the invention, and these equivalent changes and modifications also fall into the scope of the invention defined by the claims.