Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

FrogMen's avatar
Level 14

Persist Redis store periodically

Hey all, I'm thinking on counting blog article hits with Redis, and want to save the result to DB eg. daily. The point is not to stress the DB on every visitor hit..

My idea is, I make a cron job, and every midnight I get all view count values of articles from Redis, and save them to DB. Finally reset the count values to 0.

Is there a better way to do that? I know that Redis can natively persist store data, but saving to DB I can build a nice chart stat, and own the data after years, even Redis doesn't play a role later

thanks

0 likes
3 replies
Jaytee's avatar

Two great options:

  1. Depending on the amount of traffic / blog views you expect, hitting the database each time will actually be okay

  2. Like @christophharms said, fire a job using the scheduler once or twice a day to update the DB is fine.

FrogMen's avatar
Level 14

Thank you for the answers, of course I use scheduler, and why not, I'll use the basic approach, eg. saving the counts to DB periodically..

Please or to participate in this conversation.