Open rajneran-quot opened 4 years ago
i think you're looking for https://redis.io/commands/zrange
i think you're looking for https://redis.io/commands/zrange
zrange gives the data in a given range but I want to get the data based on some regex that should give all the string which follow that regex with sorted score. For Example :
ZSCAN test3 0 MATCH t 1) "200" 2) 1) "lakeside-collection|Lakeside_Collection" 2) "84353" 3) "tomtom|TomTom" 4) "183" 5) "kaplan|Kaplan_Test_Prep" 6) "62493" 7) "frenchtoast|Frenchtoast" 8) "76651" 9) "hostelbookers|HostelBookers" 10) "473"
If you observe the result here the string is coming with their scores but that is not in sorted manner.
that's right, ZRANGE can give you the entire sorted set, but with no filtering. and ZSCAN doesn't do sorting. i suppose the only thing you can do is use ZRANGE inside a Lua script which will do the filtering for you. If you also want to scan it alliteratively rather than get the whole set in one go, that would also complicate things.
that's right, ZRANGE can give you the entire sorted set, but with no filtering. and ZSCAN doesn't do sorting. i suppose the only thing you can do is use ZRANGE inside a Lua script which will do the filtering for you. If you also want to scan it alliteratively rather than get the whole set in one go, that would also complicate things.
Since wanted to implement autocompletion so fetching the data each time for different regex that would be highly costly task.
@rajneran-quot so your LUA script can fetch just the first n results, and even do incremental calls to LRANGE and abort the "scan" when enough results were collected.
i'm guessing there are better way, maybe involving a module. @itamarhaber might be able to point to something.
@itamarhaber can you check and let me know is there any better way ?
Hello @rajneran7890
As @oranagra said, I'd go with a Lua script to implement this using vanilla Redis. Alternatively, you can extend Redis with the RediSearch module and use its autocomplete feature (i.e SUGADD
and SUGGET
).
@itamarhaber
MODULE LOAD redisearch.so OPT1 OPT2
(error) ERR unknown command MODULE
, with args beginning with: LOAD
, redisearch.so
, OPT1
, OPT2
,
getting this while loading the redissearch.so any idea why so ?
Redis modules were added to Redis v4 - which version are you using?
redis_version:4.0.14
redis_version:4.0.14
This doesn't make sense... unless you're using a managed Redis service where this functionality has been turned off? Although if that's the case I'm not sure how you got the .so file there in the first place.
ZADD add the data in sorted set with score and some value while fetching the data wanted the data to be sorted based on their scores. Tried with ZSCAN but didn't get desired result