Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ TRUSTED_PROXIES=

# Redis
REDIS_PASSWORD=!ChangeThisRedisPass!
REDIS_DNS=redis://${REDIS_PASSWORD}@127.0.0.1:6379
REDIS_HOST=127.0.0.1
REDIS_PORT=6379
REDIS_DNS=redis://${REDIS_PASSWORD}@${REDIS_HOST}:${REDIS_PORT}
# Or when using Redis Socket:
#REDIS_DNS=redis://${REDIS_PASSWORD}/var/run/redis/redis-server.sock
# Or socket without password:
Expand Down
6 changes: 4 additions & 2 deletions .env.example_docker
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,10 @@ HCAPTCHA_SECRET=
TRUSTED_PROXIES=

# Valkey
VALKEY_PASSWORD=!ChangeThisValkeyPass!
REDIS_DNS=redis://${VALKEY_PASSWORD}@valkey:6379
REDIS_PASSWORD=!ChangeThisValkeyPass!
REDIS_HOST=valkey
REDIS_PORT=6379
REDIS_DNS="redis://${REDIS_PASSWORD}@${REDIS_HOST}:${REDIS_PORT}"

# S3 storage (optional)
S3_KEY=
Expand Down
2 changes: 1 addition & 1 deletion compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ services:
image: valkey/valkey:trixie
restart: unless-stopped
user: ${MBIN_USER}
command: valkey-server /valkey.conf --requirepass ${VALKEY_PASSWORD}
command: valkey-server /valkey.conf --requirepass ${REDIS_PASSWORD}
healthcheck:
test: ['CMD', 'valkey-cli', 'ping']
volumes:
Expand Down
11 changes: 10 additions & 1 deletion config/packages/framework.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,20 @@ framework:
# We set our cookie session lifetime to the same value as remember_me token.
# More info: https://symfony.com/doc/current/session.html#session-idle-time-keep-alive
session:
handler_id: Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler
# previous
#handler_id: Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler
# transition
handler_id: App\MigratePdoToRedisSessionHandler
# new
#handler_id: Symfony\Component\HttpFoundation\Session\Storage\Handler\RedisSessionHandler
cookie_secure: auto
cookie_samesite: lax
cookie_lifetime: 10512000 # 4 months long lifetime
storage_factory_id: session.storage.factory.native
# see: https://symfony.com/doc/7.4/session.html#configuring-garbage-collection
# debian sets this value to 0, so since we cannot control that, make the garbage collection a 1/1000 chance
gc_probability: 1
gc_divisor: 1000

http_client:
default_options:
Expand Down
15 changes: 15 additions & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -285,3 +285,18 @@ services:
Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler:
arguments:
- '%env(DATABASE_URL)%'

Symfony\Component\HttpFoundation\Session\Storage\Handler\RedisSessionHandler:
arguments:
- '@Redis'

Redis:
class: Redis
calls:
- connect:
- '%env(REDIS_HOST)%'
- '%env(int:REDIS_PORT)%'

# uncomment the following if your Redis server requires a password
- auth:
- '%env(REDIS_PASSWORD)%'
17 changes: 17 additions & 0 deletions src/MigratePdoToRedisSessionHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace App;

use Symfony\Component\HttpFoundation\Session\Storage\Handler\MigratingSessionHandler;
use Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler;
use Symfony\Component\HttpFoundation\Session\Storage\Handler\RedisSessionHandler;

class MigratePdoToRedisSessionHandler extends MigratingSessionHandler
{
public function __construct(PdoSessionHandler $currentHandler, RedisSessionHandler $writeOnlyHandler)
{
parent::__construct($currentHandler, $writeOnlyHandler);
}
}
Loading