I'd like to know what would be the best way to store IPs (not a lot of them (<50)) together with some meta data (time added, note) in Redis. I need to be able to quickly determine if some IP is in that list and be able to retrieve all stored IPs.
I have some ideas but they don't seem elegant/efficient to me:
Is there some other way of doing this with redis or will I have to use one of the above approaches (if so, which one is the best)?
For the your data size it will not really matter.
However how about this hack. Use an ordered set with the score being the IP (treat it as a number with each period being considered a 00, ex 127.0.0.1 => 1270000001) and each item being the metadata and the IP in JSON
zadd ip_set 1270000001 '{ip:"127.0.0.1", note:"blah"}
then to get all you just do
zrange ip_set 0 -1
and to check for presence
zcount ip_set 1270000001
Second way of course. It's a key-value storage. You should use keys exactly how you described. Redis executes operations very quickly. Don't worry about 1-2 operations.
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