Skip to content

Instantly share code, notes, and snippets.

@laytan
Created May 24, 2023 18:04
Show Gist options
  • Save laytan/2b7eb3f0e5607e94e00f05936fa1e85a to your computer and use it in GitHub Desktop.
Save laytan/2b7eb3f0e5607e94e00f05936fa1e85a to your computer and use it in GitHub Desktop.
In progress Redis (hiredis) bindings for Odin
package hiredis
import "core:c"
foreign import lib "./libhiredis.a"
ERR :: -1
OK :: 0
ERR_IO :: 1
ERR_OTHER :: 2
ERR_EOF :: 3
ERR_PROTOCOL :: 4
ERR_OOM :: 5
ERR_TIMEOUT :: 6
REPLY_STRING :: 1
REPLY_ARRAY :: 2
REPLY_INT :: 3
REPLY_NIL :: 4
REPLY_STATUS :: 5
REPLY_ERROR :: 6
// RESP3, don't think its needed.
// REPLY_DOUBLE :: 7
// REPLY_BOOL :: 8
// REPLY_MAP :: 9
// REPLY_SET :: 10
// REPLY_ATTR :: 11
// REPLY_PUSH :: 12
// REPLY_BIGNUM :: 13
// REPLY_VERB :: 14
Context :: struct {
funcs: rawptr,
err: c.int,
errstr: [128]byte,
// More fields here...
}
Reply :: struct {
type: c.int,
integer: c.longlong,
double: c.double,
len: c.size_t,
str: cstring,
vtype: [4]byte,
elements: c.size_t,
element: ^[]Reply, // I think.
}
foreign lib {
@(link_name="redisConnect")
connect :: proc(ip: cstring, port: c.int) -> ^Context ---
@(link_name="redisCommand")
command :: proc(ctx: ^Context, cmd: cstring) -> ^Reply ---
@(link_name="redisCommandArgv")
command_argv :: proc(ctx: ^Context, count: c.int, args: [^]cstring, lengths: [^]c.size_t) -> ^Reply ---
@(link_name="redisFree")
free :: proc(ctx: ^Context) ---
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment