關鍵命名方案

為了清晰和可維護性,通常建議開發用於命名 Redis 金鑰的系統或模式。以下是用於命名金鑰的常用和可維護系統的一些示例:

user:10134
user:10134:favorites
user:10134:friends
user:10134:friends-of-friends

user:10134
user:10134/favorites
user:10134/friends
user:10134/friends.of.friends

user/10134
user/10134/favorites
user/10134/friends
user/10134/friends of friends

請注意,雖然允許,但較大的金鑰使用更多記憶體並導致查詢時間較慢,因此使用 500MB 金鑰可能不是一個好主意。更好的想法可能是使用大型二進位制物件的 SHA-1,SHA-256 或 MD5 雜湊作為鍵:

image/9517bb726d33efdc503a43582e6ea2eea309482b
image52e9df0577fca2ce022d4e8c86b1eccb070d37bef09dec36df2fabbfa7711f5c