If I am doing this:
client.get("foo", (err, res) => {
console.log(res);
});
And there billions of keys stored in the Redis server, would it return the data as quick as if there stored only just couple of keys?
OR that I should use index (if there indexes in Redis), just like querying the DB in MongoDB?
Redis GET command has a O(1) complexity, meaning that it will always get the data in the same amount of time (not counting network latency and bandwith) if there are 10, 10k or a 10 million entries. This is the case where you are using Redis a simple key-value store. In-memory retrieval + unique keys allows it to do that.
If you have more complex data structures, like hashes, then you could do secondary indexing. See more here
Redis doesn't have indexes for keys. Each typical query for a key will have constant execution time, O(1)
, so it doesn't matter if you have one or billions of keys in the database.
However if you plan to search for anything other than the key, you might want to check the docs for indexing patterns
Sorted sets as indexes Lexicographically encoded indexes Geospatial indexes IP range indexes Full text search indexes Partitioned indexes
But again, these are non-key indexes.
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