Answer the question
In order to leave comments, you need to log in
How to make a task queue for inserting data into a database?
Hello everyone, can you explain how to create a task queue for inserting data into a database? Preferably with simple examples.
Are there any differences between working with Mysql and Redis databases?
Thanks in advance!
Answer the question
In order to leave comments, you need to log in
Do you mean queue? But what if you need to access data that has not yet been inserted? Well, there are transactions, for most cases.
For the task queue, I recommend RabbitMQ, there are enough examples.
Comparing Mysql and Redis does not seem reasonable, they work in completely different ways.
Redis: LPUSH + BRPOP
fiznool.com/blog/2016/02/24/building-a-simple-mess...
For lazy insertion into mySql, the write data (attributes) by the webserver process is placed in the Redis queue:
LPUSH queue1 '{ "name":"Kolya","age":25}'
Another process periodically checks the length of the queue, and if it is non-zero, it takes the
BRPOP queue1 element from the queue
and, extracting data from JSON, composes a query for insertion into mySql:
INSERT INTO tbl_name ( name, age) VALUES('Kolya', 25)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question