Piekarski D
Piekarski D

Reputation: 377

Deeply nested data structures in redis

For example i have array of objects

  messages = [
    {
      name: user1,
      messages: [
        {
          user2: [message1, message2]
        }
      ]
    },
    {
      name: user2,
      messages: [
        {
          user1: [message1, message2]
        }
      ]
    }
  ]

What is the best way to store it in redis cache? I would want to update it each time message is sent.

Upvotes: 0

Views: 550

Answers (1)

Anuj Vishwakarma
Anuj Vishwakarma

Reputation: 842

There are multiple ways to store this information in redis.

  • Make jsonString of object and store simple key/Value pair.

    • Advantage: good practive, json parsing seems fast in this case.
  • Use HashMap to store the jsonObject in redis.

    • Advantage : No need to parse JSON object.
    • Disadvantage : Objects withing objects cannot be stored.

For use case go for the option 1.

Upvotes: 1

Related Questions