Skip to content

feat: add ddev redis-backend for swappable backends, fixes #32, fixes #28 #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

stasadev
Copy link
Member

@stasadev stasadev commented Apr 25, 2025

The Issue

How This PR Solves The Issue

Adds ddev redis-backend command.

TODOL add some bats tests.

Manual Testing Instructions

Using Laravel quickstart https://ddev.readthedocs.io/en/stable/users/quickstart/#laravel

mkdir my-laravel-site && cd my-laravel-site
ddev config --project-type=laravel --docroot=public
ddev start
ddev composer create-project "laravel/laravel:^12"

Get this PR add-on:

ddev dotenv set .env --cache-store=redis --redis-host=redis
ddev add-on get https://github.com/ddev/ddev-redis/tarball/20250424_stasadev_redis_backend
ddev redis-backend redis
ddev restart

Testing redis cache in Laravel:

echo "<?php
use Illuminate\Support\Facades\Route;
Route::get('/set/{key}', function ($key) {
    cache()->set('test', 'foo-'.$key);
    echo 'foo-'.$key;
});
Route::get('/get', function () {
    echo cache()->get('test');
});" > routes/web.php

$ curl -f https://my-laravel-site.ddev.site/set/bar
using redis cache store
test=bar

$ curl -f https://my-laravel-site.ddev.site/get
using redis cache store
test=bar

And now repeat:

ddev redis-backend redis-alpine
ddev restart
curl -f https://my-laravel-site.ddev.site/set/bar
curl -f https://my-laravel-site.ddev.site/get
ddev redis-backend valkey
ddev restart
curl -f https://my-laravel-site.ddev.site/set/bar
curl -f https://my-laravel-site.ddev.site/get
ddev redis-backend valkey-alpine
ddev restart
curl -f https://my-laravel-site.ddev.site/set/bar
curl -f https://my-laravel-site.ddev.site/get
ddev redis-backend redis:6
ddev restart
curl -f https://my-laravel-site.ddev.site/set/bar
curl -f https://my-laravel-site.ddev.site/get

Do the same with optimized config:

ddev dotenv set .env --cache-store=redis --redis-host=redis --redis-password=redis
ddev add-on get https://github.com/ddev/ddev-redis/tarball/20250424_stasadev_redis_backend
ddev redis-backend redis optimized
ddev restart
curl -f https://my-laravel-site.ddev.site/set/bar
curl -f https://my-laravel-site.ddev.site/get
ddev redis-backend redis-alpine optimized
ddev restart
curl -f https://my-laravel-site.ddev.site/set/bar
curl -f https://my-laravel-site.ddev.site/get
ddev redis-backend valkey optimized
ddev restart
curl -f https://my-laravel-site.ddev.site/set/bar
curl -f https://my-laravel-site.ddev.site/get
ddev redis-backend valkey-alpine optimized
ddev restart
curl -f https://my-laravel-site.ddev.site/set/bar
curl -f https://my-laravel-site.ddev.site/get
ddev redis-backend redis:6 optimized
ddev restart
curl -f https://my-laravel-site.ddev.site/set/bar
curl -f https://my-laravel-site.ddev.site/get

Automated Testing Overview

Release/Deployment Notes

@stasadev stasadev force-pushed the 20250424_stasadev_redis_backend branch 2 times, most recently from b95fa8e to 0478ef5 Compare April 29, 2025 08:53
@stasadev stasadev force-pushed the 20250424_stasadev_redis_backend branch from 0478ef5 to 42b8ff9 Compare May 7, 2025 13:13
@stasadev
Copy link
Member Author

stasadev commented May 7, 2025

I did some manual testing, not everything is 100% compatible with redis-server CLI, some images want to accept config with -c config_file.conf, others have completely different options.

This can be overridden with command: in docker-compose.redis_extra.yaml file.

So I'll only use redis and valkey presets, as I don't need to change anything for them.

Manual testings instructions are updated.

@stasadev stasadev force-pushed the 20250424_stasadev_redis_backend branch from 42b8ff9 to dc80263 Compare May 7, 2025 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant