{"metadata":{"name":"hew/db/redis","vers":"0.7.1","description":"Actor-owned Redis client with typed errors, explicit misses, pipelines, and bounded pub/sub","license":"MIT OR Apache-2.0","authors":["Hew Contributors"],"deps":[],"features":{},"keywords":["database","redis","cache"],"repository":"https://github.com/hew-lang/ecosystem","edition":"2026","hew":">=0.10.0, <0.12.0","readme":"# hew.db.redis\n\nAn actor-owned Redis client for Hew. Its commands fail with a typed `RedisError`,\ndistinguishes missing values from present empty byte buffers, and automatically\nreleases connection, reply, collection, and pipeline resources.\n\n## Example\n\nRun Redis locally on its default port, then save this as `main.hew` in a\nproject that depends on `hew.db.redis = \"0.7.1\"`:\n\n```hew\nimport hew.db.redis;\nimport std.encoding.utf8;\n\nfn main() {\n    let client = spawn redis.Conn { options: redis.Options { url: \"redis://127.0.0.1/\" } };\n\n    match client.set(\"greeting\", \"hello\".to_bytes()) {\n        .Ok(_) => {}\n        .Err(.Failed(error)) => println(redis.error_message(error)),\n        .Err(_) => println(\"Redis actor stopped before replying\"),\n    }\n\n    match client.get(\"greeting\") {\n        .Ok(.Value(value)) => println(utf8.decode_lossy(value)),\n        .Ok(.Missing) => println(\"greeting is missing\"),\n        .Err(.Failed(error)) => println(redis.error_message(error)),\n        .Err(_) => println(\"Redis actor stopped before replying\"),\n    }\n\n    stop(client);\n    stopped(client);\n}\n```\n\nThe checked example at [`examples/basic.hew`](examples/basic.hew) is the same\nprogram, plus a test that runs it, against the Redis service in\n`docker-compose.yml`. Run it from the\necosystem checkout:\n\n```sh\ndocker compose up -d redis\nhew run --pkg-path . db/redis/examples/basic.hew\n```\n\nIt prints `hello`.\n\nEvery command declares `fails RedisError`, so a call replies with\n`Result<T, ActorError<RedisError>>`: `.Ok(value)` on success,\n`.Err(.Failed(error))` when Redis reports a failure, and another `ActorError`\nvariant, such as `.Dead`, when the actor could not answer. Redis payloads use\nHew's `bytes` ABI end to end, so embedded NUL and non-text bytes round-trip\nwithout C-string truncation.\n\nA plain `import hew.db.redis;` brings in the module, not its type names\nunqualified. The example writes `redis.Options { url: ... }` for that reason.\n`.Value` and `.Missing` work because the match scrutinee's type selects the\nenum. A type annotation, such as `Vec<Lookup>`, needs either a qualified\n`redis.Lookup` or a brace import:\n\n```hew\nimport hew.db.redis.{Lookup};\n```\n\nThat is the whole rule, and it is why some files here carry a brace import and\nmost do not.\n\n## Pipelines\n\nPipelines are submitted as a complete wire-safe command list. The actor owns\nthe native queue and releases it on success or error:\n\n```hew\nvar commands: Vec<redis.PipelineCommand> = Vec.new();\ncommands.push(redis.PipelineCommand.Set(\"one\", \"1\".to_bytes()));\ncommands.push(redis.PipelineCommand.Set(\"two\", \"2\".to_bytes()));\nlet _ = client.pipeline_exec(commands);\n```\n\n## API surface\n\n`pub actor Conn { init(options: Options) ... }` — one connection per actor\ninstance. Every method below is a `receive fn` declared `-> T fails RedisError`,\nwhere `T` is the return listed:\n\n| Method | Returns |\n| --- | --- |\n| `set(key, value: bytes)` | `()` |\n| `get(key)` | `Lookup` |\n| `del(key)` | number of keys removed |\n| `set_ex(key, value: bytes, ttl_seconds)` | `()` |\n| `expire(key, ttl_seconds)` | `bool` — whether the key existed |\n| `ttl(key)` | `KeyTtl` |\n| `incr(key)` | the incremented `i64` |\n| `lpush(key, value: bytes)` | new list length |\n| `rpop(key)` | `Lookup` |\n| `hset(key, field, value: bytes)` | `bool` — newly added |\n| `hget(key, field)` | `Lookup` |\n| `hdel(key, field)` | `bool` — whether it existed |\n| `hgetall(key)` | `Vec<HashEntry>` |\n| `sadd(key, member: bytes)` | `bool` — newly inserted |\n| `srem(key, member: bytes)` | `bool` — whether it existed |\n| `smembers(key)` | `Vec<SetMember>` |\n| `sismember(key, member: bytes)` | `bool` |\n| `publish(channel, message: bytes)` | subscriber count |\n| `subscribe_once(channel, timeout_ms)` | `bytes` — one message, or `RedisError.Timeout` |\n| `pipeline_exec(commands: Vec<PipelineCommand>)` | pipeline result count |\n| `stop(client); stopped(client);` | Gracefully stop the actor and wait for native connection cleanup. |\n\nTypes: `RedisError` (`Connection`, `InvalidInput`, `Command`, `Timeout`,\n`Closed`, `Internal` — use `error_message(error)` for the diagnostic string),\n`Lookup` (`Missing` / `Value(bytes)`), `KeyTtl` (`Missing` / `Persistent` /\n`Seconds(i64)`), `HashEntry { field, value }`, `SetMember { value }`,\n`Options { url }`, and `PipelineCommand` (`Ping`, `Del`, `Set`, `Hset`).\n"},"version":{"name":"hew/db/redis","vers":"0.1.0","deps":[],"features":{},"cksum":"sha256:0f341c8056ca9e4f5b0fd47258bd1223a39c71ac54e17bbe27dbd3f3482d6104","sig":"ed25519:a88102f2d0371e5654e7e7ed6a876196ab8cf5f5a8c794eda4d416d8dd7a4c468914a41a67248b1e1831b0fbf54775e473bdaf940d0826041a0cc5cf16d24f0e","key_fp":"SHA256:3njv78NJD/NTkV83eJ86yfrXqpu+l652GAjPzB/Grp0","yanked":false,"registry_sig":"ed25519:70b3bc073e1afe0fb57813ba97dc4b5cfa3a3f65c5a9fb85bd70e73e07b621c0312f092c49ae5ffce4e335f5fdcf8d42f37bbdd2467b9eb8af88974d702dad0e","registry_key_fp":"SHA256:NR2yrof9/ZWkCWyhDODRU8Yvm9Lob/0yYVTdCKzMHb8","published_at":"2026-03-12T21:10:49.532Z","dl":"https://cdn.hewpkg.com/tarballs/hew/db/redis/0.1.0.tar.zst"}}