Reputation:
I'm planning to use Redis as the main the db and hold a large set of keys (~20^12 keys+values).
These keys will be something like the following (for the posts):
+-------------+
+-- title ----+
+-------------+
+---- id -----+ <- Increment id
+-------------+
+-- author ---+
+-------------+
+-- content --+
+-------------+
+--- date ----+
+-------------+
+--- votes ---+
+-------------+
+--- views ---+
+-------------+
+--- locked --+ <- Boolean value
+-------------+
It looks like HMSET is the best bet but it is O(N) whereas HSET O(1).
Is there a HMSET like operation but with a time complexity of O(1)? I'm mostly worried about the network trips overhead and the time to retrieve a certain key if that happens to be in the middle of the fields.
What's your way to tackle with such a large dataset otherwise?
Upvotes: 0
Views: 1082
Reputation: 7223
I quote Redis documentation on HMGET:
Time complexity: O(N) where N is the number of fields being set.
So N is just the number of fields of your item. If you get just one field from your item, it is indeed O(1) (just like HGET). Of course, you need to know the name of the field you are looking for.
It is just a multiple HSET / HGET in one call.
Upvotes: 3