{"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.2.0","deps":[],"features":{},"cksum":"sha256:ac9c720e5151f1ac8286e8f96b62086886e2839e62a738d295cbe37e271b98cb","sig":"ed25519:3cc3f26c203b27726c701adb1b0104bb663956adc7c196db4fdca8e23870647e4431e30c5a638760d1d2c1a39a198cb63a9bb65e881ba064087a9ca3edd06b06","key_fp":"SHA256:Jirr0zhp7LzbnuixrT+JkXo6OneHocCoIctlKCUkqmw","yanked":false,"edition":"2026","hew":">=0.6.0-rc1, <0.7.0","registry_sig":"ed25519:903493907ffab888ca7eb755b246102f290da1622576265528877d971fe93f160fd00310fcb6b6dda3a0a6250fe330c630a91da05a8b2f5edc9a0bb999cc1b00","registry_key_fp":"SHA256:NR2yrof9/ZWkCWyhDODRU8Yvm9Lob/0yYVTdCKzMHb8","published_at":"2026-08-15T16:49:09.928Z","dl":"https://cdn.hewpkg.com/tarballs/hew/db/redis/0.2.0.tar.zst"}}