Answer the question
In order to leave comments, you need to log in
What is better to use to store unique ip addresses per day?
I would like to get advice on what is the most relevant method of storing and retrieving unique data per day.
A little about the load and data:
IP addresses come to the php script via udp every minute about 2 thousand times (80 percent are all repetitions), it is necessary to record only unique values for today in the database in the future. That is, there are 3 fields id (autogenerated), ip, datatime. the script is launched and a constant exchange of packets begins.
As I see it, it is necessary to install either redis or memcache and enter all absolutely addresses into the RAM cache, after which, for example, every 5-10 minutes, enter only unique ip, datatime entries for today.
Answer the question
In order to leave comments, you need to log in
Redis is quite up to the task.
For example, for each ip, generate a key of the form дата:ip
. For example SET "20210205:192.168.1.5" ""
, for each ip, create a key with an empty string.
After midnight, IPs will be saved with a new date, and the PHP cron script will parse the previous day KEYS "20210205:*"
and save the collected IPs to the database.
It is even better to keep every day as a hash, where the name is the date, the ip fields, and the hit counter values from this ip. Do it every time HINCRBY "дата" "ip" 1
See HINCRBY
PS ip, if there is only IPv4, it's 4 bytes, can be stored as integers, not strings - more compact.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question