Skip to main content
Build a REST app that performs Redis operations through a RedisDemoController. You use Winter Boot for the application runtime and the Winter Redis module from Winter Modules for single-node access via PhpRedisTemplate.

Prerequisites

You need PHP 8.5 or later with the swoole, redis, and pcntl extensions. You also need a Redis server. The sample config points at localhost:30637 with password redis123 — replace the host, port, and password with your own server. Start Redis before you run the app:

Project structure

The sample uses this layout:

Install dependencies

Require the framework and the modules package:
The redis PHP extension must be installed separately:

Source files

Switch between the source files. Each tab shows the exact file from the sample.
The single entry point. It points Winter Boot at the config directory and at the sample namespace.

Configuration

Switch between the two config files. application.yml enables the module, and redis-config.yml defines the primary single-node connection.
The full sample file registers RedisModule and sets the server and app identity:
See Configuration for every application.yml key.

Run the app

Start the app, then call the endpoints to store a string, work a hash, and run the full demo. 1. Start the application:
2. Check connectivity:
3. Set a string with a 60s TTL:
4. Get the string:
5. Increment a counter:
6. Work with a hash:
7. Run the complete demo:
The demo writes string, counter, hash, list, and set keys under a time-based prefix, verifies each read, sets a TTL, cleans up, and returns one status entry per operation.

Next steps

  • Read the Redis module for cluster, array, sentinel, and Dynomite templates.
  • Browse all Libraries when you need Kafka, SQS, S3, or Doctrine in the same app.