/ Published in: PHP
PHP implementation of antirez\\\'s Redis autocompletion in Ruby. (http://antirez.com/post/autocomplete-with-redis.html)\\r\\nUsing Php Redis extension available here : http://github.com/owlient/phpredis
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php $redis = new Redis(); $redis->connect("db", 6379); if(!$redis->exists(":compl")) { echo "Loading entries in the Redis DB\n"; foreach($file as $line) { $redis->zAdd(":compl", 0,$prefix); } $redis->zAdd(":compl", 0, $line . "*"); } } else { echo "NOT loading entries, there is already a 'compl' key \n"; } function complete($redis, $prefix, $count) { $rangeLen = 50; $start = $redis->zRank(":compl", $prefix); if(!$start) { return $results; } $range = $redis->zRange(":compl", $start, $start+$rangeLen-1); $start += $rangeLen; break; } foreach($range as $entry) { } } } } return $results; } $results = complete($redis, "marcell", 50); foreach($results as $res) { echo $res . "\n"; }
URL: redis-autcomplete