I am pretty new to NoSQL, but I always liked the idea of it. I took a look at Redis, and got a few questions about the best ways of storing and recieving multiple hashes
.
Assuming the following scenario:
Store a list of objects (redis 'Hashes') and select them by their timestamp.
To archive this in SQL
, it would require one table and two simple queries (INSERT & SELECT).
Trying to do this in Redis
, I ended up creating the following structure:
- Key
object:$id
(hash) containing theobject
- Key
index:timestamp:$id
(sorted set)score
equalstimestamp
andvalue
includesid
While I can live with the additional maintenance work of two keys instead of one table (SQL), I am curious about the process of selecting multiple objects:
ZRANGEBYSCORE index:timestamp:$id timestampStart timestampEnd
This returns an array
of all IDs which got created between timestampStart
and timestampEnd
. To get the object itself I am requesting every single one by:
GET object:$id
- Is this the right way of doing it?
- In comparison with an SQL Database: Is it still appreciably faster or might it even become slower caused by the high number of
GET
s?