<? | |
require("redis.php"); | |
require("json.php"); | |
$term = $_GET['term']; | |
$r = new Redis("127.0.0.1","6379"); | |
$r->connect(); | |
$items = $r->zrangebylex("kernel","[$term","[$term\xff",Array("LIMIT","0","10")); | |
$t = Array(); | |
$id = 0; | |
foreach($items as $item) { | |
$t[] = Array("id" => $id++, "label" => $item); | |
} | |
$json = new Services_JSON(); | |
$output = $json->encode($t); | |
echo($output); | |
?> |
This comment has been minimized.
This comment has been minimized.
The demo errors:
|
This comment has been minimized.
This comment has been minimized.
I wrote something for nodejs if anyone is interested. It uses the same jquery UI autocomplete widget as http://autocomplete.redis.io/ but it executes a function as the edit: oh and btw I'm a novice so idk how good this code is, but it works. On the server it uses socket.io and the [redis](https://www.npmjs.org/package /redis) npm module. server:
client:
|
This comment has been minimized.
This comment has been minimized.
Hello, |
This comment has been minimized.
This comment has been minimized.
Warning: fsockopen() [For instance many configuration options can be modified without any kind of restart using the function.fsockopen]: unable to connect to 127.0.0.1:10001 (Connection refused) in /var/virtual/autocomplete.redis.io/httpdocs/redis.php on line 29 Fatal error: Cannot open socket to 127.0.0.1:10001, error 111. in /var/virtual/autocomplete.redis.io/httpdocs/redis.php on line 37 |
This comment has been minimized.
This comment has been minimized.
I am unsure how this works as I cannot find support for zrangebylex with PHP anywhere. |
This comment has been minimized.
This comment has been minimized.
Seems like demo script doesn't work for several years :-( |
This comment has been minimized.
This comment has been minimized.
You can use predis library and call ZSetRangeByLex |
This comment has been minimized.
This comment has been minimized.
By any chance has anyone an example project on how to store the data, index it and the UI for autocomplete? Thank you in advance. Michal |
This comment has been minimized.
It is preferred to use the native functions json_encode and json_decode of PHP instead of the class Services_JSON.
Also the code below is for PHP >= 5.4