Added a Redis/Valkey extension named redis. (0.42.0)
This commit is contained in:
parent
06072576fc
commit
cbb81c0b93
28 changed files with 798 additions and 15 deletions
|
|
@ -4,7 +4,7 @@
|
|||
<!--<p style="text-align:center;">{% if site.git %}Source: <a href="{{ site.git }}{{ site.branch }}{{ page.path }}" class="git" target="_blank">{{ site.git }}{{ site.branch }}{{ page.path }}</a>{% endif %}</p>-->
|
||||
<h2 style="display:none;">Navigation</h2>
|
||||
<ul style="list-style:none;margin-left:0px;text-align:center;">
|
||||
<li style="display:inline;"><a href="/" style="text-decoration:none;" title="Homepage" class="home">Homepage</a> -</li>
|
||||
<li style="display:inline;"><a href="/" style="text-decoration:none;" title="Home" class="home">Home</a> -</li>
|
||||
<!--<li style="display:inline;"> <a href="/about/" style="text-decoration:none;" title="About" class="about">About</a> -</li>-->
|
||||
<li style="display:inline;"> <a href="/contact/" style="text-decoration:none;" title="Contact" class="mail">Contact</a> -</li>
|
||||
<li style="display:inline;"> <a href="/community/code-of-conduct/" style="text-decoration:none;" title="Code of Conduct" class="love">Code of Conduct</a> -</li>
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@
|
|||
<div class="trigger">
|
||||
<h2 style="display:none;">Navigation</h2>
|
||||
<ul style="list-style: none;">
|
||||
<li><a class="page-link" href="/" style="text-decoration:none;" title="Homepage">/</a></li>
|
||||
<li><a class="page-link" href="/" style="text-decoration:none;" title="Home">Home</a></li>
|
||||
<li><a class="page-link" href="/about/" style="text-decoration:none;" title="About">About</a></li>
|
||||
<li><a class="page-link" href="/features/" style="text-decoration:none;" title="Features">Features</a></li>
|
||||
<!--<li><a class="page-link" href="/community/" style="text-decoration:none;" title="Community">Community</a></li>-->
|
||||
<!--<li><a class="page-link" href="/contact/" style="text-decoration:none;" title="Contact">Contact</a></li>-->
|
||||
<li><a class="page-link" href="/documentation/" style="text-decoration:none;" title="Documentation">Documentation</a></li>
|
||||
<li><a class="page-link" href="/download/" style="text-decoration:none;" title="Download">Download</a></li>
|
||||
<li><a class="page-link" href="/community/" style="text-decoration:none;" title="Community">Community</a></li>
|
||||
<li><a class="page-link" href="/contact/" style="text-decoration:none;" title="Contact">Contact</a></li>
|
||||
<li><a class="page-link" href="/faq/" style="text-decoration:none;" title="FAQ">FAQ</a></li>
|
||||
<!--
|
||||
https://www.w3schools.com/howto/howto_js_toggle_dark_mode.asp
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
layout: page
|
||||
published: false
|
||||
published: true
|
||||
noToc: false
|
||||
noDate: false
|
||||
title: Community
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
layout: page
|
||||
published: false
|
||||
published: true
|
||||
noToc: true
|
||||
noDate: false
|
||||
noPermalink: true
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@ noToc: false
|
|||
noComments: false
|
||||
noDate: false
|
||||
title: Building Fun
|
||||
subtitle: How to build Fun with CMake, available targets, and build options (FUN_DEBUG, FUN_USE_MUSL, FUN_WITH_CPP, FUN_WITH_RUST, FUN_WITH_OPENSSL).
|
||||
description: How to build Fun with CMake, available targets, and build options (FUN_DEBUG, FUN_USE_MUSL, FUN_WITH_CPP, FUN_WITH_RUST, FUN_WITH_OPENSSL).
|
||||
subtitle: How to build Fun with CMake, available targets, and build options (FUN_DEBUG, FUN_USE_MUSL, FUN_WITH_CPP, FUN_WITH_RUST, FUN_WITH_OPENSSL, FUN_WITH_REDIS).
|
||||
description: How to build Fun with CMake, available targets, and build options (FUN_DEBUG, FUN_USE_MUSL, FUN_WITH_CPP, FUN_WITH_RUST, FUN_WITH_OPENSSL, FUN_WITH_REDIS).
|
||||
permalink: /documentation/build/
|
||||
lang: en
|
||||
tags:
|
||||
|
|
@ -50,6 +50,7 @@ Fun exposes several options you can toggle at configure time:
|
|||
- `FUN_WITH_CPP` (ON/OFF) - Enable C++-based opcode/examples support
|
||||
- `FUN_WITH_RUST` (ON/OFF) - Build and link Rust staticlib from `src/rust/`
|
||||
- `FUN_WITH_OPENSSL` (ON/OFF) - Enable OpenSSL-backed helpers (MD5/SHA-256/SHA-512/RIPEMD-160)
|
||||
- `FUN_WITH_REDIS` (ON/OFF) - Enable Redis extension powered by hiredis (sync API: connect/cmd/close)
|
||||
|
||||
### VM configuration constants
|
||||
|
||||
|
|
@ -72,6 +73,8 @@ See [VM](../vm/) for more information.
|
|||
FUN_USE_MUSL: ENABLED|DISABLED
|
||||
FUN_WITH_CPP: ENABLED|DISABLED
|
||||
FUN_WITH_RUST: ENABLED|DISABLED
|
||||
FUN_WITH_OPENSSL: ENABLED|DISABLED
|
||||
FUN_WITH_REDIS: ENABLED|DISABLED
|
||||
===========================</pre>
|
||||
|
||||
## Example commands
|
||||
|
|
@ -92,7 +95,7 @@ cmake --build build_release --target build</pre>
|
|||
### Enabling optional extensions
|
||||
|
||||
<pre>cmake -S . -B build_release -DCMAKE_BUILD_TYPE=Release \
|
||||
-DFUN_WITH_CPP=ON -DFUN_WITH_RUST=ON -DFUN_WITH_OPENSSL=ON
|
||||
-DFUN_WITH_CPP=ON -DFUN_WITH_RUST=ON -DFUN_WITH_OPENSSL=ON -DFUN_WITH_REDIS=ON
|
||||
cmake --build build_release --target build</pre>
|
||||
|
||||
### Customizing VM limits
|
||||
|
|
@ -104,6 +107,8 @@ If `FUN_WITH_RUST` is enabled, ensure `cargo` is available in PATH; the build wi
|
|||
|
||||
If `FUN_WITH_OPENSSL` is enabled, CMake must detect your system OpenSSL (libcrypto).
|
||||
|
||||
If `FUN_WITH_REDIS` is enabled, ensure `hiredis` headers and library are installed and discoverable (typically via pkg-config).
|
||||
|
||||
## Running
|
||||
- CLI: run the `fun` executable from your build directory.
|
||||
- REPL: `fun -i` or just run `fun` without a script, depending on your CLI version (see [CLI](../cli/)).
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ The examples directory contains demonstrations of most Fun features, from basic
|
|||
Documentation for optional, build-time selectable integrations lives in [./extensions/](./extensions/):
|
||||
|
||||
- [Index of extensions](./extensions/)
|
||||
- Highlights: [cURL](./extensions/curl/), [INI](./extensions/ini/), [JSON](./extensions/json/), [XML (libxml2)](./extensions/xml2/), [SQLite](./extensions/sqlite/), [PCRE2](./extensions/pcre2/), [PC/SC](./extensions/pcsc/), [OpenSSL](./extensions/openssl/)
|
||||
- Highlights: [cURL](./extensions/curl/), [INI](./extensions/ini/), [JSON](./extensions/json/), [XML (libxml2)](./extensions/xml2/), [SQLite](./extensions/sqlite/), [PCRE2](./extensions/pcre2/), [PC/SC](./extensions/pcsc/), [OpenSSL](./extensions/openssl/), [Redis](./extensions/redis/)
|
||||
|
||||
## Tips
|
||||
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ This section documents Fun's optional, build-time selectable extensions. Each pa
|
|||
- [PC/SC (Smart cards)](./pcsc/)
|
||||
- [OpenSSL](./openssl/)
|
||||
- [kcgi](./kcgi/)
|
||||
- [Redis (hiredis)](./redis/)
|
||||
|
||||
## Notes:
|
||||
|
||||
|
|
|
|||
81
web/documentation/extensions/redis/redis.md
Normal file
81
web/documentation/extensions/redis/redis.md
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
---
|
||||
layout: page
|
||||
published: true
|
||||
noToc: false
|
||||
noComments: false
|
||||
noDate: false
|
||||
title: Redis (hiredis) Extension
|
||||
subtitle: Redis 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
|
||||
- hiredis
|
||||
- database
|
||||
- cache
|
||||
- extension
|
||||
- networking
|
||||
- async
|
||||
---
|
||||
|
||||
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
|
||||
------------
|
||||
- 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
|
||||
----------------------
|
||||
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>
|
||||
|
||||
When configured, the build summary will include a line:
|
||||
|
||||
<pre>Redis (FUN_WITH_REDIS): ENABLED</pre>
|
||||
|
||||
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)`
|
||||
|
||||
- `redis_cmd(handle: int, cmd: string) -> Value`
|
||||
- Executes a Redis inline command string and returns the reply as a Fun value.
|
||||
- Reply mapping:
|
||||
- Status/String -> string
|
||||
- Integer -> number
|
||||
- Nil -> `nil`
|
||||
- Array -> array of recursively converted values
|
||||
- Example: `print(redis_cmd(h, 'PING'))` ⇒ `PONG`
|
||||
|
||||
- `redis_close(handle: int) -> Nil`
|
||||
- Closes the connection associated with the handle and frees resources.
|
||||
|
||||
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
|
||||
--------
|
||||
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`
|
||||
|
||||
Quick start (from repo root, using a built Fun executable):
|
||||
|
||||
<pre>build_debug/fun examples/extensions/redis/basic_ping.fun</pre>
|
||||
|
||||
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`.
|
||||
|
|
@ -111,7 +111,7 @@ Opcode handlers organization:
|
|||
|
||||
- To keep vm.c readable, most opcode implementations are factored into small .c files included directly into vm.c (e.g., vm/core/load_const.c, vm/logic/and.c, vm/arrays/push.c, vm/math/abs.c, vm/os/thread_spawn.c, etc.).
|
||||
- This is a deliberate “amalgamation” style: small single-purpose C units compiled as part of vm.c.
|
||||
- Optional subsystems (JSON, PCRE2, CURL, SQLite, libSQL, PC/SC, XML2, Tcl/Tk, Notcurses, INI, OpenSSL/LibreSSL crypto helpers, sockets, serial, OS helpers) are grouped under src/extensions and src/vm/<domain>/.
|
||||
- Optional subsystems (JSON, PCRE2, CURL, SQLite, libSQL, PC/SC, XML2, Redis, Tcl/Tk, Notcurses, INI, OpenSSL/LibreSSL crypto helpers, sockets, serial, OS helpers) are grouped under src/extensions and src/vm/<domain>/.
|
||||
|
||||
Dispatch naming and visibility:
|
||||
|
||||
|
|
@ -152,7 +152,7 @@ The VM is dynamically typed. Values carry a tag; operations check types at runti
|
|||
- Maps: OP_MAKE_MAP/KEYS/VALUES/HAS_KEY.
|
||||
- Conversions/reflection: OP_TO_NUMBER/TO_STRING/CAST/TYPEOF, OP_UCLAMP/SCLAMP.
|
||||
- I/O and OS: OP_READ_FILE/WRITE_FILE/INPUT_LINE/ENV/PROC_RUN/PROC_SYSTEM/TIME_NOW_MS/CLOCK_MONO_MS/DATE_FORMAT/OS_LIST_DIR/RANDOM_NUMBER, sockets, serial.
|
||||
- Extensions (optional): JSON, CURL, SQLite, libSQL, PC/SC, XML2, Tcl/Tk, Notcurses, INI, OpenSSL/LibreSSL.
|
||||
- Extensions (optional): JSON, CURL, SQLite, libSQL, PC/SC, XML2, Redis, Tcl/Tk, Notcurses, INI, OpenSSL/LibreSSL.
|
||||
|
||||
Each handler enforces argument types and returns clear error messages via vm_raise_error on misuse.
|
||||
|
||||
|
|
|
|||
|
|
@ -339,8 +339,9 @@ Enabled via CMake flags; each wraps a mature C library:
|
|||
| **XML** | `FUN_WITH_XML2` | libxml2 | `xml_parse()`, `xml_root()`, `xml_name()`, `xml_text()` |
|
||||
| **PC/SC** | `FUN_WITH_PCSC` | libpcsclite | `pcsc_establish()`, `pcsc_list_readers()`, `pcsc_connect()`, `pcsc_transmit()`, etc. |
|
||||
| **KCGI** | `FUN_WITH_KCGI` | libkcgi | `kcgi_parse()`, `kcgi_reply_start()`, `kcgi_write()`, `kcgi_end()` |
|
||||
| **Redis** | `FUN_WITH_REDIS` | hiredis | `redis_connect()`, `redis_cmd()`, `redis_close()` |
|
||||
|
||||
Each extension also has a corresponding **stdlib wrapper class** in `lib/io/` or `lib/net/`:
|
||||
Some extensions also have a corresponding **stdlib wrapper class** in `lib/io/` or `lib/net/`:
|
||||
|
||||
- `JSON` class (`lib/io/json.fun`)
|
||||
- `INI` class (`lib/io/ini.fun`)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue