From 5e48743694673a521620edfb2be7ca87d3ed531f Mon Sep 17 00:00:00 2001 From: Erick Hitter <erick@ethitter.com> Date: Sat, 27 Sep 2014 01:37:13 +0000 Subject: [PATCH] Add support for socket connections --- wp-redis-user-session-storage.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/wp-redis-user-session-storage.php b/wp-redis-user-session-storage.php index f38b0d5..c82f87d 100644 --- a/wp-redis-user-session-storage.php +++ b/wp-redis-user-session-storage.php @@ -57,6 +57,7 @@ class WP_Redis_User_Session_Storage extends WP_Session_Tokens { $redis = array( 'host' => '127.0.0.1', 'port' => 6379, + 'socket' => null, 'serializer' => Redis::SERIALIZER_PHP, ); @@ -66,6 +67,9 @@ class WP_Redis_User_Session_Storage extends WP_Session_Tokens { if ( defined( 'WP_REDIS_USER_SESSION_PORT' ) && WP_REDIS_USER_SESSION_PORT ) { $redis['port'] = WP_REDIS_USER_SESSION_PORT; } + if ( defined( 'WP_REDIS_USER_SESSION_SOCKET' ) && WP_REDIS_USER_SESSION_SOCKET ) { + $redis['socket'] = WP_REDIS_USER_SESSION_SOCKET; + } if ( defined( 'WP_REDIS_USER_SESSION_AUTH' ) && WP_REDIS_USER_SESSION_AUTH ) { $redis['auth'] = WP_REDIS_USER_SESSION_AUTH; } @@ -79,7 +83,14 @@ class WP_Redis_User_Session_Storage extends WP_Session_Tokens { // Use Redis PECL library. try { $this->redis = new Redis(); - $this->redis->connect( $redis['host'], $redis['port'] ); + + // Socket preferred, but TCP supported + if ( $redis['socket'] ) { + $this->redis->connect( $redis['socket'] ); + } else { + $this->redis->connect( $redis['host'], $redis['port'] ); + } + $this->redis->setOption( Redis::OPT_SERIALIZER, $redis['serializer'] ); if ( isset( $redis['auth'] ) ) { -- GitLab