Q:

redis - User model with unique username AND email

Trying to have a user database in redis, how is it possible to implement a logic so that each and every user has unique emails and unique usernames?
{
    id             int64  autoincremented
    email          string UNIQUE
    username       string UNIQUE
    hashedPassword string
    token          string
    .
    .
}

A:

Redis does not support constraints. However, you can manage usernames and email uniqueness on client side. 
For example, you can maintain on redis a sorted set that contains all existing usernames in redis and an another sorted set that contains all emails in redis.
Before the client insert the user in redis, it query both sets with ZSCORE command if ZSCORE return NULL, the element not exists in the sorted set and also in database. If both ZSCORE commands reply with NULL, the client can insert the new client and insert username and emails in both sorted sets.

