Is this possible to have a datastructure inside another data structure? So far I can only insert a string or a number into a list.
A desired data structure would be a to have a list where each component is also a list.
Creating Lists Redis reads lists from left to right, and you can add new list elements to the head of a list (the “left” end) with the lpush command or the tail (the “right” end) with rpush . You can also use lpush or rpush to create a new list: lpush key value.
Redis lists are lists of strings, sorted by insertion order. It's possible to add elements to a Redis list by pushing items to the front and back of the list with LPUSH/RPUSH and can pop items from the front and back of the list with LPOP/RPOP.
Removes and returns the first elements of the list stored at key . By default, the command pops a single element from the beginning of the list. When provided with the optional count argument, the reply will consist of up to count elements, depending on the list's length.
Redis LPUSH command is used to insert all the specified values at the head of the list stored at key. It is created as an empty list before performing the push operations if tje key does not exist. When key holds a value that is not a list, an error is returned.
Simple answer: No, Redis list members can only be strings.
Complex answer: There is a lot you can do with strings. You can serialize a list into a string using a number of different formats (JSON, XML, CSV, language specific serialization, etc.). Redis can hold pretty large string values so you can store just identifiers which point to a key containing the real values, or you can have a serialized list of the values themselves.
Redis have a very limited set of data types which can be found here: Data types
What you can do is to store the names of element lists in a list so it will effectively act as list of lists.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With