gpt4 book ai didi

Redis数据架构用于用户登录检查

转载 作者:可可西里 更新时间:2023-11-01 11:39:17 32 4
gpt4 key购买 nike

我第一次接触 Redis。我想为我的项目创建最灵活的架构(将来或现在使用集群)。我的主要数据存储 - Redis,现在,我重写了存储库:我有 EntityFramework 存储库:

public class UserRepository : CommonRepository<User, Guid>
{
public async Task<bool> IsLoginExists(string email)
{
return await ExistsAsync(user => user.Email == email);
}

public async Task<bool> CheckLoginPassword(string email, string password)
{
return await ExistsAsync(user => user.Email == email && user.Password == password);
}

public User GetByEmail(string email)
{
return FindOne(user => user.Email == email);
}
}

所有用户都保留为 {user:ab1a8d80-1fdb-4668-b477-f92be4815e1c} 和所有其他属性的 hashEntry。但是我没有经验,我想存储用户登录信息(我不想加入 key )。最佳实践是什么?对于分片和简单的查询......创建 key UserLogins 并为所有 userLogins 添加哈希?无法查询此信息。

创建 key :{user_login:test@mail.com} 值:ab1a8d80-1fdb-4668-b477-f92be4815e1c ?

最佳答案

从 Redis 书中我得到答案!

set users:9001 "{id: 9001, email: leto@dune.gov, ...}"
hset users:lookup:email leto@dune.gov 9001

关于Redis数据架构用于用户登录检查,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25968875/

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