简体   繁体   中英

is redisJSON better than plain redis when keeping data for boardgame session data?

Just loaded up a redis server for my backend with ioredis.

I'm learning that if i want to store data in json spec, i gotta use the redisJSON module instead. Since hashes are only string typed and they are flat. However, if im only storing one object per user instance, containing less than 10 fields that are typed string/num or array.. is it better to just use without redisJSON? On one hand, redisJSON can let me query an object on one query. On the other, i can just store multiple datatypes and query between those sets/hash with a consistent naming convention.

Does anyone know whats the better usage or pitfalls with either approach?

the backend serves a websocket for a multiplayer boardgame.

The answer is it depends and it requires several trade-offs to be made for each project

  • Performance: RedisJSON uses a tree structure for storing all elements in a document.
    • Comparing to a string: the advantage is that updating sub-elements of a document will be faster than manipulating a string containing a serialised JSON object. But retrieving (reassembling) and writing the entire document will be more expensive compared to Strings. Read more here .
    • Comparing to Hash: when manipulating a flat document (1 level deep), RedisJSON and HSET performance are comparable.
  • Maintainability: using several native data types in Redis to represent your object can be really performing, but the code will be more complex to maintain. There can be additional migration/refactoring work when the structure of the document is altered.
  • Querying: RediSearch has support for indexing and querying the content RedisJSON documents . This is, of course, if your use case requires secondary indexing and querying documents other than with their key. You can still build your own secondary indexing with Redis data structures, but this is also a trade-off in maintainability

disclaimer: I work at Redis, creator and maintainer of RediSearch and RedisJSON

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM