gpt4 book ai didi

python - 在redis中使用数据库作为键前缀

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

我正在评估使用 Redis 来存储一些 session 值。在构建 redis 客户端 ( we will be using this python one ) 时,我要传入要使用的数据库。使用数据库作为我的 key 的一种前缀是否合适?例如。将所有 session key 存储在 db 0 中,将一些消息存储在 db 1 中等等?或者我应该将所有应用程序 key 保存在同一个数据库中吗?

最佳答案

引用我在 this question 的回答:

It depends on your use case, but my rule of thumb is: If you have a very large quantity of related data keys that are unrelated to all the rest of your data in Redis, put them in a new database. Reasons being:

You may need to (non-ideally) use the keys command to get all of that data at some point, and having the data segregated makes that much cheaper.

You may want to switch to a second redis server later, and having related data pre-segregated makes this much easier.

You can keep your databases named somewhere, so it's easier for you, or a new employee to figure out where to look for particular data.

Conversely, if your data is related to other data, they should always live in the same database, so you can easily write pipelines and lua scripts that can access both.

关于python - 在redis中使用数据库作为键前缀,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18701983/

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