How can i write nested Map data in redis?

I want to write and then read nested map data in redis using the following function

Redix.command(:redix, insert_data)

help me out to figure out how should i write my insert_data

Example of sample data is below

data = %{
  student1 => %{
    name: "name1",
    age: 22
  },
  student1 => %{
    name: "name2",
    age: 21
  }
}

Are the library docs not good enough?

Understanding your datastores is arguably as much, or even more important than, understanding your application programming language.

At its very basic, Redis is an in-memory key/value datastore, where the keys are binary data and the values are also binary data.

Redis can do more than that though. It has the idea of maps (hashes in its terms). But again, each hash key is a binary, and each value is also a binary.

So in your case, the keys could be “student1” and “student2”, but the values would have to be serialized JSON or something similar (i.e. binary data).

There are Redis plugins for storing JSON in such a way that nested fields are queryable, but that’s a topic for another day… :slight_smile:

2 Likes