sorting - Caching sortable/filterable data in Redis -


i have variety of data i've got cached in standard redis hashmap, , i've run situation need respond client requests ordering , filtering. order rankings name, average rating, , number of reviews can change regularly (multiple times minute, possibly). can advise me on proper strategy attacking problem? consider following example understand i'm looking for:

  1. client makes api request /api/v1/cookbooks?orderby=name&limit=20&offset=0
  2. i should respond first 20 entries, ordered name

strategies i've considered far:

  • for each type of hashmap store (cookbooks, recipes, etc), creating sorted set each ordering scheme (alphabetical, average rating, etc) postgres order by; pulling out zrange slices based on limit , offset
  • storing ordering data directly json string data each key.
  • hitting postgres select id table order _, , using ids pull directly hashmap store

any additional thoughts or advice on how best address issue? in advance.

so, mentioned in comment below sorted sets great way implement sorting , filtering functionality in cache. take following example idea of how 1 might solve issue of needing order objects in hash:

  1. given hash called "movies" scheme of bucket:objectid -> object, json string representation (read "bucketing" hashes performance here.

  2. create sorted set called "movieratings", each member objectid "movies" hash, , score average of rating values (computed database). use numerical representation of whatever you're trying sort, , redis gives lot of flexibility on how can extract slices need.

  3. this simple scheme has lot of flexibility in can achieved - ask sorted set set of keys fit requirements, , keys hmget "movies" hash. 2 swift redis calls, problem solved.

  4. rinse , repeat whatever type of ordering need, such "number of reviews", "alphabetically", "actor count", etc. filtering can done in manner, normal sets quite sufficient purpose.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -