Metadata-Version: 2.4
Name: muscles-data-redis
Version: 0.2.1
Summary: Redis KeyValuePort, LockPort and StreamPort adapter for muscles-data
Author-email: "Denis B." <denis@butko.info>
Project-URL: Homepage, https://github.com/butkoden/muscles-data-redis
Project-URL: Repository, https://github.com/butkoden/muscles-data-redis
Project-URL: Documentation, https://github.com/butkoden/muscles-data-redis#readme
Project-URL: PyPI, https://pypi.org/project/muscles-data-redis/
Project-URL: Releases, https://github.com/butkoden/muscles-data-redis/releases
Project-URL: muscles-data, https://pypi.org/project/muscles-data/
Project-URL: muscles-data-elasticsearch, https://pypi.org/project/muscles-data-elasticsearch/
Project-URL: muscles-data-opensearch, https://pypi.org/project/muscles-data-opensearch/
Project-URL: muscles-data-qdrant, https://pypi.org/project/muscles-data-qdrant/
Project-URL: muscles-data-mongodb, https://pypi.org/project/muscles-data-mongodb/
Project-URL: muscles-data-s3, https://pypi.org/project/muscles-data-s3/
Project-URL: muscles-data-sqlalchemy, https://pypi.org/project/muscles-data-sqlalchemy/
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: muscles-data<1.0.0,>=0.2.0
Requires-Dist: redis<9.0,>=5.0
Provides-Extra: dev
Requires-Dist: pytest<9.0,>=8.0; extra == "dev"

# muscles-data-redis

Redis adapter package for `muscles-data`.

This package is intentionally separate from `muscles-data`: the core package
owns typed ports, resource runtime and diagnostics, while this package owns
Redis-backed `KeyValuePort`, `LockPort` and `StreamPort` implementations.

## Related packages

- Core runtime and port contracts:
  [`muscles-data`](https://github.com/butkoden/muscles-data)
- Elasticsearch search adapter:
  [`muscles-data-elasticsearch`](https://github.com/butkoden/muscles-data-elasticsearch)
- OpenSearch search adapter:
  [`muscles-data-opensearch`](https://github.com/butkoden/muscles-data-opensearch)
- Qdrant vector adapter:
  [`muscles-data-qdrant`](https://github.com/butkoden/muscles-data-qdrant)
- MongoDB document-store adapter:
  [`muscles-data-mongodb`](https://github.com/butkoden/muscles-data-mongodb)
- S3 object-store adapter:
  [`muscles-data-s3`](https://github.com/butkoden/muscles-data-s3)
- SQLAlchemy direct SQL resource adapter:
  [`muscles-data-sqlalchemy`](https://github.com/butkoden/muscles-data-sqlalchemy)
- Executable example:
  [`example_data_redis_1`](https://github.com/butkoden/muscular-example/tree/master/example_data_redis_1)

## Usage

Register this adapter once in the application composition root when building
the shared `DataAdapterCatalog`, alongside other configured adapters:

```python
catalog.register(RedisDataFactory())
```

The `cache.redis` resource itself is declared in the application's central
`data.resources` configuration shown below. A package resolves the port from
the existing runtime; it does not build another catalog or `DataRuntime`:

```python
from muscles.data.ports import KeyValuePort

cache = app.resource.connect("cache.redis", KeyValuePort)
```

Resource config stays in the project:

```yaml
data:
  resources:
    cache.redis:
      type: redis
      url_env: REDIS_URL
      namespace: app
      timeout: 3
      stream_group: workers
      consumer: index-worker
```

The adapter creates the Redis client lazily by key-value, lock, stream, explicit
native access or `data.doctor` operations. Application code should use
`KeyValuePort`, `LockPort` and `StreamPort`; direct client access is only an
advanced escape hatch with `native_client: true`.

Streams use `XADD`, `XREADGROUP` and `XACK`. The configured consumer group is
created on first read and messages use the versioned
`muscles.data.message.v1` envelope. Retry and dead-letter decisions stay with
the application worker.

See `muscular-example/example_data_redis_1` for an executable example.
