Henry Leu
Henry Leu

Reputation: 2274

how to link a key to an another existed key's value in redis

I want some thing like this in redis or in some redis api for nodejs

redis> HMSET local-user-id-001        id "001" name "Henry Leu" gender "m"
OK
redis> **LINK-KEY**  facebook-openid-001   local-user-id-001
OK
redis> HMGET local-user-id-001 id name gender
1) "001"
2) "Henry Leu"
3) "m"
redis> HMGET facebook-openid-001 id name gender
1) "001"
2) "Henry Leu"
3) "m"
redis> HSET facebook-openid-001 name "henryleu"
redis> HGET local-user-id-001 name
<string> henryleu

In my cases, I will create a local user account, and bind it to a SNS account, so end user can load his/her profile info by local user id or SNS openid. What I want is to maintain one user object for each of user, which can be read from local userid or SNS openid in redis server. In this way, less space to be used and simpler to maintain.

Is that a way to go?

Upvotes: 1

Views: 3910

Answers (1)

Septem
Septem

Reputation: 3622

redis doesn't support key alias, but you can add your own indirection layer. one sulotion is to keep the link between local id and open id with another key-value, such as:

set  link:facebook-openid-001 local-user-id-001 

def getUser(id) = {
    if isOpenId(id) hmget(get("link:" + id)) else hmget(id)
}

Upvotes: 3

Related Questions