Data writing method and data reading method
By using key-value pair index data and timing identification in the data access method, the problem of low data storage accuracy and efficiency in the prior art is solved, and efficient message data storage and flexible storage expansion are realized.
Patent Information
- Application Number
- CN202510202439.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-21
- Publication Date
- 2025-06-03
AI Technical Summary
The existing data access methods are low in accuracy and efficiency when processing massive user requests, and lack the ability to flexibly expand storage resources.
Through a data writing method, the data to be stored, including message data, information identification and timing identification, the message identification and key-value pair index data are generated, and the index data is stored in the target memory shard based on the target information identification.
It improves the accuracy and efficiency of message data storage, supports horizontal capacity expansion, and provides the ability to flexibly expand storage resources.
Smart Images

Figure CN120085807A_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present application relate to the field of computer technologies, and in particular, to a data writing method, a data reading method, a data writing device, a data reading device, a computer device, a computer-readable storage medium, and a computer program product. Background Art
[0002] With the development of modern Internet technologies and the continuous growth of the number of users, an important challenge faced by major Internet companies is how to efficiently manage and process requests from a vast number of users. Existing data access methods not only have low accuracy and efficiency but also lack the ability to flexibly expand storage resources.
[0003] It should be noted that the above content is not necessarily prior art and does not limit the patent protection scope of the present application. Summary of the Invention
[0004] Embodiments of the present application provide a data writing method, a data reading method, a data writing device, a data reading device, a computer device, a computer-readable storage medium, and a computer program product to solve or alleviate one or more of the above-mentioned technical problems.
[0005] One aspect of embodiments of the present application provides a data writing method, and the method includes: In response to a data storage request, obtain data to be stored; wherein, the data to be stored includes message data, a plurality of information identifiers, and a timing identifier; Store the message data to generate a corresponding message identifier; wherein the message identifier is used to indicate the storage location of the message data; Generate key-value pair index data based on the plurality of information identifiers, the timing identifier, and the message identifier; and Based on a target information identifier among the information identifiers, store the key-value pair index data into a corresponding target memory slice.
[0006] Optionally, the key-value pair index data includes a Key value and a Value value; generating key-value pair index data based on the plurality of information identifiers, the timing identifier, and the message identifier includes: Generate the Key value based on the plurality of information identifiers and the timing identifier; wherein each of the plurality of information identifiers and the timing identifier is respectively distributed in different fields of the Key value; Generate the Value value based on the message identifier.
[0007] Optionally, generating the Key value based on the plurality of information identifiers and the timing identifier includes: Byte-order encode the several information identifiers and timing identifiers respectively to obtain a plurality of byte sequences; wherein, the plurality of byte sequences include: several byte sequences corresponding one-to-one to the several information identifiers, and a byte sequence corresponding to the timing identifier; Write the plurality of byte sequences into an empty key in a preset order to obtain the Key value.
[0008] Optionally, the Key value is also configured with a reserved field.
[0009] Optionally, there are multiple key-value pair index data; the information identifiers among the multiple key-value pair index data are the same, but the timing identifiers among each key-value pair index data are different; Based on the target information identifier in the information identifiers, store the key-value pair index data into the corresponding target memory slice, including: According to the timing identifier of each key-value pair index data, chain and store the multiple key-value pair index data in series.
[0010] Another aspect of the embodiments of the present application provides a data reading method, and the method includes: In response to a data reading request, obtain a target information identifier and a target timestamp range; Based on the target timestamp range, obtain a target timing identifier range; Based on the target information identifier, determine a target memory slice from multiple memory slices; From the target memory slice, obtain one or more message identifiers among the multiple KV values within the target timing identifier range; According to the message identifiers within the target timing identifier range, read the corresponding one or more message data from the database.
[0011] Optionally, the Key value in the KV value includes a timing identifier; the method further includes: In the case of reading multiple message data, sort the multiple message data according to the timing identifiers of each message data; According to the sorting result, return the multiple message data to the request side in sequence.
[0012] Another aspect of the embodiments of the present application provides a data writing device, and the device includes: An acquisition module, configured to acquire data to be stored in response to a data storage request; wherein, the data to be stored includes message data, several information identifiers and a timing identifier; A first storage module, configured to store the message data and generate a corresponding message identifier; wherein, the message identifier is used to indicate the storage location of the message data; A generation module, configured to generate key-value pair index data based on the plurality of information identifiers, the timing identifier, and the message identifier; and A second storage module, configured to store the key-value pair index data into corresponding target memory slices based on a target information identifier among the plurality of information identifiers.
[0013] Another aspect of the embodiments of the present application provides a data reading device, where the device includes: A first acquisition module, configured to acquire a target information identifier and a target timestamp range in response to a data reading request; A second acquisition module, configured to obtain a target timing identifier range based on the target timestamp range; A determination module, configured to determine a target memory slice from multiple memory slices based on the target information identifier; A third acquisition module, configured to acquire one or more message identifiers among multiple KV values within the target timing identifier range from the target memory slice; A reading module, configured to read corresponding one or more message data from a database according to the message identifiers within the target timing identifier range.
[0014] Another aspect of the embodiments of the present application provides a computer device, including: At least one processor; and A memory communicatively connected to the at least one processor; Wherein: the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the method as described above.
[0015] Another aspect of the embodiments of the present application provides a computer-readable storage medium, where computer instructions are stored in the computer-readable storage medium, and when the computer instructions are executed by a processor, the method as described above is implemented.
[0016] Another aspect of the embodiments of the present application provides a computer program product, including a computer program, and when the computer program is executed by a processor, the method as described above is implemented.
[0017] The embodiments of the present application adopting the above technical solutions may include the following advantages: The time sequence identifier in the key-value pair index data provides time sequence indexing capabilities. A plurality of information identifiers jointly map to the corresponding message identifier, and the message identifier indicates the storage location of the corresponding message data, thereby improving the accuracy and efficiency of message data storage and facilitating the indexing and positioning of message data. In addition, according to the target information identifier, the key-value pair index data is stored in the corresponding target memory slice, realizing the vertical splitting of the messages to be stored containing different information identifiers both logically and physically, thereby supporting horizontal expansion and providing the ability to flexibly expand storage resources. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] The drawings exemplarily show embodiments and form part of the specification, and are used together with the written description of the specification to explain the exemplary embodiments. The shown embodiments are for illustrative purposes only and do not limit the scope of the claims. In all the drawings, the same reference numerals refer to similar but not necessarily identical elements.
[0019] Figure 1 Schematically shows an operating environment diagram of the data writing method according to Embodiment 1 of the present application; Figure 2 Schematically shows a flowchart of the data writing method according to Embodiment 1 of the present application; Figure 3 Schematically shows according to this according Figure 2 Sub-step flowchart of step S204; Figure 4 Schematically shows according to this according Figure 3 Sub-step flowchart of step S300; Figure 5 Schematically shows an information identifier writing schematic diagram of the data writing method according to Embodiment 1 of the present application; Figure 6 Schematically shows an information identifier writing schematic diagram of the data writing method according to Embodiment 1 of the present application; Figure 7 Schematically shows a storage logic schematic diagram of the memory slice of the data writing method according to Embodiment 1 of the present application; Figure 8 Schematically shows a key-value pair index data storage schematic diagram of the data writing method according to Embodiment 1 of the present application; Figure 9 Schematically shows a flowchart of the data reading method according to Embodiment 2 of the present application; Figure 10 Schematically shows a reading schematic diagram of the data reading method according to Embodiment 2 of the present application; Figure 11Schematically shows an additional flowchart of the data reading method according to the second embodiment of the present application; Figure 12 Schematically shows a block diagram of the data writing device according to the third embodiment of the present application; Figure 13 Schematically shows a block diagram of the data reading device according to the fourth embodiment of the present application; and Figure 14 Schematically shows a schematic diagram of the hardware architecture of the computer device according to the fifth embodiment of the present application. Detailed implementation manners
[0020] In order to make the objectives, technical solutions and advantages of the present application clearer and more understandable, the present application will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application. All other embodiments obtained by those of ordinary skill in the art based on the embodiments in the present application without creative efforts belong to the scope of protection of the present application.
[0021] It should be noted that the descriptions involving "first", "second", etc. in the embodiments of the present application are only for descriptive purposes and cannot be understood as indicating or implying their relative importance or implicitly indicating the quantity of the indicated technical features. Thus, the features defined with "first" and "second" may explicitly or implicitly include at least one of such features. In addition, the technical solutions between the various embodiments may be combined with each other, but it must be based on the fact that those of ordinary skill in the art can implement them. When the combination of the technical solutions results in contradictions or cannot be implemented, it should be considered that such a combination of technical solutions does not exist and is not within the scope of protection required by the present application.
[0022] In the description of the present application, it should be understood that the numerical labels before the steps do not identify the order of execution of the steps, but are only used to facilitate the description of the present application and distinguish each step, and thus cannot be understood as a limitation to the present application.
[0023] First, provide the following explanations of the terms involved in the present application: Key-Value Pair (abbreviated as KV): A structural form used to store and organize data, consisting of a key and a value.
[0024] Key value: A unique identifier used to mark and access a certain data item stored.
[0025] Value value: The specific content or data corresponding to the key.
[0026] Secondly, to facilitate those skilled in the art to understand the technical solutions provided by the embodiments of the present application, the related technologies are described below: The applicant has learned that: driven by modern Internet technologies, with the continuous growth of the number of users, how to efficiently manage and process the consultations and problems of a large number of users has become one of the major challenges faced by major Internet companies. As an important bridge connecting users and enterprises, the data access method of the customer service system directly affects the user experience and corporate reputation. In addition, with the development of the enterprise and the adjustment of the organizational structure, the data access method in the customer service system also needs to be continuously optimized and adjusted to better meet the new business needs and organizational changes.
[0027] For this reason, the embodiments of the present application provide a data writing technical solution and a data reading technical solution. In this technical solution, (1) the scalability of the system is improved, that is, it can quickly expand resources to cope with sudden user traffic; (2) the accuracy and efficiency of message storage are improved, facilitating message retrieval and positioning; (3) it adapts to the needs of organizational evolution and can better meet new business needs. See the following for details.
[0028] Finally, for the convenience of understanding, an exemplary operating environment is provided below.
[0029] As Figure 1 shown, the environmental schematic diagram includes a service platform 2, a network 4, and a client 6, where: The service platform 2 can be composed of a single or multiple computing devices. The multiple computing devices can include virtualized computing instances. The virtualized computing instances can include virtual machines, such as emulations of computer systems, operating systems, servers, etc. The computing devices can load virtual machines based on virtual images and / or other data that define specific software (e.g., operating systems, dedicated applications, servers) for emulation. As the demand for different types of processing services changes, different virtual machines can be loaded and / or terminated on one or more computing devices. A hypervisor can be implemented to manage the use of different virtual machines on the same computing device.
[0030] The service platform 2 can be configured to communicate with the client 6, etc. through the network 4. The network 4 includes various network devices, such as routers, switches, multiplexers, hubs, modems, bridges, repeaters, firewalls, proxy devices, and / or the like. The network 4 can include physical links, such as coaxial cable links, twisted pair cable links, fiber optic links, and combinations thereof, or wireless links, such as cellular links, satellite links, Wi-Fi links, etc.
[0031] The service platform 2 can provide services such as storage, reading, writing, querying, deleting, etc., such as providing a message data query service for the client.
[0032] The client 6 can be an electronic device running an operating system such as Windows, Android™, or iOS, such as a smart phone, a tablet device, a laptop computer, a virtual reality device, a gaming device, a set-top box, a vehicle-mounted terminal, or a smart TV. Based on the above operating systems, various applications can be run, such as a video platform.
[0033] The client 6 can be configured with a message data query page for querying message data and the like.
[0034] It should be noted that the above devices are exemplary, and in different scenarios or according to different requirements, the number and types of devices can be adjusted.
[0035] Next, taking the service platform 2 as the execution entity, the technical solutions of the present application will be introduced through multiple embodiments. It should be noted that these embodiments can be implemented in various different forms and should not be construed as being limited only to the embodiments described herein.
[0036] Embodiment 1 Figure 2 A flowchart of a data writing method according to Embodiment 1 of the present application is schematically shown.
[0037] As Figure 2 shown, the data writing method may include steps S200 to S206, where: Step S200, in response to a data storage request, obtain data to be stored; wherein, the data to be stored includes message data, a plurality of information identifiers, and a timing identifier.
[0038] Step S202, store the message data to generate a corresponding message identifier; wherein the message identifier is used to indicate the storage location of the message data.
[0039] Step S204, based on the plurality of information identifiers, the timing identifier, and the message identifier, generate key-value pair index data.
[0040] Step S206, based on the target information identifier in the information identifiers, store the key-value pair index data into a corresponding target memory slice.
[0041] The data writing method provided in this embodiment. The timing identifier in the key-value pair index data provides timing indexing ability. A number of information identifiers jointly map to a corresponding message identifier, and the message identifier indicates the storage location of the corresponding message data, thereby improving the accuracy and efficiency of message data storage and facilitating the indexing and positioning of message data. In addition, according to the target information identifier, the key-value pair index data is stored in the corresponding target memory slice, realizing the vertical splitting of the messages to be stored containing different information identifiers both logically and physically, thus supporting horizontal expansion and providing the ability to flexibly expand storage resources.
[0042] The following combines Figure 2 , and elaborates in detail each step in steps S200 to S206 and other optional steps.
[0043] Step S200 , in response to a data storage request, obtain the data to be stored; wherein, the data to be stored includes message data, a number of information identifiers, and a timing identifier.
[0044] The message data may include message contents such as consultation contents and problem feedback between users and merchants. The number of information identifiers are identifiers for the message data, and the number of information identifiers may be merchant department organization identifiers, merchant identifiers, user identifiers, etc. The timing identifier may be an identifier that increases along the time dimension and is globally unique. A strictly increasing timing identifier can be generated through the principle of a number generator. The principle of a number generator (i.e., the principle of a sequence number generator) is used to generate unique and increasing sequence numbers, ensuring that each generated sequence number is unique and arranged in a strictly increasing order.
[0045] Step S202 , store the message data and generate a corresponding message identifier; wherein, the message identifier is used to indicate the storage location of the message data.
[0046] The message data can be stored in a database, and the corresponding message identifier can point to the exact location of the message data in the message database. The message identifier can be used as an index for the message data to quickly locate and retrieve the corresponding message data.
[0047] Step S204 , based on the number of information identifiers, the timing identifier, and the message identifier, generate key-value pair index data.
[0048] The information identifier can be data used to describe message-related attributes, such as user ID, merchant ID, department organization ID, etc. The time series identifier can be used to identify the timestamp corresponding to the message data. Through the time series identifier, the order of the message data can be ensured, and retrieval and sorting by time range are supported. In the process of generating the key-value pair index data, the information identifier and the time series identifier can be combined into a key according to specific byte order rules, and the message identifier is used as the value, pointing to the specific location of the message data in the storage system.
[0049] The following will exemplarily introduce the specific process of generating the key-value pair index data.
[0050] In an optional embodiment, the key-value pair index data includes a Key value and a Value value; as Figure 3 shown, step S204 includes: Step S300, generating the Key value based on the plurality of information identifiers and the time series identifier; wherein, each of the plurality of information identifiers and the time series identifier are respectively distributed in different fields of the Key value; Step S302, generating the Value value based on the message identifier.
[0051] The Key value is a data field that can contain multiple fields, and each field stores an information identifier or a time series identifier respectively. For example, field 1: merchant department organization identifier, field 2: merchant identifier, field 3: user identifier, field 4: time series identifier. Each identifier can occupy a fixed byte length, making the Key value format standardized for easy parsing and processing of the Key value. The Value value can store the message identifier, which can be the address directly storing the corresponding message data. In some embodiments, the lengths of the respective fields can also be different. In some embodiments, the message content 1 of merchant 1 and user 1 is stored, and merchant 1 belongs to merchant department organization 1. The message identifier 1 can be stored through the Value value, and the message identifier 1 indicates the location where the message content 1 is stored. The merchant department organization identifier 1, merchant identifier 1, and user identifier 1 can be stored through the Key value. Based on the unique mapping relationship between the Key value and the Value value, through the identifier combination in the Key value: merchant department organization identifier 1, merchant identifier 1, and user identifier 1, the Value value storing the message identifier 1 can be located, and then through the message identifier 1 of the Value value, the actual message content 1 can be further accurately located.
[0052] In this embodiment, the information identifier related to the message data is stored through the Key value, and the message identifier pointing to the specific message data is stored through the Value value. In this way, through the unique mapping relationship of the Key-Value pair in the key-value pair index data, accurate positioning and fast retrieval of the message data can be achieved.
[0053] The specific process of generating the Key value will be exemplarily introduced below.
[0054] In an optional embodiment, as Figure 4 shown, step S300 includes: Step S400, performing endian encoding on the plurality of information identifiers and the timing identifier respectively to obtain a plurality of byte sequences; wherein, the plurality of byte sequences include: a plurality of byte sequences corresponding one-to-one to the plurality of information identifiers, and a byte sequence corresponding to the timing identifier.
[0055] Step S402, writing the plurality of byte sequences into an empty key in a preset order to obtain the Key value.
[0056] Endian encoding is to convert data (such as information identifiers and timing identifiers) into byte forms that can be processed by a computer. The plurality of byte sequences are written into an empty key in a certain order. In some embodiments, as Figure 5 , 6 shown, the plurality of information identifiers include a merchant department organization id and a merchant id. The merchant department organization id is endian encoded (such as binary conversion) to obtain a corresponding endian encoding, and then the endian encoding is written into the first field of the Key value. The merchant id is endian encoded to obtain a corresponding endian encoding, and then the endian encoding is written into the second field of the Key value.
[0057] In this embodiment, by endian encoding and combining a plurality of information identifiers and a timing identifier into a Key value, the Value value storing the corresponding message identifier can be accurately located, and then the corresponding message data can be found through the message identifier, thereby realizing efficient indexing and positioning of message data.
[0058] Regarding the Key value, in an optional embodiment, the method further includes: During the process of generating the Key value, reserving fields for the Key value according to a preset rule; wherein, the reserved fields are used to provide data expansion space for the Key value.
[0059] In addition to containing basic identification fields (such as user ID, merchant ID, time series ID, etc.), the Key value can also be configured with reserved fields according to requirements. The preset rules can be field division, field length limit, etc. For example, blank fields can be divided into multiple reserved fields to meet the needs of multiple new information identifications. Blank fields are the fields in the Key value that are not currently used, and through blank fields, flexibility can be provided for future business expansion or the emergence of specific requirements. Another example is that according to the length of the current identification field, the length of each reserved field can be limited so that all reserved fields are consistent with the length of the current identification field, facilitating the reading of each field. In practical applications, the lengths of each field in the Key value can be flexibly adjusted according to requirements, and new information identifications or other data can also be flexibly filled in the reserved fields. In some embodiments, the new information identifications can be message type ID, channel ID, priority ID, etc. The message type ID can be used to identify the specific type of the message, such as consultation and feedback, etc. The channel ID can be used to identify the channel of the message source, such as application, mini-program, official website, etc. The priority ID can be used to identify the priority of the message.
[0060] In this embodiment, reserved fields are configured in the Key value to adapt to changes in the organizational structure, so as to more flexibly meet the continuously developing business needs of the enterprise.
[0061] Step S206 , based on the target information identification in the information identification, store the key-value pair index data into the corresponding target memory slice.
[0062] The memory can be divided into multiple slices, and each slice is responsible for storing data of specific content. The memory slice can be determined according to the target information identification. In some embodiments, the target information identification can be the merchant department organization ID, and the key-value pair index data can be written into the corresponding memory slice according to the merchant department organization ID. When reading message data, the merchant department organization ID can be obtained by decoding the Key value of the key-value pair index data, and then the slice to be read can be locked. In some embodiments, after storing the corresponding slices according to the merchant department organization dimension, the slice can be logically split multiple times into sub-slices based on other multiple information identifications in the information identification, and the key-value pair index data can be logically split multiple times based on other multiple information identifications in the information identification, and the split data can be stored into the corresponding sub-slices, so as to achieve a balance between access efficiency and complexity through multi-layer memory slices.
[0063] Next, the storage logic of the key-value pair index data in the memory slice will be introduced exemplarily.
[0064] In an alternative embodiment, there are multiple key-value pair index data; the information identifiers among the multiple key-value pair index data are the same, but the timing identifiers among each key-value pair index data are different; step S206 includes: storing the multiple key-value pair index data in series in a chained structure according to the timing identifier of each key-value pair index data.
[0065] When the information identifiers among multiple key-value pair index data are the same, these multiple key-value pair index data can be associated. For example, these multiple key-value pair index data all point to the message data of user 1 and merchant 1. Different timing identifiers can correspond to message data at different times. The multiple key-value pair index data are stored in series in a chained structure according to the order of the timing identifiers. The chained storage method forms a logically chained structure among the data by saving the reference to the next data in each key-value pair index data. In some embodiments, as Figure 7 shown, the information identifiers of multiple key-value pair index data are all department organization 0, merchant 1, and user 1, then the multiple key-value pair index data are serially connected in order according to the timing identifier. Additionally, the information identifiers of multiple key-value pair index data are all department organization 1, merchant 2, and user 1, then the multiple key-value pair index data are serially connected in order according to the timing identifier.
[0066] In this embodiment, by storing the multiple key-value pair index data in series in a chained structure, it is convenient to retrieve according to the time range and sort the retrieved content according to the timing relationship.
[0067] To make the present application easier to understand, the following combines Figures 5 - 8 to provide an exemplary application.
[0068] S1. In response to a data storage request, obtain the data to be stored.
[0069] The data to be stored includes message data, several information identifiers, and a timing identifier (message timing id).
[0070] S2. Store the message data and generate a corresponding message identifier.
[0071] S3. Generate key-value pair index data based on the several information identifiers, the timing identifier, and the message identifier.
[0072] As Figure 8 shown, the key-value pair index data includes a Key value and a Value value, and one Key value maps (MAPs) to one Value value.
[0073] As Figure 5As shown, a number of information identifiers include the merchant department organization ID. The merchant department organization ID is byte-order encoded (such as binary transcoding) to obtain the corresponding byte-order encoding, and then this byte-order encoding is written into the first field of the Key value.
[0074] Such as Figure 6 As shown, a number of information identifiers include the merchant ID. The merchant ID is byte-order encoded (such as binary transcoding) to obtain the corresponding byte-order encoding, and then this byte-order encoding is written into the second field of the Key value. And so on, other information identifiers are sequentially written into the empty field of the Key value.
[0075] Based on the message identifier, a Value value is generated.
[0076] S4. Based on the target information identifier in the information identifier, store the key-value pair index data into the corresponding target memory shard.
[0077] Such as Figure 8 As shown, the target information identifier is the department organization ID. According to the department organization ID, the key-value pair index data is stored (written) into the corresponding target memory shard. Specifically, the merchant department organization ID can be obtained by decoding the Key value of the key-value pair index data, and then the shard to be read can be locked.
[0078] When the information identifiers among multiple key-value pair index data are the same, the multiple key-value pair index data are stored in series in a chained structure. Such as Figure 7 As shown, the information identifiers of multiple key-value pair index data are all department organization 0, merchant 1, and user 1, then these multiple key-value pair index data are serially connected in order according to the time sequence identifier. Additionally, if the information identifiers of multiple key-value pair index data are all department organization 1, merchant 2, and user 1, then these multiple key-value pair index data are serially connected in order according to the time sequence identifier.
[0079] In this exemplary application, through the data writing method of this solution, the accuracy and efficiency of message data storage can be improved, and at the same time, horizontal expansion is supported, providing the ability to flexibly expand storage resources.
[0080] Embodiment 2 For the data reading method provided in this embodiment, the technical details can refer to the above.
[0081] Figure 9 Schematically shows a flowchart of the data reading method according to Embodiment 2 of the present application.
[0082] Such as Figure 9 As shown, this data reading method may include steps S900 to S908, where: Step S900, in response to a data reading request, obtain a target information identifier and a target timestamp range.
[0083] Step S902, based on the target timestamp range, obtain a target time sequence identifier range.
[0084] Step S904, based on the target information identifier, determine a target memory slice from multiple memory slices.
[0085] Step S906, from the target memory slice, obtain one or more message identifiers among multiple KV values within the target time sequence identifier range.
[0086] Step S908, according to the message identifiers within the target time sequence identifier range, read corresponding one or more message data from the database.
[0087] The data reading request may be to query the consultation content of a user with a certain merchant within a certain time period. In some embodiments, as Figure 10 shown, the user needs to read the message data related to merchant 0 within the target timestamp range. The department organization id and merchant id related to merchant 0 can be obtained, and the corresponding target time sequence id range is determined through the target timestamp range. Lock the merchant slice (shard0) based on the department organization id, and then obtain the corresponding KV value according to the merchant id and user id to obtain multiple message identifiers among multiple KV values within the target time sequence id range, that is, message 2 to message m. Then, according to the corresponding message meta-information obtained from message 2 to message m, the message data is arranged in time sequence and returned to the requester.
[0088] In this embodiment, the target memory slice is determined according to the target information identifier, and then one or more message identifiers among multiple KV values within the target time sequence identifier range are obtained from the target memory slice. According to the message identifiers within the target time sequence identifier range, corresponding one or more message data are read from the database. In this way, the accuracy and efficiency of message data reading are improved, and the indexing and positioning of message data are facilitated.
[0089] In an alternative embodiment, the Key value in the KV value includes a time sequence identifier; as Figure 11 shown, the method further includes: Step S1100, in the case of reading multiple message data, sort the multiple message data according to the time sequence identifiers of each message data.
[0090] Step S1102, according to the sorting result, sequentially return the multiple message data to the request side.
[0091] To enable the multiple message data obtained to be presented in the chronological order of event occurrence, these message data can be sorted according to the chronological identifier. The sorting can be performed in ascending or descending order of the chronological identifier. For example, it can be arranged in ascending order according to the numerical value of the chronological identifier, that is, arranged from the earliest time to the latest time.
[0092] In this embodiment, through sorting by the chronological identifier, the returned message data is made to conform to the order of event occurrence, facilitating the viewing and understanding by the requesting party.
[0093] Embodiment III Figure 12 Schematically shows a block diagram of a data writing device according to Embodiment III of the present application. The device can be divided into one or more program modules. One or more program modules are stored in a storage medium and executed by one or more processors to complete the embodiments of the present application. The program modules referred to in the embodiments of the present application refer to a series of computer program instruction segments that can complete specific functions. The following description will specifically introduce the functions of each program module in this embodiment. As Figure 12 shown, the device 1200 may include: an acquisition module 1210, a first storage module 1220, a generation module 1230, and a second storage module 1240, where: The acquisition module 1210 is configured to acquire data to be stored in response to a data storage request; wherein, the data to be stored includes message data, a plurality of information identifiers, and a chronological identifier; The first storage module 1220 is configured to store the message data and generate a corresponding message identifier; wherein, the message identifier is used to indicate the storage location of the message data; The generation module 1230 is configured to generate key-value pair index data based on the plurality of information identifiers, the chronological identifier, and the message identifier; and The second storage module 1240 is configured to store the key-value pair index data into a corresponding target memory slice based on a target information identifier among the plurality of information identifiers.
[0094] As an optional embodiment, the key-value pair index data includes a Key value and a Value value; the generation module 1230 is further configured to: generate the Key value based on the plurality of information identifiers and the chronological identifier; wherein, each of the plurality of information identifiers and the chronological identifier is distributed in different fields of the Key value; generate the Value value based on the message identifier.
[0095] As an optional embodiment, the generation module 1230 is further configured to: Byte-order encode the several information identifiers and timing identifiers respectively to obtain a plurality of byte sequences; wherein, the plurality of byte sequences include: several byte sequences corresponding one-to-one to the several information identifiers, and a byte sequence corresponding to the timing identifier; Write the plurality of byte sequences into an empty key in a preset order to obtain the Key value.
[0096] As an optional embodiment, the generating module 1230 is further configured to: During the process of generating the Key value, configure a reserved field for the Key value according to a preset rule; Wherein, the reserved field is used to provide data expansion space for the Key value.
[0097] As an optional embodiment, there are multiple key-value pair index data; the information identifiers between the multiple key-value pair index data are the same, but the timing identifiers between each key-value pair index data are different; the second storage module 1240 is further configured to: According to the timing identifier of each key-value pair index data, store the multiple key-value pair index data in series in a chained structure.
[0098] Embodiment IV Figure 13 Schematically shows a block diagram of a data reading device according to Embodiment IV of the present application. The device can be divided into one or more program modules. One or more program modules are stored in a storage medium and executed by one or more processors to complete the embodiments of the present application. The program modules referred to in the embodiments of the present application refer to a series of computer program instruction segments that can complete specific functions. The following description will specifically introduce the functions of each program module in this embodiment. As Figure 13 shown, the device 1300 may include: a first acquisition module 1310, a second acquisition module 1320, a determination module 1330, a third acquisition module 1340, and a reading module 1350, wherein: The first acquisition module 1310 is configured to acquire a target information identifier and a target timestamp range in response to a data reading request; The second acquisition module 1320 is configured to obtain a target timing identifier range based on the target timestamp range; The determination module 1330 is configured to determine a target memory slice from multiple memory slices based on the target information identifier; The third acquisition module 1340 is configured to acquire one or more message identifiers among multiple KV values within the target timing identifier range from the target memory slice; The reading module 1350 is configured to read corresponding one or more message data from the database according to the message identifiers within the target timing identifier range.
[0099] The Key value in the KV value includes a timing identifier; the device 1300 further includes a sorting module, and the sorting module is configured to: In the case of reading multiple message data, sort the multiple message data according to the timing identifiers of the respective message data; According to the sorting result, sequentially return the multiple message data to the requesting end.
[0100] Embodiment Five Figure 14 Schematically shows a hardware architecture diagram of a computer device 10000 suitable for implementing a data writing / reading method according to Embodiment Three of the present application. In some embodiments, the computer device 10000 may be a rack server, a blade server, a tower server, or a cabinet server (including a stand-alone server or a server cluster composed of multiple servers), etc. As Figure 14 shown, the computer device 10000 includes, but is not limited to: a memory 10010, a processor 10020, and a network interface 10030 that can communicate with each other through a system bus. Among them: The memory 10010 includes at least one type of computer-readable storage medium. The readable storage medium includes flash memory, a hard disk, a multimedia card, a card-type memory (such as an SD or DX memory), a random access memory (RAM), a static random access memory (SRAM), a read-only memory (ROM), an electrically erasable programmable read-only memory (EEPROM), a programmable read-only memory (PROM), a magnetic memory, a magnetic disk, an optical disk, etc. In some embodiments, the memory 10010 may be an internal storage module of the computer device 10000, such as the hard disk or memory of the computer device 10000. In other embodiments, the memory 10010 may also be an external storage device of the computer device 10000, such as a plug-in hard disk equipped on the computer device 10000, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. Of course, the memory 10010 may also include both an internal storage module and an external storage device of the computer device 10000. In this embodiment, the memory 10010 is generally used to store the operating system and various application software installed on the computer device 10000, such as the program code of the data writing / reading method. In addition, the memory 10010 may also be used to temporarily store various data that have been output or will be output.
[0101] In some embodiments, the processor 10020 may be a Central Processing Unit (CPU), a controller, a microcontroller, a microprocessor, or other chips. The processor 10020 is generally used to control the overall operation of the computer device 10000, such as performing control and processing related to data interaction or communication with the computer device 10000. In this embodiment, the processor 10020 is used to run the program code stored in the memory 10010 or process data.
[0102] The network interface 10030 may include a wireless network interface or a wired network interface. The network interface 10030 is generally used to establish a communication link between the computer device 10000 and other computer devices. For example, the network interface 10030 is used to connect the computer device 10000 to an external terminal through a network, and establish a data transmission channel and a communication link between the computer device 10000 and the external terminal. The network can be an enterprise internal network (Intranet), the Internet, the Global System of Mobile communication (abbreviated as GSM), Wideband Code Division Multiple Access (abbreviated as WCDMA), 4G network, 5G network, Bluetooth, Wi-Fi and other wireless or wired networks.
[0103] It should be noted that Figure 14 Only the computer device with components 10010 - 10030 is shown, but it should be understood that it is not required to implement all the shown components, and more or fewer components can be alternatively implemented.
[0104] In this embodiment, the data writing / reading method stored in the memory 10010 can also be divided into one or more program modules and executed by one or more processors (such as the processor 10020) to complete the embodiments of the present application.
[0105] Embodiment Six The embodiment of the present application also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the data writing / reading method in the embodiment are implemented.
[0106] In this embodiment, the computer-readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (such as SD or DX memory, etc.), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, magnetic disk, optical disk, etc. In some embodiments, the computer-readable storage medium may be an internal storage unit of a computer device, such as the hard disk or memory of the computer device. In other embodiments, the computer-readable storage medium may also be an external storage device of the computer device, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) card, a Flash Card, etc., equipped on the computer device. Of course, the computer-readable storage medium may also include both the internal storage unit and the external storage device of the computer device. In this embodiment, the computer-readable storage medium is generally used to store the operating system installed on the computer device and various application software, such as the program code of the data writing / reading method in the embodiment. In addition, the computer-readable storage medium can also be used to temporarily store various data that have been output or will be output.
[0107] Embodiment VII The embodiment of the present application further provides a computer program product, including a computer program, which implements the method in the above embodiment when executed by a processor.
[0108] Obviously, those skilled in the art should understand that the above-mentioned modules or steps of the embodiments of the present application can be implemented by a general-purpose computer device. They can be concentrated on a single computer device or distributed on a network composed of multiple computer devices. Optionally, they can be implemented by program codes executable by the computer device. Thus, they can be stored in a storage device and executed by the computer device. And in some cases, the steps shown or described can be executed in a different order from here, or they can be separately made into individual integrated circuit modules, or multiple modules or steps among them can be made into a single integrated circuit module to implement. In this way, the embodiments of the present application are not limited to any specific combination of hardware and software.
[0109] It should be noted that the above are only the preferred embodiments of the present application, and do not limit the patent protection scope of the present application. Any equivalent structure or equivalent process transformation made by using the content of the specification and drawings of the present application, or directly or indirectly applied in other related technical fields, shall be equally included in the patent protection scope of the present application.
Claims
1. A data writing method, characterized in that: The method comprises: In response to a data storage request, obtaining data to be stored; wherein the data to be stored includes message data, a plurality of information identifiers and a timing identifier; Storing the message data and generating a corresponding message identifier; wherein the message identifier is used to indicate a storage location of the message data; Based on the plurality of information identifiers, the timing identifier and the message identifier, generating key-value pair index data; and Based on the target information identifier in the information identifier, the key-value pair index data is stored in a corresponding target memory slice.
2. The method according to claim 1, characterized in that The key-value pair index data includes a Key value and a Value value; based on the plurality of information identifiers, the timing identifier and the message identifier, generating the key-value pair index data includes: Based on the plurality of information identifiers and the timing identifier, the Key value is generated; wherein each of the plurality of information identifiers and the timing identifier is respectively distributed in different fields of the Key value; Based on the message identifier, a Value value is generated.
3. The method according to claim 2, characterized in that Generating the Key value based on the plurality of information identifiers and the timing identifier includes: Performing byte sequence encoding on the information identifiers and timing identifiers respectively to obtain a plurality of byte sequences; wherein the plurality of byte sequences include: a plurality of byte sequences corresponding one-to-one to the information identifiers, and a byte sequence corresponding to the timing identifier; The multiple byte sequences are written into the empty key in a preset order to obtain the Key value.
4. The method according to claim 2 or 3, characterized in that: The method further comprises: In the process of generating the Key value, a reserved field is configured for the Key value according to a preset rule; The reserved field is used to provide data expansion space for the Key value.
5. The method according to claim 1, 2 or 3, characterized in that: There are multiple key-value pair index data; the information identifiers of the multiple key-value pair index data are the same, but the timing identifiers of each key-value pair index data are different; Based on the target information identifier in the information identifier, storing the key-value pair index data in a corresponding target memory slice includes: According to the time sequence identifier of each key-value pair index data, a plurality of key-value pair index data are stored in series in a chain structure.
6. A data reading method, characterized in that: The method comprises: In response to a data read request, obtaining a target information identifier and a target timestamp range; Based on the target timestamp range, a target timing identification range is obtained; Based on the target information identifier, determining a target memory slice from a plurality of memory slices; Obtaining, from the target memory slice, one or more message identifiers among a plurality of KV values within the target timing identifier range; According to the message identifiers within the target timing identifier range, one or more corresponding message data are read from the database.
7. The method according to claim 6, characterized in that The Key value in the KV value includes a timing identifier; the method further includes: In the case where multiple message data are read, the multiple message data are sorted according to the timing identifiers of the respective message data; According to the sorting result, the multiple message data are returned to the requesting end in sequence.
8. A data writing device, characterized in that: The device comprises: An acquisition module, used to acquire the data to be stored in response to a data storage request; wherein the data to be stored includes message data, a plurality of information identifiers and a timing identifier; A first storage module, used to store the message data and generate a corresponding message identifier; wherein the message identifier is used to indicate a storage location of the message data; A generating module, configured to generate key-value pair index data based on the plurality of information identifiers, the timing identifier and the message identifier; and The second storage module is used to store the key-value pair index data in a corresponding target memory slice based on a target information identifier among the plurality of information identifiers.
9. A data reading device, characterized in that: The device comprises: A first acquisition module, configured to acquire a target information identifier and a target timestamp range in response to a data read request; A second acquisition module, configured to obtain a target timing identification range based on the target timestamp range; A determination module, configured to determine a target memory slice from a plurality of memory slices based on the target information identifier; A third acquisition module is used to acquire one or more message identifiers among a plurality of KV values within the target timing identifier range from the target memory slice; The reading module is used to read one or more corresponding message data from the database according to the message identifier within the target timing identifier range.
10. A computer device, characterized in that: include: at least one processor; and a memory communicatively connected to the at least one processor; wherein: The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 7.
11. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and when the computer instructions are executed by a processor, the method according to any one of claims 1 to 7 is implemented.
12. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to claims 1 to 7 are implemented.
Citation Information
Cited By
Data processing method, electronic device, storage medium and computer program product
CN121301648A