Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Want the data in sorted manner based on their scores from sorted set. #7477

Open
rajneran-quot opened this issue Jul 7, 2020 · 11 comments
Open

Comments

@rajneran-quot
Copy link

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

@oranagra
Copy link
Member

oranagra commented Jul 7, 2020

i think you're looking for https://redis.io/commands/zrange

@rajneran-quot
Copy link
Author

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"
    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"
  2. "473"

If you observe the result here the string is coming with their scores but that is not in sorted manner.

@oranagra
Copy link
Member

oranagra commented Jul 7, 2020

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.

@rajneran-quot
Copy link
Author

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.

@oranagra
Copy link
Member

oranagra commented Jul 7, 2020

@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.

@rajneran7890
Copy link

@itamarhaber can you check and let me know is there any better way ?

@itamarhaber
Copy link
Member

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).

@rajneran-quot
Copy link
Author

rajneran-quot commented Jul 9, 2020

@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 ?

@itamarhaber
Copy link
Member

Redis modules were added to Redis v4 - which version are you using?

@rajneran-quot
Copy link
Author

redis_version:4.0.14

@itamarhaber
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants