9951 explained code solutions for 126 technologies


predisHow do I use PHP Predis with TLS encryption?


Using PHP Predis with TLS encryption requires a few steps:

  1. Install the Predis library via Composer:
composer require predis/predis
  1. Create a new client object, and configure it to use TLS encryption:
$client = new Predis\Client([
    'scheme' => 'tls',
    'host'   => '127.0.0.1',
    'port'   => 6379
]);
  1. Use the client object to connect to the Redis server:
$client->connect();
  1. Execute commands on the server:
$client->set('foo', 'bar');
  1. Retrieve the result of the command:
$value = $client->get('foo');
echo $value;
// Output: "bar"
  1. Close the connection when you are done:
$client->disconnect();

For more information about using TLS encryption with Predis, please refer to the official Predis documentation.

Edit this code on GitHub