A page-view counter backed by Redis, using
vania_redis with the
Vania framework.
The app depends on a small CounterStore
contract, with two implementations:
RedisCounterStore— real, usingRedis().command(INCR/GET/DEL).- an in-memory fake in the tests.
A thin PageViews service sits on top, so the
counting logic is Redis-free and unit-testable. The
controller injects the Redis
store; config/app.dart registers RedisServiceProvider.
| Method | Path | Description |
|---|---|---|
| POST | /api/views/{page} |
Record a view, return the count |
| GET | /api/views/{page} |
Read the current count |
Needs a reachable Redis (REDIS_HOST / REDIS_PORT, defaults
localhost:6379):
docker run -p 6379:6379 redis:7
dart pub get
dart run bin/server.dartcurl -X POST localhost:8000/api/views/home # {"page":"home","views":1}
curl -X POST localhost:8000/api/views/home # {"page":"home","views":2}
curl localhost:8000/api/views/home # {"page":"home","views":2}PageViews is tested against the in-memory CounterStore, so no Redis is
needed:
dart test