Today, I came across this awesome post on the Spool blog—Fast, easy, realtime metrics using Redis bitmaps. And I immediately wanted to build something in PHP. You should read the article to get the background of what I am trying to do here.
First, Java has native a Bitset library. No such luck in PHP. So, after scouring, I found that PECL has here. Follow the instructions in the README to install the Bitset library. You might have to add the extension to your php.ini file manually:
Next, use a PHP-Redis client of Predis. Here’s the rest of the code sample:
This is, of course, a test and you wouldn’t normally use this to track page views real time. But it’s just an indication of the vast array of problems you can solve with Redis.