• Resolved inobgiub

    (@inobgiub)


    Hi,

    I’m unable to get the connection to my redis unix socket working. I already checked file permissions.

    PHP is able to connect to redis.

    php > $redis = new Redis();
    php > $redis->connect(‘/home/user1/.redis/redis.sock’);
    php > $res = $redis->ping();
    php > echo $res;
    1
    php > exit

    Also I tried connection to unix socket with another wordpress plugin (litespeed cache) which worked as well. Connection had been established and keys were available in redis db.

    But unfortunately Redis Object Cache plugin don’t want to connect to my socket.

    Status: Nicht verbunden
    Client: PhpRedis (v5.3.3)
    Drop-in: Valid
    Disabled: No
    Ping:
    Errors: [
    “Connection refused”
    ]
    PhpRedis: 5.3.3
    Relay: Not loaded
    Predis: Not loaded
    Credis: Not loaded
    PHP Version: 8.0.17
    Plugin Version: 2.0.25
    Redis Version: Unknown
    Multisite: No
    Metrics: Disabled
    Metrics recorded: null
    Filesystem: Working
    Global Prefix: “wp_”
    Blog Prefix: “wp_”
    WP_REDIS_SCHEME: “unix”
    WP_REDIS_PATH: “/home/user1/.redis/redis.sock”
    Global Groups: [
    “blog-details”,
    “blog-id-cache”,
    “blog-lookup”,
    “global-posts”,
    “networks”,
    “rss”,
    “sites”,
    “site-details”,
    “site-lookup”,
    “site-options”,
    “site-transient”,
    “users”,
    “useremail”,
    “userlogins”,
    “usermeta”,
    “user_meta”,
    “userslugs”,
    “redis-cache”
    ]
    Ignored Groups: [
    “counts”,
    “plugins”,
    “themes”,
    “blog-details”,
    “blog-id-cache”,
    “blog-lookup”,
    “global-posts”,
    “networks”,
    “rss”,
    “sites”,
    “site-details”,
    “site-lookup”,
    “site-options”,
    “site-transient”,
    “users”,
    “useremail”,
    “userlogins”,
    “usermeta”,
    “user_meta”,
    “userslugs”,
    “redis-cache”,
    “blog_meta”
    ]
    Unflushable Groups: []
    Drop-ins: [
    “advanced-cache.php v by “,
    “Redis Object Cache Drop-In v2.0.25 by Till Krüss”
    ]

    define( ‘WP_REDIS_PATH’, ‘/home/user1/.redis/redis.sock’ );
    define( ‘WP_REDIS_SCHEME’, ‘unix’ );

    Do you have any ideas what could be the reason?

    Best Regards!

    • This topic was modified 2 years, 6 months ago by inobgiub.
    • This topic was modified 2 years, 6 months ago by inobgiub.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Till Krüss

    (@tillkruess)

    Was this resolved? I never got an email about this post.

    unfortunately not. we stick to LScache for now. it supports redis too. it works here but without debugging in query monitor 🙁

    Hi, exact same problem on my config. Wanted to swicht to unix socket (hoping to squeeze out some performance gain) but getting the same “Connexion Refused” in the plugin diagnostic data.

    in wp-config.php:

    
    define( 'WP_REDIS_SCHEME', 'unix' );
    define( 'WP_REDIS_PATH', '/var/run/redis/redis.sock' );
    define( 'WP_REDIS_DATABASE', 0 );
    

    the /var/run/redis/redis.sock file permissions is set to 775 but the file owner (by default) is redis:redis

    I found out that when chowning the file to redis:www-data the error is gone and the plugin can connect to the Redis server just fine. But when the redis service is restarted, the (new) socket file has redis:redis as owner again and the issue returns.

    Adding redis user to the www-data group does not help. In redis.conf I had unixsocketperm 775 but that was clearly not enough. I change it to unixsocketperm 777 and did a Redis server restart again.

    This time the connexion works, even after a restart. But it’s not the most secure, is it? Is there a better way to solve this?

    Thank you, you solve my problem on making a unix socket work on Redis.

    I have no clue why the permissions need to be 777. But the comment above unixsocketperm did show an example of the permissions of 700.

    I also did a test which are changing the permissions of the parent folder back to default permission chmod 650 /var/run/redis/ and set the owner and group back to default ownerships as well chown redis:redis /var/run/redis/. The extra test works as expected!

    So I think the only concern is that redis.sock is the only permissions issue.

    Thanks!!

    I solved the same problem by simply editing the wp-config.php.

    Redis options have to go BEFORE the last line which includes wp-settings.php:

    
    define( 'WP_REDIS_SCHEME', 'unix' );
    define( 'WP_REDIS_PATH', '/path/to/redis.sock' );
    
    /** Sets up WordPress vars and included files. */
    require_once ABSPATH . 'wp-settings.php';
    
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Redis socket “Connection refused”’ is closed to new replies.