hiredis

Hiredis minimalistic Redis client bindings for Kit

Files

FileDescription
.editorconfigEditor formatting configuration
.gitignoreGit ignore rules for build artifacts and dependencies
.tool-versionsasdf tool versions (Zig, Kit)
LICENSEMIT license file
README.mdThis file
c/kit_hiredis.cC FFI wrapper
c/kit_hiredis.hC header for FFI wrapper
examples/basic.kitBasic usage example
kit.tomlPackage manifest with metadata and dependencies
src/hiredis.kitKit HiRedis - Minimalistic Redis client bindings
tests/hiredis.test.kitTests for hiredis

Dependencies

No Kit package dependencies.

Installation

kit add gitlab.com/kit-lang/packages/kit-hiredis.git

System Requirements

PlatformCommand
macOSbrew install hiredis
Ubuntusudo apt install libhiredis-dev
Fedorasudo dnf install hiredis-devel

Usage

import Kit.HiRedis as Redis

main = fn =>
  match Redis.connect "127.0.0.1" 6379
    | Ok ctx ->
      # Ping
      pong = Redis.ping ctx
      println ("PING: " ++ pong)

      # String commands
      match Redis.set ctx "key" "value"
        | Ok _ -> println "SET ok"
        | Err e -> println ("SET error: " ++ e)

      match Redis.get ctx "key"
        | Some val -> println ("GET: " ++ val)
        | None -> println "Key not found"

      # Counter
      val = Redis.incr ctx "counter"
      println ("INCR: " ++ (show val))

      # Lists
      -len = Redis.lpush ctx "mylist" "item"
      match Redis.lpop ctx "mylist"
        | Some item -> println ("LPOP: " ++ item)
        | None -> println "List empty"

      # Hashes
      match Redis.hset ctx "user" "name" "Alice"
        | Ok _ -> println "HSET ok"
        | Err e -> println ("HSET error: " ++ e)

      match Redis.hget ctx "user" "name"
        | Some val -> println ("HGET: " ++ val)
        | None -> println "Field not found"

      # Clean up
      -d = Redis.del ctx "key"
      -d2 = Redis.del ctx "counter"
      -d3 = Redis.del ctx "mylist"
      -d4 = Redis.del ctx "user"

      Redis.free ctx
    | Err e -> println ("Connection error: " ++ e)

main

Development

Running Examples

Run examples with the interpreter:

kit run examples/basic.kit

Compile examples to a native binary:

kit build examples/basic.kit && ./basic

Running Tests

Run the test suite:

kit test

Run the test suite with coverage:

kit test --coverage

Running kit dev

Run the standard development workflow (format, check, test):

kit dev

This will:

  1. Format and check source files in src/
  2. Run tests in tests/ with coverage

Generating Documentation

Generate API documentation from doc comments:

kit doc

Note: Kit sources with doc comments (##) will generate HTML documents in docs/*.html

Cleaning Build Artifacts

Remove generated files, caches, and build artifacts:

kit task clean

Note: Defined in kit.toml.

Local Installation

To install this package locally for development:

kit install

This installs the package to ~/.kit/packages/@kit/hiredis/, making it available for import as Kit.HiRedis in other projects.

License

This package is released under the MIT License - see LICENSE for details.

Hiredis is released under the BSD 3-Clause License.

Exported Functions & Types

connect

Connect to a Redis server.

Parameters:

Returns:

NonEmptyString -> PositiveInt -> Result Ptr String

connect-timeout

Connect to a Redis server with a timeout.

Parameters:

Returns:

NonEmptyString -> PositiveInt -> PositiveInt -> Result Ptr String

connect-unix

Connect to a Redis server via Unix socket.

Parameters:

Returns:

NonEmptyString -> Result Ptr String

free

Free a Redis connection and release its resources.

Parameters:

    Ptr -> Unit

is-connected?

Check if the connection is active.

Parameters:

Returns:

Ptr -> Bool

set

Set a key to a string value.

Parameters:

Returns:

Ptr -> NonEmptyString -> String -> Result Unit String

get

Get the value of a key.

Parameters:

Returns:

Ptr -> NonEmptyString -> Option String

setex

Set a key with an expiration time in seconds.

Parameters:

Returns:

Ptr -> NonEmptyString -> PositiveInt -> String -> Result Unit String

del

Delete a key.

Parameters:

Returns:

Ptr -> NonEmptyString -> Int

exists?

Check if a key exists.

Parameters:

Returns:

Ptr -> NonEmptyString -> Bool

expire

Set an expiration on a key.

Parameters:

Returns:

Ptr -> NonEmptyString -> PositiveInt -> Result Unit String

ttl

Get the remaining time to live of a key.

Parameters:

Returns:

Ptr -> NonEmptyString -> Int

incr

Increment the integer value of a key by 1.

Parameters:

Returns:

Ptr -> NonEmptyString -> Int

decr

Decrement the integer value of a key by 1.

Parameters:

Returns:

Ptr -> NonEmptyString -> Int

incrby

Increment the integer value of a key by a specific amount.

Parameters:

Returns:

Ptr -> NonEmptyString -> Int -> Int

lpush

Push a value to the left (head) of a list.

Parameters:

Returns:

Ptr -> NonEmptyString -> String -> Int

rpush

Push a value to the right (tail) of a list.

Parameters:

Returns:

Ptr -> NonEmptyString -> String -> Int

lpop

Pop a value from the left (head) of a list.

Parameters:

Returns:

Ptr -> NonEmptyString -> Option String

rpop

Pop a value from the right (tail) of a list.

Parameters:

Returns:

Ptr -> NonEmptyString -> Option String

llen

Get the length of a list.

Parameters:

Returns:

Ptr -> NonEmptyString -> Int

hset

Set a field in a hash.

Parameters:

Returns:

Ptr -> NonEmptyString -> NonEmptyString -> String -> Result Unit String

hget

Get a field value from a hash.

Parameters:

Returns:

Ptr -> NonEmptyString -> NonEmptyString -> Option String

hdel

Delete a field from a hash.

Parameters:

Returns:

Ptr -> NonEmptyString -> NonEmptyString -> Int

hexists?

Check if a field exists in a hash.

Parameters:

Returns:

Ptr -> NonEmptyString -> NonEmptyString -> Bool

command

Execute an arbitrary Redis command string.

Parameters:

Returns:

Ptr -> String -> String

ping

Ping the Redis server.

Parameters:

Returns:

Ptr -> String

select-db

Select a Redis database by index.

Parameters:

Returns:

Ptr -> Int -> Result Unit String

flushdb

Flush (delete all keys in) the current database.

Parameters:

Returns:

Ptr -> Result Unit String