CN111767310A - Data storage method and device - Google Patents

Data storage method and device Download PDF

Info

Publication number
CN111767310A
CN111767310A CN201910763793.5A CN201910763793A CN111767310A CN 111767310 A CN111767310 A CN 111767310A CN 201910763793 A CN201910763793 A CN 201910763793A CN 111767310 A CN111767310 A CN 111767310A
Authority
CN
China
Prior art keywords
data
annotation
redis
database
cache
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.)
Pending
Application number
CN201910763793.5A
Other languages
Chinese (zh)
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.)
Intercontinental Media Information Technology Liaoning Co ltd
Original Assignee
Intercontinental Media Information Technology Liaoning 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 Intercontinental Media Information Technology Liaoning Co ltd filed Critical Intercontinental Media Information Technology Liaoning Co ltd
Priority to CN201910763793.5A priority Critical patent/CN111767310A/en
Publication of CN111767310A publication Critical patent/CN111767310A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2455Query execution
    • G06F16/24552Database cache management
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
    • G06F16/275Synchronous replication

Landscapes

  • Engineering & Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computing Systems (AREA)
  • Computational Linguistics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention relates to a data storage method, which comprises the following steps: adding annotations for automatically storing the data in the database into a redis cache on a redis API; and adding annotations for synchronously updating the data in the database into a redis cache on the redis API. According to the data storage device, the @ Myredis annotation and the @ Update annotation are added to the redis API, data in the database with the @ Myredis annotation can be automatically stored in the redis cache only by one line of codes, the data in the database with the @ Update annotation is synchronously updated in the redis cache, a large amount of redundant codes and development cost are reduced, storage is convenient and fast, and codes interacting with the database are reduced.

Description

Data storage method and device
Technical Field
The invention relates to a data storage method and a data storage device, and belongs to the field of computers.
Background
Currently, it is a common trade channel for buyers and suppliers to trade on-line. During the course of a transaction, the server may generate a large amount of data. In the prior art, a bottom-layer cache framework of a server generally uses a Redis, which is an open-source, network-supporting, memory-based, optional-persistence key-value pair storage database written by using an ANSIC.
Currently, in the caching process of the Redis, the sequence of reading data is to read the cache database first and then read the database, and the sequence of writing data is to write the database first and then write the cache database. After the relevant data is updated every time, the cache data in the cache database is cleaned, the problem that the data is inconsistent with the cache data is avoided, or failure time is set for the cache database, and the cache data is automatically cleaned after the failure time is reached, so that the consistency of the data and the cache data is ensured.
However, when the number of times of updating the cache is large, the operation is not only cumbersome and long in time delay, but also may cause a sequence error due to carelessness or capacity problems of a developer, which may cause a problem of data inconsistency.
Disclosure of Invention
The invention provides a data storage method, which can reduce a large amount of redundant codes and development cost, is convenient and quick to store and reduces codes interacting with a database.
The application provides a data storage method, which comprises the following steps:
adding annotations for automatically storing the data in the database into a redis cache on a redis API; and adding annotations for synchronously updating the data in the database into a redis cache on the redis API.
The annotation for automatically storing the data in the database into the redis cache is an @ Myredis annotation, and the @ Myredis annotation comprises cache expiration time.
The annotation for synchronously updating the data in the database into the redis cache is an @ Update annotation, and the @ Update annotation comprises a scope parameter.
Wherein the scope parameter is an enumerated value UpdateType.
Wherein the enumeration value is updatetype.
Wherein, the enumeration value is updatetype.class, which indicates that all caches under the current class are updated.
Wherein, if the enumerated value is updatetype.
The present application further provides a data caching apparatus, including:
the first adding module is used for adding annotations for automatically storing the data in the database into the redis cache on the redis API;
and the second adding module is used for adding annotations for synchronously updating the data in the database to the redis cache on the redis API.
The annotation added by the first adding module is an @ Myredis annotation, and the @ Myredis annotation comprises cache invalidation time.
The annotation added by the second adding module is an @ Update annotation, and the @ Update annotation comprises scope parameters.
According to the method, the @ Myredis annotation and the @ Update annotation are added to the redisAPI, data in the database with the @ Myredis annotation can be automatically stored in a redis cache only by one line of codes, and the data in the database with the @ Update annotation is synchronously updated in the redis cache, so that a large amount of redundant codes and development cost are reduced, the storage is convenient and fast, codes interacted with the database are reduced, and the data in the database and the cache are consistent;
furthermore, the invalidation time of the object in the redis cache can be automatically set, so that the consistency of the data and the cache data is further ensured;
furthermore, the range of the updated data is determined according to the enumeration value in the parameter of the @ Update annotation, so that the range of the data Update is defined, the data Update time is saved, and the efficiency of the data Update is improved.
Drawings
FIG. 1 is a schematic flow chart of a data storage method according to an embodiment of the present invention;
fig. 2 is a schematic structural diagram of a data storage device according to an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions, advantages, and the like of the present invention clearer, practical examples are given and further description is given with reference to the drawings.
As shown in fig. 1, the present application provides a data storage method, including:
101. adding an annotation for automatically storing data in a database into a redis cache on a redis API (application programming interface, hereinafter referred to as API);
specifically, adding an @ Myredis annotation on a redisAPI, wherein the @ Myredis annotation is used for automatically storing data in a database into a redis cache;
the @ Myredis annotation includes cache expiration time in seconds, and if default parameters are not set, the default expiration time is 720 seconds.
102. And adding annotations for synchronously updating the data in the database into a redis cache on the redis API.
Specifically, adding an @ Update annotation on the redisAPI, wherein the @ Update annotation is used for synchronously updating data in the database into the redis cache.
The @ Update annotation includes a scope parameter, and in practical application, the scope parameter is represented by an enumerated value UpdateType, and the UpdateType is used for describing the scope of the @ Update annotation, namely, the refresh range of the cache. When the enumeration value is UpdateType.ALL, all redis caches are updated; when the enumeration value is UpdateType.CLASS, updating all redis caches under the current class; NOW, indicating that all redis caches under the execution method are updated.
It should be noted that, the step 101 and step 102 do not have a determined execution order relationship, and the @ Myredis annotation may be added first and then the @ Update annotation is added on the basis of the redisa api, or the @ Update annotation may be added first and then the @ Myredis annotation is added, which is not limited in this embodiment of the present invention.
According to the data storage method, the @ Myredis annotation and the @ Update annotation are added to the redisAPI, data in the database with the @ Myredis annotation can be automatically stored in the redis cache only by one line of codes, and the data in the database with the @ Update annotation is synchronously updated in the redis cache, so that a large amount of redundant codes and development cost are reduced, the storage is convenient and rapid, codes interacting with the database are reduced, and the data in the database and the cache are consistent; furthermore, the invalidation time of the object in the redis cache can be automatically set, so that the consistency of the data and the cache data is further ensured; furthermore, the range of the updated data is determined according to the enumeration value in the parameter of the @ Update annotation, so that the range of the data Update is defined, the data Update time is saved, and the efficiency of the data Update is improved.
As shown in fig. 2, the present application provides a data caching apparatus, which includes a first adding module 201 and a second adding module 202;
the first adding module 201 is configured to add, on the redis api, an annotation for automatically storing data in the database to the redis cache;
specifically, the first adding module 201 adds @ Myredis annotation on the redisAPI, where the @ Myredis annotation is used for automatically storing data in the database into a redis cache;
the @ Myredis annotation includes cache expiration time in seconds, and if default parameters are not set, the default expiration time is 720 seconds.
A second adding module 202, configured to add, on the redis api, an annotation for synchronously updating data in the database into the redis cache.
Specifically, the second adding module 202 adds an @ Update annotation on the redisAPI, where the @ Update annotation is used for implementing synchronous Update of data in the database to the redis cache.
According to the data storage device, the @ Myredis annotation and the @ Update annotation are added to the redisAPI, data in the database with the @ Myredis annotation can be automatically stored in the redis cache only by one line of codes, and the data in the database with the @ Update annotation is synchronously updated in the redis cache, so that a large amount of redundant codes and development cost are reduced, the storage is convenient and rapid, codes interacting with the database are reduced, and the data in the database and the cache are consistent; furthermore, the invalidation time of the object in the redis cache can be automatically set, so that the consistency of the data and the cache data is further ensured; furthermore, the range of the updated data is determined according to the enumeration value in the parameter of the @ Update annotation, so that the range of the data Update is defined, the data Update time is saved, and the efficiency of the data Update is improved.
Although the present application has been described with reference to a few embodiments, it should be understood that various changes, substitutions and alterations can be made herein without departing from the spirit and scope of the application as defined by the appended claims.

Claims (10)

1. A method of storing data, comprising:
adding annotations for automatically storing the data in the database into a redis cache on a redis API; and adding annotations for synchronously updating the data in the database into a redis cache on the redis API.
2. The method according to claim 1, wherein the annotation for automatically storing the data in the database into the redis annotation @ Myredis annotation, and the @ Myredis annotation comprises cache expiration time.
3. The method according to claim 1, wherein the annotation for synchronously updating the data in the database into the redis cache is an @ Update annotation, and the @ Update annotation comprises a scope parameter.
4. The method of claim 3, wherein the scope parameter is an enumerated value UpdateType.
5. The method of claim 4, wherein the enumerated value is UpdateType.ALL, indicating that all caches are updated.
6. The method of claim 4, wherein the enumerated value is UpdateType.CLASS, which indicates that all buffers in the current class are updated.
7. The method of claim 4, wherein if the enumerated value is UpdateType.NOW, all buffers under the execution method are updated.
8. A data caching apparatus, comprising:
the first adding module is used for adding annotations for automatically storing the data in the database into the redis cache on the redis API;
and the second adding module is used for adding annotations for synchronously updating the data in the database to the redis cache on the redis API.
9. The apparatus according to claim 8, wherein the annotation added by the first adding module is an @ Myredis annotation, which includes a cache expiration time.
10. The apparatus of claim 8, wherein the annotation added by the second adding module is an @ Update annotation, and wherein the @ Update annotation includes a scope parameter therein.
CN201910763793.5A 2019-08-19 2019-08-19 Data storage method and device Pending CN111767310A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910763793.5A CN111767310A (en) 2019-08-19 2019-08-19 Data storage method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910763793.5A CN111767310A (en) 2019-08-19 2019-08-19 Data storage method and device

Publications (1)

Publication Number Publication Date
CN111767310A true CN111767310A (en) 2020-10-13

Family

ID=72718885

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910763793.5A Pending CN111767310A (en) 2019-08-19 2019-08-19 Data storage method and device

Country Status (1)

Country Link
CN (1) CN111767310A (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20030200194A1 (en) * 2002-04-18 2003-10-23 International Business Machines Corporation Computer apparatus and method for caching results of a database query
CN105677251A (en) * 2016-01-05 2016-06-15 上海瀚之友信息技术服务有限公司 Storage system based on Redis cluster
CN106933644A (en) * 2015-12-31 2017-07-07 北京国双科技有限公司 Data processing method and device
CN108628891A (en) * 2017-03-21 2018-10-09 北京京东尚科信息技术有限公司 Realize method, apparatus, electronic equipment and the readable storage medium storing program for executing of data buffer storage layer
CN109670053A (en) * 2018-12-25 2019-04-23 北京锐安科技有限公司 Data object mapping method, device, equipment and computer readable storage medium

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20030200194A1 (en) * 2002-04-18 2003-10-23 International Business Machines Corporation Computer apparatus and method for caching results of a database query
CN106933644A (en) * 2015-12-31 2017-07-07 北京国双科技有限公司 Data processing method and device
CN105677251A (en) * 2016-01-05 2016-06-15 上海瀚之友信息技术服务有限公司 Storage system based on Redis cluster
CN108628891A (en) * 2017-03-21 2018-10-09 北京京东尚科信息技术有限公司 Realize method, apparatus, electronic equipment and the readable storage medium storing program for executing of data buffer storage layer
CN109670053A (en) * 2018-12-25 2019-04-23 北京锐安科技有限公司 Data object mapping method, device, equipment and computer readable storage medium

Non-Patent Citations (4)

* Cited by examiner, † Cited by third party
Title
DANNY_SHU: "Spring Boot Cache + redis 设置有效时间和自动刷新缓存,时间支持在配置文件中配置", pages 1 - 3, Retrieved from the Internet <URL:https://blog.csdn.net/shuxing520/article/details/78787545> *
JUDYW: "自定义注解的使用", pages 1 - 16, Retrieved from the Internet <URL:https://www.imooc.com/article/275447> *
天涯泪小武: "1 Springboot中使用redis,自动缓存、更新、删除", pages 1 - 6, Retrieved from the Internet <URL:https://cloud.tencent.com/developer/article/1383997> *
码农教程: "Java自定义注解实现Redis自动缓存的方法", pages 1 - 7, Retrieved from the Internet <URL:http://www.manongjc.com/article/131819.html> *

Similar Documents

Publication Publication Date Title
US10664362B2 (en) Recovery processing for database in persistent system
RU2554847C2 (en) Reference points for file system
CN109471851B (en) Data processing method, device, server and storage medium
CN110058962B (en) Method, apparatus and computer program product for determining consistency level of virtual machine snapshots
CN113094362A (en) Method and device for reliably delivering and processing asynchronous message
US9430415B2 (en) Concurrent dumping of large address space
US9588884B2 (en) Systems and methods for in-place reorganization of device storage
CN110019063A (en) Method, terminal device and the storage medium of calculate node data disaster tolerance playback
US20110289289A1 (en) Backup and restore of items using bounded checkpoint and log buffers in memory
US20150169668A1 (en) Single Pass File System Repair With Copy On Write
US10430115B2 (en) System and method for optimizing multiple packaging operations in a storage system
KR20180099680A (en) Playback of partially executed instruction blocks in a processor-based system using the block-atom execution model
CN113448977A (en) Distributed cache updating method and device based on database Binlog
CN116627331B (en) Cache verification device, method and system
CN110928890A (en) Data storage method and device, electronic equipment and computer readable medium
CN111767310A (en) Data storage method and device
US9542120B2 (en) Systems and methods for processing instructions while repairing and providing access to a copied volume of data
US11803317B2 (en) Interrupted replicated write recognition
CN114237715A (en) Multi-core memory access instruction verification system and method
CN114896276A (en) Data storage method and device, electronic equipment and distributed storage system
CN113608925A (en) Data backup method and system based on continuous data protection CDP protocol
US20150161006A1 (en) Information processing apparatus and method for testing same
CN108733704B (en) Multi-database data processing method and device, storage medium and electronic equipment
US10810662B1 (en) Utilizing time-series tables for tracking accumulating values
CN110597862A (en) Data entry method, equipment and system based on information system

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination