Skip to content
This page View Markdown Open in ChatGPT Open in Claude

Get redis key

Reads values you stored with set redis key from the external Redis of API Maker (the one which also holds the cache of the APIs). Keys are kept in a namespace of the account, so two accounts never see each other's keys.

Method POST
URL /api/system-api/admin/get-redis-key : admin is the user path of your account
Body { keys }
Answer data : the value (a string, null when the key is not there), or an array of values
From code g.sys.cache.getKey

The call

Body : one key
{ "keys": "session:user123" }
Answer
{ "success": true, "statusCode": 200, "data": "{\"cart\":3}" }
Body : several keys
{ "keys": [ "session:user123", "captcha:abc" ] }
Answer
{ "success": true, "statusCode": 200, "data": [ "{\"cart\":3}", null ] }
  • Values are strings : JSON.parse what you stored as JSON.

From code

const raw = await g.sys.cache.getKey('session:user123');
const session = raw ? JSON.parse(raw) : null;
import json

raw = await g.sys.cache.get_key('session:user123')
session = json.loads(raw) if raw else None
$raw = $g->sys->cache->getKey('session:user123');
$session = $raw !== null ? json_decode($raw) : null;
var raw = await g.Sys.Cache.GetKey("session:user123");
var session = raw is null ? null : JsonNode.Parse(raw);
import "encoding/json"

raw, err := g.Sys.Cache.GetKey("session:user123") // nil when the key is not there
if err != nil {
    return nil, err
}
var session any
if raw != nil {
    if err := json.Unmarshal([]byte(*raw), &session); err != nil {
        return nil, err
    }
}
let raw = g.sys.cache.get_key("session:user123")?;
let session: Option<Value> = raw.map(|text| serde_json::from_str(&text)).transpose()?;
String raw = g.sys.cache.getKey("session:user123");
Object session = raw == null ? null : Json.parse(raw);
val raw = g.sys.cache.getKey("session:user123")
val session = raw?.let { Json.parse(it) }

Several keys at once

  • Get multiple redis keys values.
await g.sys.cache.getKey(["REDIS_KEY_NAME", "ANOTHER_REDIS_KEY_NAME"]);
await g.sys.cache.get_keys(['REDIS_KEY_NAME', 'ANOTHER_REDIS_KEY_NAME'])
$g->sys->cache->getKeys(['REDIS_KEY_NAME', 'ANOTHER_REDIS_KEY_NAME']);
await g.Sys.Cache.GetKeys(["REDIS_KEY_NAME", "ANOTHER_REDIS_KEY_NAME"]);
1
2
3
if _, err := g.Sys.Cache.GetKeys([]string{"REDIS_KEY_NAME", "ANOTHER_REDIS_KEY_NAME"}); err != nil {
    return nil, err
}
g.sys.cache.get_keys(&["REDIS_KEY_NAME", "ANOTHER_REDIS_KEY_NAME"])?;
g.sys.cache.getKeys(List.of("REDIS_KEY_NAME", "ANOTHER_REDIS_KEY_NAME"));
g.sys.cache.getKeys(listOf("REDIS_KEY_NAME", "ANOTHER_REDIS_KEY_NAME"))

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) or IS_PUBLIC. Without settings it is NO_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 is NO_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