PHP code example of lorenzo / redis

1. Go to this page and download the library: Download lorenzo/redis library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

lorenzo / redis example snippets


    'Datasources' => [
        ...
        'redis' => [
            'className' => 'Cake\Redis\RedisConnection',
            'driver' => 'phpredis', // Can also use a full class name or 'predis'
            'log' => false, // Log executed commands
            'host' => '127.0.0.1',
            'port' => 6379,
            'timeout' => [optional],
            'reconnectionDelay' => [optional],
            'persistentId' => [optional],
            'database' => [optional],
            'options' => [], // extra options for the driver
        ]
    ]

use Cake\Datasource\ConnectionManager;

ConnectionManager::config('redis', [
    'className' => 'Cake\Redis\RedisConnection',
    'driver' => 'Cake\Redis\Driver\PHPRedisDriver',
    'log' => false, // Log executed commands
    'host' => '127.0.0.1',
    'port' => 6379,
    'timeout' => [optional],
    'reconnectionDelay' => [optional],
    'persistentId' => [optional],
    'database' => [optional],
    'options' => [], // extra options for the driver
]);


$redis = ConnectionManager::get('redis');
$redis->set('cakephp', 'awesome');
echo $redis->get('cakephp'); // Returns 'awesome'


$redis = ConnectionManager::get('redis');
$redis->transactional(function ($client) {
    $client
        ->set('cakephp', 'awesome')
        ->set('another_key', 'value')
});