Skip to content

Instantly share code, notes, and snippets.

@antirez
Last active April 18, 2022 20:37
  • Star 35 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
<?
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);
?>
@ThreadedThinking
Copy link

I am unsure how this works as I cannot find support for zrangebylex with PHP anywhere.

@milovtim
Copy link

Seems like demo script doesn't work for several years :-(

@al-ramadhan
Copy link

al-ramadhan commented Jun 16, 2016

You can use predis library and call ZSetRangeByLex

@mictadlo
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment