Redis: Can I save more than 1 value for different keys?
I'd like to save several values for the same key, for example:
key "value1" "value2" "value3"
and be able to pop the th开发者_运维问答ree values.
Redis has a list datatype which you can push to:
RPUSH key value1
RPUSH key value2
RPUSH key value3
then
RPOP key
RPOP key
RPOP key
will remove and return the elements in reverse order (i.e. the list is treated as a stack). You can also retrieve elements with LRANGE
or LINDEX
.
Have a look through the online documentation, there is even a live prompt where you can try out the commands if you click on one of the command names.
When use a list
{'key': ['value1', 'value2', 'value3'] }
精彩评论