Created
July 5, 2010 04:17
-
-
Save alfredwesterveld/463987 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Predis.php | |
Predis_Compatibility.php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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