Set redis key¶
Stores values in the external Redis of API Maker, in the namespace of the account : sessions, captchas, counters, anything a later call or another server needs. Each key can expire on its own.
| Method | POST |
| URL | /api/system-api/admin/set-redis-key : admin is the user path of your account |
| Body | an array of { key, value, ttl?, NX? } |
| Answer | data : true |
| From code | g.sys.cache.setKey |
The call¶
Body
[
{ "key": "session:user123", "value": "{\"cart\":3}", "ttl": 3600 },
{ "key": "captcha:abc", "value": "7H2K", "ttl": 180, "NX": true }
]
| Key | Meaning |
|---|---|
key |
The name. It is stored under the namespace of the account. |
value |
A string. Serialise objects with JSON.stringify. |
ttl |
Seconds before the key expires. Without it, redisValueExpireInSeconds of the configuration (7200 by default) : keys never live forever. |
NX |
true : write only when the key does not exist yet. |
From code¶
import "encoding/json"
session, err := json.Marshal(am.M{"cart": 3})
if err != nil {
return nil, err
}
if _, err := g.Sys.Cache.SetKey("session:user123", string(session), 3600); err != nil {
return nil, err
}
if _, err := g.Sys.Cache.SetKeys([]am.SetKey{
{Key: "captcha:abc", Value: "7H2K", Ttl: 180, NX: true},
}); err != nil {
return nil, err
}
- The Redis dashboard shows the keys with their TTL and lets you edit them.
Access, headers and errors¶
- Over HTTP, a system API answers only once its settings open it :
TOKEN_ACCESS(the token of an API user whose group grants this system API) orIS_PUBLIC. Without settings it isNO_ACCESS: only your code (g.sys) and the admin panel reach it. - The settings can also keep the answer in the cache, or ask for the token of a person (
authProviders). Pre and post hooks run around it, as around any API. - It takes the request headers and answers the envelope.
401: no valid token, or the API isNO_ACCESS.403: no group grants it.400: the body is wrong, and the message names the key.
Related : All APIs · System API settings · System APIs from code