1
0
Fork 0
forked from fun/fun

Documentation and Web update. No code changes. (0.42.1)

This commit is contained in:
Johannes Findeisen 2026-06-06 18:52:16 +02:00
commit 42e702f9e8
11 changed files with 74 additions and 60 deletions

View file

@ -5,12 +5,13 @@ noToc: false
noComments: false
noDate: false
title: Redis (hiredis) Extension
subtitle: Redis client integration for Fun using the hiredis C library.
subtitle: Redis/Valkey client integration for Fun using the hiredis C library.
description: Documentation for the optional Redis extension in Fun. Provides redis_connect, redis_cmd, and redis_close builtins backed by hiredis.
permalink: /documentation/extensions/redis/
lang: en
tags:
- redis
- valkey
- hiredis
- database
- cache
@ -21,25 +22,25 @@ tags:
The Redis extension adds a minimal client for Redis-compatible servers using the [hiredis](https://github.com/redis/hiredis){:class="ext"} C library. It currently exposes a simple synchronous API; Async I/O through Fun's event loop will be added later.
Requirements
------------
## Requirements
- Build-time option: `-DFUN_WITH_REDIS=ON`
- System libraries: `hiredis` headers and library available (via pkg-config or default linker search paths)
- Runtime: a Redis-compatible server (e.g., on `127.0.0.1:6379`)
Enabling the extension
----------------------
## Enabling the extension
Example CMake configure line enabling Redis along with other options:
<pre>cmake -S . -B build_release -DCMAKE_BUILD_TYPE=Release \
-DFUN_WITH_REDIS=ON -DFUN_WITH_OPENSSL=ON</pre>
-DFUN_WITH_REDIS=ON</pre>
When configured, the build summary will include a line:
<pre>Redis (FUN_WITH_REDIS): ENABLED</pre>
Provided builtins/opcodes
-------------------------
## Provided builtins/opcodes
- `redis_connect(host: string, port: int) -> int`
- Establishes a TCP connection and returns a positive handle id on success, or `0` on error.
- Example: `h = redis_connect('127.0.0.1', 6379)`
@ -56,26 +57,28 @@ Provided builtins/opcodes
- `redis_close(handle: int) -> Nil`
- Closes the connection associated with the handle and frees resources.
Notes and limitations
---------------------
## Notes and limitations
- Error handling: invalid handles or failed commands yield `nil` or an empty/neutral value depending on context.
- Security: this initial version does not include TLS; TLS support may be added in a future iteration once hiredis SSL is wired in.
- Async: the current API is synchronous. Integration with Fun's asyncio is planned.
Examples
--------
## Examples
Runnable examples are included in the source tree:
- `examples/extensions/redis/basic_ping.fun`
- `examples/extensions/redis/kv_set_get.fun`
- `examples/extensions/redis/list_ops.fun`
- `examples/extensions/redis/hash_ops.fun`
- `examples/extensions/redis/redis_test.fun`
Quick start (from repo root, using a built Fun executable):
<pre>build_debug/fun examples/extensions/redis/basic_ping.fun</pre>
Troubleshooting
---------------
## Troubleshooting
- Ensure a Redis server is reachable at the host/port you pass to `redis_connect`.
- If `redis_connect` returns `0`, verify the hiredis library and headers are installed and that Fun was configured with `-DFUN_WITH_REDIS=ON`.