PHP code example of mix / redis

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

    

mix / redis example snippets


$rds = new Mix\Redis\Redis('127.0.0.1', 6379, 'password', 0);

$rds->set('foo', 'bar');
$value = $rds->get('foo');

$maxOpen = 50;        // 最大开启连接数
$maxIdle = 20;        // 最大闲置连接数
$maxLifetime = 3600;  // 连接的最长生命周期
$waitTimeout = 0.0;   // 从池获取连接等待的时间, 0为一直等待
$rds->startPool($maxOpen, $maxIdle, $maxLifetime, $waitTimeout);
Swoole\Runtime::enableCoroutine(); // 必须放到最后,防止触发协程调度导致异常

$rds->poolStats(); // array, fields: total, idle, active

$tx = $rds->multi();
$tx->set('foo', 'bar');
$tx->set('foo1', 'bar1');
$ret = $tx->exec();

$tx = $rds->pipeline();
$tx->set('foo', 'bar');
$tx->set('foo1', 'bar1');
$ret = $tx->exec();

$tx = $rds->watch('foo');
$tx->incr('foo');
$ret = $tx->exec();

$db->setLogger($logger);

interface LoggerInterface
{
    public function trace(float $time, string $cmd, array $args, ?\Throwable $exception): void;
}