Skip to content

Instantly share code, notes, and snippets.

@alfredwesterveld
Created July 5, 2010 04:17
Show Gist options
  • Save alfredwesterveld/463987 to your computer and use it in GitHub Desktop.
Save alfredwesterveld/463987 to your computer and use it in GitHub Desktop.
Predis.php
Predis_Compatibility.php
<?php
require 'Predis.php';
$key1 = "key1"; #should come up with a good name.
$key2 = "key2";
$millis = time() * 1000;
print "time: $millis\r\n";
$event = "Hello World $millis";
// print_r($event);
$redis = new Predis_Client();
$oldfirst = $redis->zrange($key1, 0, 0);
print "oldfirst\r\n";
print_r($oldfirst);
$redis->zadd($key1, $millis, $event);
#Get event which has to be scheduled first
$first = $redis->zrange($key1, 0, 0);
print "first\r\n";
print_r($first);
if ($first[0] != null && $oldfirst == null || $oldfirst <> $first) {
#got different first event => notify wakeup.php.   
print "diff\r\n";
$redis->lpush($key2, $first[0]);
} else {
print "same\r\n";
}
<?php
require 'Predis.php';
$redis = new Predis_Client();
$key1 = "key1";
$key2 = "key2";
$timeout = 5;
while(true) {
$first = $redis->blpop($key2, $timeout);
print_r($first);
print "\r\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment