diff --git a/compose.yml b/compose.yml index 4b87e0b6..71d876a2 100644 --- a/compose.yml +++ b/compose.yml @@ -24,11 +24,11 @@ services: - ./local-instances/${INSTANCE:-0}/www:/var/www - ./docker/php/www.conf:/usr/local/etc/php-fpm.d/www.conf - ./docker/php/jit.ini:/usr/local/etc/php/conf.d/jit.ini + - redis-sock:/var/run/redis #MySQL Service db: image: mysql:8.0.35 - container_name: db restart: unless-stopped tty: true ports: @@ -38,3 +38,13 @@ services: MYSQL_ROOT_PASSWORD: password volumes: - ./local-instances/${INSTANCE:-0}/mysql:/var/lib/mysql + + redis: + build: + context: ./ + dockerfile: ./docker/redis/Dockerfile + volumes: + - redis-sock:/var/run/redis + +volumes: + redis-sock: diff --git a/docker/redis/Dockerfile b/docker/redis/Dockerfile new file mode 100644 index 00000000..9ab7f7fc --- /dev/null +++ b/docker/redis/Dockerfile @@ -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" ] diff --git a/docker/redis/redis.conf b/docker/redis/redis.conf new file mode 100644 index 00000000..609d57ff --- /dev/null +++ b/docker/redis/redis.conf @@ -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 diff --git a/inc/Data/Driver/RedisCacheDriver.php b/inc/Data/Driver/RedisCacheDriver.php index a2354482..389fff32 100644 --- a/inc/Data/Driver/RedisCacheDriver.php +++ b/inc/Data/Driver/RedisCacheDriver.php @@ -8,7 +8,7 @@ class RedisCacheDriver implements CacheDriver { private string $prefix; 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(); if (str_starts_with($host, 'unix:') || str_starts_with($host, ':')) { $ret = \explode(':', $host); @@ -30,10 +30,10 @@ class RedisCacheDriver implements CacheDriver { throw new \RuntimeException('Unable to configure Redis serializer'); } 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 { diff --git a/inc/config.php b/inc/config.php index 43bd7f69..f177f9e1 100644 --- a/inc/config.php +++ b/inc/config.php @@ -174,7 +174,7 @@ // 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 // 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. // If you have any lambdas/includes present in your config, you should move them to instance-functions.php