redis — Redis client

Requires: hiredis (auto-installed via minks install redis)

#include "redis"

Query results from HGetAll, SMembers, and Keys are returned as JSON arrays.


Method Args Out Description
Redis:Connect host, port Number Connect; returns handle. Throws RedisException on failure
Redis:ConnectAuth host, port, password Number Connect with AUTH
Redis:Close handle void Close the connection
Redis:Error handle String Last error message, "" if none
Redis:Set handle, key, value Boolean SET
Redis:SetEx handle, key, value, ttl Boolean SETEX with TTL in seconds
Redis:Get handle, key String GET; "" if key missing
Redis:Del handle, key Boolean DEL
Redis:Exists handle, key Boolean EXISTS
Redis:Expire handle, key, ttl Boolean EXPIRE
Redis:TTL handle, key Number TTL in seconds; -1 = no expiry, -2 = missing
Redis:Incr handle, key Number INCR
Redis:IncrBy handle, key, delta Number INCRBY
Redis:HSet handle, hash, field, value Boolean HSET
Redis:HGet handle, hash, field String HGET
Redis:HGetAll handle, hash String HGETALL → JSON object
Redis:HDel handle, hash, field Boolean HDEL
Redis:LPush handle, key, value Number LPUSH → new list length
Redis:RPush handle, key, value Number RPUSH → new list length
Redis:LPop handle, key String LPOP
Redis:RPop handle, key String RPOP
Redis:LLen handle, key Number LLEN
Redis:SAdd handle, key, member Boolean SADD
Redis:SRem handle, key, member Boolean SREM
Redis:SIsMember handle, key, member Boolean SISMEMBER
Redis:SMembers handle, key String SMEMBERS → JSON array
Redis:Keys handle, pattern String KEYS → JSON array
Redis:Exec handle, command String Raw command string → reply as string

Throws RedisException on connection failure. See Object — Exception.

Var:Number r;
Var:Boolean ok;
Var:String val;

try {
    Redis:Connect("127.0.0.1", 6379, r);
} catch (RedisException e) {
    Konsol:Print("connect failed: ${e.message}");
}

Redis:Set(r, "greeting", "hello", ok);
Redis:Get(r, "greeting", val);
Konsol:Print(val);   // hello

Redis:HSet(r, "user:1", "name", "Alice", ok);
Var:String fields;
Redis:HGetAll(r, "user:1", fields);
Konsol:Print(fields);   // {"name":"Alice"}

Redis:Close(r);

Building from source

Platform Command
Debian/Ubuntu sudo apt install libhiredis-dev
Fedora/RHEL sudo dnf install hiredis-devel
macOS brew install hiredis
MSYS2 MINGW64 pacman -S mingw-w64-x86_64-redis-plus-plus
MSYS2 UCRT64 pacman -S mingw-w64-ucrt-x86_64-redis-plus-plus
MSYS2 CLANG64 pacman -S mingw-w64-clang-x86_64-redis-plus-plus
MSYS2 CLANGARM64 pacman -S mingw-w64-clang-aarch64-redis-plus-plus

The Makefile auto-detects via pkg-config. For native Windows, build hiredis from source or install via vcpkg and set HIREDIS_DIR:

make -C redis_plugin HIREDIS_DIR="C:/path/to/hiredis"