PHP code example of xervice / redis

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

    

xervice / redis example snippets




use Xervice\Redis\RedisConfig;

// Config
$config[RedisConfig::REDIS_HOST] = '127.0.0.1';
$config[RedisConfig::REDIS_PORT] = 6379;
$config[RedisConfig::REDIS_PASSWORD] = '';
$config[RedisConfig::REDIS_DATABASE] = 0;


// Static
$config[RedisConfig::REDIS_OPTIONS] = [
    'service'    => 'master',
    'parameters' => [
        'database' => $config[RedisConfig::REDIS_DATABASE]
    ]
];

if ($config[RedisConfig::REDIS_PASSWORD]) {
    $config[RedisConfig::REDIS_OPTIONS]['parameters']['password'] = $config[RedisConfig::REDIS_PASSWORD];
}

$config[RedisConfig::REDIS] = [
    'schema' => 'tcp',
    'host'   => $config[RedisConfig::REDIS_HOST],
    'port'   => $config[RedisConfig::REDIS_PORT]
];

Locator::getInstance()->redis()->facade()->init();

Locator::getInstance()->redis()->facade()->set(...);
Locator::getInstance()->redis()->facade()->get(...);
Locator::getInstance()->redis()->facade()->mget(...);
Locator::getInstance()->redis()->facade()->mset(...);
//...