开发者

Redis: Can I save more than 1 value for different keys?

开发者 https://www.devze.com 2023-02-05 11:32 出处:网络
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

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'] }
0

精彩评论

暂无评论...
验证码 换一张
取 消