Redis Strategy for Collections Management -
we have situation have object, "affiliate" cache in redis. when calls getaffiliatebyid, first check redis, if available, gets served, else call db made, entry added redis , served. changes affiliate invalidate cache entry. works charm.
now imagine call 'listaffiliates' allows 1 skip/take records , in addition has parameters 'include archived' or 'include disabled' affiliates. in addition this, may want include "search term" in call list affiliates matching criteria provided.
what best strategy use redis this? here options have evaluated @ our end:
- build key like: affiliates:skip:{skip}:take:{take}:searchterm:{term}:includearchived:{includearchived}:includedisabled:{includedisabled} , store entire result set key. when makes query using same search criteria again, serve redis.
to invalidate, each time "any" affiliate updated, wipe out keys. challenge have wipe out keys start 'affiliates:skip'. know, script call because redis sdks in general don't allow deleting items keys begin phrase. other issue multiple searches keep same data on , on again.
keep affiliates in sorted set, them in memory, apply filter/sort , return subset. downside risk caching way data in redis (which may/may not problem)
another alternative query database based on criteria, obtain ids , store them in redis criteria. may not need store them in redis, imply call db such scenarios.
based on ids obtained, multiple redis entries.
if entries specific ids not found, db , add them in redis , serve them up.
now when affiliate updated, can invalidate individual entry redis.
if new affiliates added, or archived/restored or disabled/enabled, still need clear out search pattern entries redis (if had cached them).
are there better ways of dealing this? love hear thoughts.
thank you!
Comments
Post a Comment