gpt4 book ai didi

database - 如何使用此哈希通过 Redis 获取数据

转载 作者:可可西里 更新时间:2023-11-01 11:22:42 24 4
gpt4 key购买 nike

在文档中说你可以使用哈希来存储对象或任何类型的数据,然后你可以提取它们。例如,我想通过哈希保存一些用户的 id,然后提取所有 id,或者所有具有 id 的元素(类似的东西,我没有完成任何类似的事情),你能帮我吗?

redis 127.0.0.1:6379> set user:id:1234 "content of my first user"
OK
redis 127.0.0.1:6379> set user:id:1235 "content of my second user"
OK
redis 127.0.0.1:6379> set user:id:1236 "content of my third user"
OK
redis 127.0.0.1:6379> get user:id
(nil) ####I hoped to see all my id's users listed, I want to make
something like that,in the documentation I saw an example, but
is not completed####

最佳答案

那些是普通的顶级 key 集。要生成哈希,您应该使用 HSET

hset user:id 1234 "content of my first user"
hset user:id 1235 "content of my second user"

hgetall user:id

关于database - 如何使用此哈希通过 Redis 获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13159360/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com