Clean up redis a bit more

This commit is contained in:
Amarpreet Minhas 2023-05-01 18:44:05 -04:00
parent 25440558e9
commit f6144f470d

View file

@ -37,16 +37,16 @@ func RequestNostrAddr(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "html/nostr_form.html")
case "POST":
r.ParseForm()
redisCli := redis.NostrRedisConn
redisCli := redis.NostrRedisConn.Client
// check if the user already exists
rKey := getRkey("verified", r.FormValue("Name"), getHostname(r.Host))
exists := redisCli.Client.Exists(ctx, rKey)
exists := redisCli.Exists(ctx, rKey)
if exists.Val() == 1 {
w.WriteHeader(http.StatusConflict)
return
}
rKey = getRkey("requested", r.FormValue("Name"), getHostname(r.Host))
exists = redisCli.Client.Exists(ctx, rKey)
exists = redisCli.Exists(ctx, rKey)
if exists.Val() == 1 {
w.WriteHeader(http.StatusConflict)
return
@ -84,7 +84,7 @@ func RequestNostrAddr(w http.ResponseWriter, r *http.Request) {
return
}
requestKey := getRkey("requested", r.FormValue("Name"), getHostname(r.Host))
err = redisCli.Client.Set(ctx, requestKey, enc, exp).Err()
err = redisCli.Set(ctx, requestKey, enc, exp).Err()
if err != nil {
l.Error().Msg("unable to connect to redis")
}
@ -98,11 +98,11 @@ func GetNostrAddr(w http.ResponseWriter, r *http.Request) {
requestedName := r.FormValue("name")
// connect to redis
redisCli := redis.NostrRedisConn
redisCli := redis.NostrRedisConn.Client
// search for user@domain
search := getRkey("verified", requestedName, getHostname(r.Host))
addr, err := redisCli.Client.Get(ctx, search).Result()
addr, err := redisCli.Get(ctx, search).Result()
if err != nil {
w.WriteHeader(http.StatusNotFound)
return
@ -138,10 +138,10 @@ func AddNostrAddr(n NostrRequest) {
}
jsonUser, _ := json.Marshal(user)
redisCli := redis.NostrRedisConn
redisCli := redis.NostrRedisConn.Client
nameKey := getRkey("verified", n.Name, n.Hostname)
enc := b64.StdEncoding.EncodeToString([]byte(jsonUser))
err = redisCli.Client.Set(ctx, nameKey, enc, 0).Err()
err = redisCli.Set(ctx, nameKey, enc, 0).Err()
if err != nil {
l.Error().Msg("unable to connect to redis")
}