predisHow can I configure TLS encryption for a connection between PHP and Redis?
TLS encryption can be configured for a connection between PHP and Redis using the tls
connection option. For example,
$redis = new Redis();
$redis->connect('127.0.0.1', 6379, null, null, null, null, [
'tls' => [
'ca_cert_path' => '/path/to/ca_cert.pem',
'cert_path' => '/path/to/cert.pem',
'key_path' => '/path/to/key.pem',
]
]);
The ca_cert_path
option is the path to the certificate authority's certificate. The cert_path
option is the path to the client's certificate. The key_path
option is the path to the client's private key.
Once the connection is established, you can check the TLS encryption status using the Redis::getTlsVersion()
method:
$tlsVersion = $redis->getTlsVersion();
echo $tlsVersion; // Outputs "TLSv1.2"
For more information, see the PHP Redis documentation.
More of Predis
- How can I use PHP and Redis to retrieve a range of values from a sorted set?
- How can I use Predis with a cluster in PHP?
- How do I install and configure a PHP Redis DLL on a Windows machine?
- How can I use PHP and Redis to parse JSON data?
- How can I use the zscan command in PHP with Redis?
- How can I use PHP to increment values in Redis using ZINCRBY?
- How can I use PHP and Redis to retrieve data from a sorted set using ZRANGEBYSCORE?
- How do I use hmset in PHP with Redis?
- How can I set a timeout for a Redis connection using PHP?
- How can I use Redis with the Yii PHP framework?
See more codes...