Merge pull request #847 from Zankaria/redis-cache-fix

Fixes for the redis cache implementation
This commit is contained in:
Lorenzo Yario 2024-12-02 08:47:18 -08:00 committed by GitHub
commit 342558307d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 37 additions and 5 deletions

View File

@ -24,11 +24,11 @@ services:
- ./local-instances/${INSTANCE:-0}/www:/var/www - ./local-instances/${INSTANCE:-0}/www:/var/www
- ./docker/php/www.conf:/usr/local/etc/php-fpm.d/www.conf - ./docker/php/www.conf:/usr/local/etc/php-fpm.d/www.conf
- ./docker/php/jit.ini:/usr/local/etc/php/conf.d/jit.ini - ./docker/php/jit.ini:/usr/local/etc/php/conf.d/jit.ini
- redis-sock:/var/run/redis
#MySQL Service #MySQL Service
db: db:
image: mysql:8.0.35 image: mysql:8.0.35
container_name: db
restart: unless-stopped restart: unless-stopped
tty: true tty: true
ports: ports:
@ -38,3 +38,13 @@ services:
MYSQL_ROOT_PASSWORD: password MYSQL_ROOT_PASSWORD: password
volumes: volumes:
- ./local-instances/${INSTANCE:-0}/mysql:/var/lib/mysql - ./local-instances/${INSTANCE:-0}/mysql:/var/lib/mysql
redis:
build:
context: ./
dockerfile: ./docker/redis/Dockerfile
volumes:
- redis-sock:/var/run/redis
volumes:
redis-sock:

6
docker/redis/Dockerfile Normal file
View File

@ -0,0 +1,6 @@
FROM redis:7.4-alpine
RUN mkdir -p /var/run/redis && chmod 777 /var/run/redis
COPY ./docker/redis/redis.conf /etc/redis.conf
ENTRYPOINT [ "docker-entrypoint.sh", "/etc/redis.conf" ]

16
docker/redis/redis.conf Normal file
View File

@ -0,0 +1,16 @@
# Accept connections on the specified port, default is 6379 (IANA #815344).
# If port 0 is specified Redis will not listen on a TCP socket.
#port 6379
port 0
# Unix socket.
#
# Specify the path for the Unix socket that will be used to listen for
# incoming connections. There is no default, so Redis will not listen
# on a unix socket when not specified.
#
unixsocket /var/run/redis/redis-server.sock
# Executig a socket is a no-op, and we need to share acces to other programs.
# Shared the connection only with programs in the redis group for security.
#unixsocketperm 700
unixsocketperm 666

View File

@ -8,7 +8,7 @@ class RedisCacheDriver implements CacheDriver {
private string $prefix; private string $prefix;
private \Redis $inner; private \Redis $inner;
public function __construct(string $prefix, string $host, ?int $port, ?string $password, string $database) { public function __construct(string $prefix, string $host, ?int $port, ?string $password, int $database) {
$this->inner = new \Redis(); $this->inner = new \Redis();
if (str_starts_with($host, 'unix:') || str_starts_with($host, ':')) { if (str_starts_with($host, 'unix:') || str_starts_with($host, ':')) {
$ret = \explode(':', $host); $ret = \explode(':', $host);
@ -30,10 +30,10 @@ class RedisCacheDriver implements CacheDriver {
throw new \RuntimeException('Unable to configure Redis serializer'); throw new \RuntimeException('Unable to configure Redis serializer');
} }
if (!$this->inner->select($database)) { if (!$this->inner->select($database)) {
throw new \RuntimeException('Unable to connect to Redis!'); throw new \RuntimeException('Unable to connect to Redis database!');
} }
$$this->prefix = $prefix; $this->prefix = $prefix;
} }
public function get(string $key): mixed { public function get(string $key): mixed {

View File

@ -174,7 +174,7 @@
// Redis server to use. Location, port, password, database id. // Redis server to use. Location, port, password, database id.
// Note that vichan may clear the database at times, so you may want to pick a database id just for // Note that vichan may clear the database at times, so you may want to pick a database id just for
// vichan to use. // vichan to use.
$config['cache']['redis'] = array('localhost', 6379, '', 1); $config['cache']['redis'] = [ 'localhost', 6379, null, 1 ];
// EXPERIMENTAL: Should we cache configs? Warning: this changes board behaviour, i'd say, a lot. // EXPERIMENTAL: Should we cache configs? Warning: this changes board behaviour, i'd say, a lot.
// If you have any lambdas/includes present in your config, you should move them to instance-functions.php // If you have any lambdas/includes present in your config, you should move them to instance-functions.php