Please sign in to comment.
Implement TLS/SSL-encrypted connections.
This is handy for accessing remote Redis instances over a secure SSL connection which is currently a popular option or even requirement with many cloud hosting environments. In order to configure the client to use an SSL-encrypted connection the scheme in the connection parameters must be either "tsl" or "rediss" and a set of SSL options (see http://php.net/manual/en/context.ssl.php) must be provided via the "ssl" parameter as a named array. The following example (which does not necessarily represent an example of good practices!) illustrates how to set the "ssl" parameter using a named array and the equivalent URI string: // Parameters as named array $parameters = [ 'scheme' => 'tls', 'host' => '127.0.0.1', 'ssl' => [ 'cafile' => '/home/adaniele/redis.pem', 'verify_peer_name' => false, ], ]; // Parameters as URI string $parameters = 'tls://127.0.0.1?ssl[cafile]=redis.pem&ssl[verify_peer_name]=1'; Support for SSL is currently limited to the Predis\Connection\StreamConnection backend but we intend to investigate if it is possible to extend this feature to Predis\Connection\PhpiredisStreamConnection in the future. Be aware that using encrypted connections may lead to a performance degradation especially in the connect() operation due to the overhead of the TLS handshake. Unfortunately there is no real way to reuse SSL sessions from userland, aside from enabling persistent connections, but this will work only on PHP >= 7.0.0 because previous versions of PHP do not provide enough info about a stream from get_stream_meta_data(). NOTE: Redis does not have built-in support for SSL-encrypted connections, but if you want to expose it to public networks you may want to rely on "stunnel".
- Loading branch information...
Showing with 209 additions and 45 deletions.
- +3 −0 CHANGELOG.md
- +8 −0 FAQ.md
- +22 −4 README.md
- +2 −0 src/Connection/Factory.php
- +2 −12 src/Connection/PhpiredisStreamConnection.php
- +66 −1 src/Connection/StreamConnection.php
- +20 −0 tests/PHPUnit/PredisConnectionTestCase.php
- +38 −28 tests/Predis/Connection/FactoryTest.php
- +24 −0 tests/Predis/Connection/PhpiredisSocketConnectionTest.php
- +24 −0 tests/Predis/Connection/PhpiredisStreamConnectionTest.php