PHP code example of mfonte / redisw

1. Go to this page and download the library: Download mfonte/redisw 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/ */

    

mfonte / redisw example snippets



use Mfonte\Redisw\RedisClient as Redisw;

try {
    $client = Redisw::instance([
        'host' => '127.0.0.1', 
        'port' => 6379, 
        'connect_timeout' => 1, // optional
        'connect_tries' => 10, // optional
        'persistent' => true, // optional
        'db_index' => 1, // optional
        'cache_ttl' => 60, // optional. Defaults to 60 sec.
        'auth_password' => '', // optional
        'ssl' => '', // optional
        'key_prefix' => 'some_prefix', // optional
        'serializer' => 'ibginary', // optional. One of: igbinary, json, php
        'compression' => 'lzf', // optional. One of: lzf, zstd, lz4
    ]);

    // set a key
    $client->set('somekey', ['value', 'value', 'value']);

    // get a key
    $value = $client->get('somekey');
}
catch(\Exception $ex) {
    echo "Something got wrong: {$ex->getMessage()}";
}

// don't want exceptions while setting/getting/whatever?
$client->wrap('set', 'wont-throw-exceptions', [1, 2, 3, 4]);

$value = $client->wrap('get', 'wont-throw-exceptions');