Nextcloud connect to redis timeout

My Nextcloud is running in a docker container with MariaDB, and Redis in Raspberry Pi, if I’m not config the Redis in config.php, the Nextcloud will work, but if I config the config.php regarding Redis, the error below will show up( An error will be reported during file related operations
).

please help, Thanks!

my config.php about redis as below:

  'filelocking.enabled' => true,
  'memcache.locking' => '\OC\Memcache\Redis',
  'redis' => array(
     'host' => '172.17.0.3',
     'port' => 6379,
     'timeout' => 0.5,
     'dbindex' => '0',
     'password' => 'jabal123',
      ),

error logs in nextcloud as below:

[webdav] 错误: RedisException: Connection timed out at <<closure>>

 0. /var/www/html/lib/private/RedisFactory.php line 137
    Redis->pconnect("172.17.0.3", 6379, 0.5, "*** sensitive parameters replaced ***", 0, 0)
 1. /var/www/html/lib/private/RedisFactory.php line 178
    OC\RedisFactory->create("*** sensitive parameters replaced ***")
 2. /var/www/html/lib/private/Memcache/Redis.php line 66
    OC\RedisFactory->getInstance()
 3. /var/www/html/lib/private/Memcache/Redis.php line 137
    OC\Memcache\Redis->getCache()
 4. /var/www/html/lib/private/Lock/MemcacheLockingProvider.php line 61
    OC\Memcache\Redis->inc("files/624bbdc833a492b896084fcec0422167")
 5. /var/www/html/lib/private/Files/Storage/Common.php line 765
    OC\Lock\MemcacheLockingProvider->acquireLock("files/624bbdc833a492b896084fcec0422167", 1, "home::tate::fil ... g")
 6. /var/www/html/lib/private/Files/Storage/Wrapper/Wrapper.php line 607
    OC\Files\Storage\Common->acquireLock("files/Photos/23-01-24 21-23-30 4024.png", 1, ["OC\\Lock\\MemcacheLockingProvider"])
 7. /var/www/html/lib/private/Files/Storage/Wrapper/Wrapper.php line 607
    OC\Files\Storage\Wrapper\Wrapper->acquireLock("files/Photos/23-01-24 21-23-30 4024.png", 1, ["OC\\Lock\\MemcacheLockingProvider"])
 8. /var/www/html/lib/private/Files/View.php line 1917
    OC\Files\Storage\Wrapper\Wrapper->acquireLock("files/Photos/23-01-24 21-23-30 4024.png", 1, ["OC\\Lock\\MemcacheLockingProvider"])
 9. /var/www/html/lib/private/Files/View.php line 2030
    OC\Files\View->lockPath("/Photos/23-01-24 21-23-30 4024.png", 1, false)
10. /var/www/html/apps/dav/lib/Connector/Sabre/Node.php line 399
    OC\Files\View->lockFile("/Photos/23-01-24 21-23-30 4024.png", 1)
11. /var/www/html/apps/dav/lib/Connector/Sabre/Directory.php line 146
    OCA\DAV\Connector\Sabre\Node->acquireLock(1)
12. /var/www/html/3rdparty/sabre/dav/lib/DAV/Server.php line 1098
    OCA\DAV\Connector\Sabre\Directory->createFile("*** sensitive parameters replaced ***")
13. /var/www/html/3rdparty/sabre/dav/lib/DAV/CorePlugin.php line 504
    Sabre\DAV\Server->createFile("*** sensitive parameters replaced ***")
14. /var/www/html/3rdparty/sabre/event/lib/WildcardEmitterTrait.php line 89
    Sabre\DAV\CorePlugin->httpPut(["Sabre\\HTTP\\Request"], ["Sabre\\HTTP\\Response"])
15. /var/www/html/3rdparty/sabre/dav/lib/DAV/Server.php line 472
    Sabre\DAV\Server->emit("method:PUT", [["Sabre\\HTTP\\ ... ]])
16. /var/www/html/3rdparty/sabre/dav/lib/DAV/Server.php line 253
    Sabre\DAV\Server->invokeMethod(["Sabre\\HTTP\\Request"], ["Sabre\\HTTP\\Response"])
17. /var/www/html/3rdparty/sabre/dav/lib/DAV/Server.php line 321
    Sabre\DAV\Server->start()
18. /var/www/html/apps/dav/lib/Server.php line 364
    Sabre\DAV\Server->exec()
19. /var/www/html/apps/dav/appinfo/v2/remote.php line 35
    OCA\DAV\Server->exec()
20. /var/www/html/remote.php line 172
    require_once("/var/www/html/a ... p")

PUT /remote.php/dav/files/tate/Photos/23-01-24%2021-23-30%204024.png
from 172.18.0.1 by tate at 2023-09-22T07:01:55+00:00

hi @Tate welcome to the forum :handshake:

in docker you

  • configure the system primarily through environment variables and not through config.php
  • don’t configure an IP but rather container (service) name as redis connection as the IP will change once you restart the container.

This might or not be an issue in your case. I would recommend you docker inspect <redis> and docker inspect <nextcloud-app> and verify both are connected to the same network.

here is a very basic docker-compose extract what you need to configure redis:


cat redis.env

REDIS_HOST=redis
REDIS_HOST_PASSWORD=myhighsecurepasswordforredis

cat compose.yaml

---
version: "3.3"
  redis:
    image: redis:alpine
    container_name: nextcloud-redis
    command: redis-server --requirepass ${REDIS_HOST_PASSWORD}
    env_file:
      - ./redis.env
    restart: unless-stopped

  nextcloud-app:
    image: nextcloud:${NEXTCLOUD_VERSION}
    container_name: nextcloud-app
    depends_on:
      - db
      - redis
    env_file:
      - ./redis.env
      - ./other-related-varaibles.env
...
    networks:
      # this network is used to connect to the app e.g. from reverse proxy
      externalnetwork:
      # db and redis is connected to this network by default
      default:
...

1 Like

Many thanks for your kind reply, I Ignored the network configuration of Redis, now it’s working now.