hiredis
| Kind | ffi-c |
|---|---|
| Capabilities | ffi |
| Categories | database ffi |
| Keywords | redis hiredis cache database keyvalue |
Hiredis minimalistic Redis client bindings for Kit
Files
| File | Description |
|---|---|
.editorconfig | Editor formatting configuration |
.gitignore | Git ignore rules for build artifacts and dependencies |
.tool-versions | asdf tool versions (Zig, Kit) |
LICENSE | MIT license file |
README.md | This file |
c/kit_hiredis.c | C FFI wrapper |
c/kit_hiredis.h | C header for FFI wrapper |
examples/basic.kit | Basic usage example |
kit.toml | Package manifest with metadata and dependencies |
src/hiredis.kit | Kit HiRedis - Minimalistic Redis client bindings |
tests/hiredis.test.kit | Tests for hiredis |
Dependencies
No Kit package dependencies.
Installation
kit add gitlab.com/kit-lang/packages/kit-hiredis.gitSystem Requirements
| Platform | Command |
|---|---|
| macOS | brew install hiredis |
| Ubuntu | sudo apt install libhiredis-dev |
| Fedora | sudo 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)
mainDevelopment
Running Examples
Run examples with the interpreter:
kit run examples/basic.kitCompile examples to a native binary:
kit build examples/basic.kit && ./basicRunning Tests
Run the test suite:
kit testRun the test suite with coverage:
kit test --coverageRunning kit dev
Run the standard development workflow (format, check, test):
kit devThis will:
- Format and check source files in
src/ - Run tests in
tests/with coverage
Generating Documentation
Generate API documentation from doc comments:
kit docNote: Kit sources with doc comments (##) will generate HTML documents in docs/*.html
Cleaning Build Artifacts
Remove generated files, caches, and build artifacts:
kit task cleanNote: Defined in kit.toml.
Local Installation
To install this package locally for development:
kit installThis 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