Reputation: 1965
I'm at the beginning of a project and I've been asked by my manager to have a look at Redis as we already have a cluster.
Basically the project is quite small, 2 pages with the same aim: displaying a list of projects or video. Whatever in a way it's image with description, the other is videos + description.
And I just start to work on the DB, thus I have the last Redis version, with python (Flask / Tornado) and here is my concern: From what I understood with Redis, you can only have a KEY VALUE schema.
For project in Projects, you can have a list like: LPUSH listkey keyvalue
My short term question: Once a project has been added to the projects list, if I want to change only the title, do I have to update the whole value?
My mid term question: If there is an ordering option on my showroom, let's say the 25th element becomes the 2nd, is it hard to do the modification in the list? Does it work with a List?? how am I suppose to find the key position after that?
The more I look into it the less I find it appropriate for what I have to do. And I wish to be wrong because Redis is so fast and 'easy'!
Upvotes: 0
Views: 33
Reputation: 49942
One way to go about this is to store each project/video in a Hash key whose name is that element's id (e.g. video:123
). Note that you can update individual fields of the Hash (e.g. the description).
To keep track of the elements, use a Sorted Set in which the members are element ids (key names) and their scores reflect the order of display. This will let you both to easily control the display's contents and order, as well as page through the set.
Note: Lists are a bad choice of data structure for this task as their members are immutable and searching them has O(N) time complexity.
Upvotes: 1