r

redonis

e82c574library

RESP3 based Redis client library for the Odin programming language.

0 stars0 forksMITupdated 5 hours ago
Open repo

Redonis — Redis SDK for Odin

RESP3-based Redis client library for the Odin programming language.

Features

  • RESP3
  • Basic connection pooling with configurable min/max connections
  • Flat Client API — all Redis commands as methods on a single Client struct. Might change later.
  • Type-safe responses — native Odin types (string, i64, bool, etc.)

Quick Start

package main

import "redonis"

main :: proc() {
    cfg := redonis.Pool_Config{
        address   = "localhost:6379",
        password  = "",       // optional
        username  = "",       // optional (Redis 6+ ACL)
        database  = 0,        // optional
        min_conns = 0,
        max_conns = 10,
    }

    client, err := redonis.client_init(cfg)
    defer redonis.client_destroy(client)

    // Strings
    redonis.client_set(client, "key", "value")
    val, _ := redonis.client_get(client, "key")

    // Hashes
    redonis.client_hset(client, "hash", "field1", "val1", "field2", "val2")
    hval, _ := redonis.client_hget(client, "hash", "field1")

    // Lists
    redonis.client_lpush(client, "list", "a", "b", "c")
    items, _ := redonis.client_lrange(client, "list", 0, -1)

    // Sets
    redonis.client_sadd(client, "set", "x", "y", "z")
    members, _ := redonis.client_smembers(client, "set")

    // Sorted Sets
    redonis.client_zadd(client, "zset", .None, "1.0", "one", "2.0", "two")

    // Streams
    redonis.client_xadd(client, "stream", "*", "sensor", "temp", "value", "42")

    // Raw execute for custom/unimplemented commands
    raw_val, _ := redonis.client_raw(client, "CUSTOM", "arg1", "arg2")
}

Error Handling

Errors are a tagged union:

Error :: union {
    Redis_Error,       // Redis returned an error (code + message)
    Connection_Error,  // Dial, connection lost, auth/hello failed, parse error
    Pool_Error,        // Pool exhausted or closed
}

Usage:

val, err := redonis.client_get(client, "key")
switch e in err {
case redonis.Redis_Error:
    fmt.println("Redis error:", e.code, e.message)
case redonis.Connection_Error:
    fmt.println("Connection error:", e)
case redonis.Pool_Error:
    fmt.println("Pool error:", e)
}

Implemented Commands

Connection

ping echo select quit hello

Server

info time client_list client_getname client_setname config_get config_set command

Keys

del exists expire expireat ttl pttl persist keys scan type rename renamenx dbsize flushdb flushall randomkey move copy

Strings

set set_ex set_px set_nx set_xx get getset mget mset setnx setex psetex append strlen incr incrby decr decrby incrbyfloat getrange setrange getdel getex

Hashes

hset hsetnx hget hgetall hdel hexists hkeys hvals hlen hincrby hincrbyfloat hmget hmset hscan

Lists

lpush rpush lpop rpop llen lrange lindex lset lrem ltrim blpop brpop linsert lpos

Sets

sadd srem smembers sismember scard spop srandmember smove sunion sunionstore sinter sinterstore sdiff sdiffstore sscan smismember

Sorted Sets

zadd zrem zscore zrank zrevrank zcard zcount zrange zrevrange zrangebyscore zincrby zremrangebyrank zremrangebyscore zpopmin zpopmax zscan

Streams

xadd xread xrange xrevrange xlen xdel xtrim xreadgroup xgroup_create xgroup_destroy xgroup_createconsumer xgroup_delconsumer xack xclaim xpending

Geospatial

geoadd geodist geohash geopos geosearch geosearchstore

HyperLogLog

pfadd pfcount pfmerge

Bitmaps

setbit getbit bitcount bitpos bitop bitfield

Scripting

eval evalsha script_load script_exists script_flush script_kill

Transactions

multi exec discard watch unwatch

ACL

acl_list acl_users acl_getuser acl_setuser acl_deluser acl_cat acl_genpass acl_whoami acl_log acl_save acl_load acl_dryrun

Generic

touch unlink sort

Escape Hatch

client_raw — execute any Redis command by passing args directly. Useful for commands not yet wrapped.

What's Missing / Planned

Pub/Sub

subscribe unsubscribe psubscribe punsubscribe publish pubsub

The connection layer already has conn_send/conn_receive split and conn_receive_push for reading push messages. Pub/Sub will be added in v2 with a background thread for push message dispatch and a callback/subscription registry on the Client.

Cluster

All CLUSTER * commands (e.g., CLUSTER NODES, CLUSTER SLOTS, CLUSTER MEET, etc.)

Pipelining

Batch command execution (pipeline_queue / pipeline_exec).

Connection Pool Enhancements

  • Idle connection timeout/eviction
  • Health checks (periodic PING)
  • Connection max lifetime
  • Metrics (active/idle count)

Testing

  • No integration tests against a running Redis instance yet
  • No unit tests for the RESP3 parser/writer

Versioning in the code

  • I've no idea how to handle package versioning in odin. I need to do some research.
Package Info
Version
e82c574
License
MIT
Author
@gokomer
Type
library
Forks
0
Created
5 hours ago
Updated
5 hours ago
Health
maintained
has releases
has readme
has license
Activity
last 56 weeks