Since your question remains a little vague as to how you want to request your data, it remains unclear how to resolve your question. With that in mind, however, here are my thoughts on how I can model your data:
Updated answer detailing how to use SORTED SET
I edited this answer to be able to store your values so that you can query for dynamic date ranges. This edit assumes that your database values are timestamps, as in the value for one time, and not 2, as in your current setting.
Yes, you are correct that using Sorted Sets can accomplish this. I suggest you always use the Unix timestamp value for the rating component in these sorted sets.
If you are new to redis, explain the limitations of indexing. Redis is a simple key value designed to quickly get values with a key. Because of this design, it does not contain many of the features of your traditional DBMS, such as column indexing.
In redis, you index using a key, and the most nested key structures are available in HASH and SORTED SET, but you only get two key structures. In HASH, you have a key (the same as any data type), and an internal hash key that can take the form of any string.
In a SORTED INSTALL, you have a key (the same as any data type) and a numerical value.
A HASH is nice to use to store organized grouped data.
A SORTED KIT is good if you want to request a range of values. This may work well for your data.
Your SORTED SET will look like this:
key 00888:XA => score (date value) value 1452427200 (2016-01-10) xxxxxxxx 1452859200 (2016-01-10) yyyyxxxx 1453291200 (2016-01-10) zzzzxxxx
Let's use a more intuitive example, a 2017 Juventus list:
To create the SORTED KIT in the table below, run this command on your redis client:
ZADD JUVENTUS 32 "Emil Audero" 1 "Gianluigi Buffon" 42 "Mattia Del Favero" 36 "Leonardo Loria" 25 "Neto" 15 "Andrea Barzagli" 4 "Medhi Benatia" 19 "Leonardo Bonucci" 3 "Giorgio Chiellini" 40 "Luca Coccolo" 29 "Paolo De Ceglie" 26 "Stephan Lichtsteiner" 12 "Alex Sandro" 24 "Daniele Rugani" 43 "Alessandro Semprini" 23 "Dani Alves" 22 "Kwadwo Asamoah" 7 "Juan Cuadrado" 6 "Sami Khedira" 18 "Mario Lemina" 46 "Mehdi Leris" 38 "Rolando Mandragora" 8 "Claudio Marchisio" 14 "Federico Mattiello" 45 "Simone Muratore" 20 "Marko Pjaca" 5 "Miralem Pjanic" 28 "Tomás Rincón" 27 "Stefano Sturaro" 21 "Paulo Dybala" 9 "Gonzalo Higuaín" 34 "Moise Kean" 17 "Mario Mandzukic" Jersey Name Jersey Name 32 Emil Audero 23 Dani Alves 1 Gianluigi Buffon 42 Mattia Del Favero 36 Leonardo Loria 25 Neto 15 Andrea Barzagli 4 Medhi Benatia 19 Leonardo Bonucci 3 Giorgio Chiellini 40 Luca Coccolo 29 Paolo De Ceglie 26 Stephan Lichtsteiner 12 Alex Sandro 24 Daniele Rugani 43 Alessandro Semprini 22 Kwadwo Asamoah 7 Juan Cuadrado 6 Sami Khedira 18 Mario Lemina 46 Mehdi Leris 38 Rolando Mandragora 8 Claudio Marchisio 14 Federico Mattiello 45 Simone Muratore 20 Marko Pjaca 5 Miralem Pjanic 28 Tomás Rincón 27 Stefano Sturaro 21 Paulo Dybala 9 Gonzalo Higuaín 34 Moise Kean 17 Mario Mandzukic
Request a list using a number of knitwear numbers:
ZRANGEBYSCORE JUVENTUS 1 5 Output: 1) "Gianluigi Buffon" 2) "Giorgio Chiellini" 3) "Medhi Benatia" 4) "Miralem Pjanic"
Please note that points are not refunded, however the ZRANGEBYSCORE team orders the results in ASC order for the result. To add points, add the "WITHSCORES" command to the command: ZRANGEBYSCORE JUVENTUS 1 5 WITHSCORES
Using ZRANGEBYSCORE, you can request any key (counter number + counter code) with a date range, producing values in that range.
Original: Below is my original answer recommending HASH
Based on your examples, I recommend using HASH .
With a hash, you will have a master key for finding a hash (example 00888:XA ). Then in the hash you have key pairs → values (example 2017-01-10:2017-01-20 → xxxxxxxx ). I prefer to delimit or label the components of my keys with a colon colon : but you can use any delimiter.
HASH matches your data structure very well:
key 00888:XA => hashkey value 2017-01-10:2017-01-20 xxxxxxxx 2017-01-21:2017-01-31 yyyyxxxx 2016-02-01:2016-12-31 zzzzxxxx key 00888:ZI => hashkey value 2017-01-10:2017-01-20 xxxxxxxx 2017-01-21:2017-01-31 xxxxyyyy 2016-02-01:2016-12-31 xxxxzzzz
When requesting data instead of a GET key you request using the HGET key hashkey . For setting values, use the HSET key hashkey value instead of SET key value HSET key hashkey value .
Command Examples
HSET 00777:XA 2017-01-10:2017-01-20 xxxxxxxx HSET 00777:XA 2017-01-21:2017-01-31 yyyyyyyy HSET 00777:XA 2016-02-01:2016-12-31 zzzzzzzz
(Note: there is also an HMSET to simplify this into one command) Then:
HGET 00777:XA 2017-01-21:2017-01-31
Would yyyyyyyy
If there is no specific performance consideration or other purpose for your data, I think the hash is perfect for your system.
It is also very convenient if you want to get all hashkeys or all values for a given hash using commands like HKEYS , HVALS or HGETALL .