PHP code example of ruesin / redis

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

    

ruesin / redis example snippets


$configs = [
    'default' => [
        'host' => '127.0.0.1',
        'port' => '6379',
        'database' => '0',
        'username' => '',
        'password' => '',
        'prefix' => 'default:'
    ],
    'web' => [
        'host' => '127.0.0.1',
        'port' => '6379',
        'database' => '0',
        'username' => '',
        'password' => '',
        'prefix' => 'web:'
    ]
];
//加载配置到静态属性
foreach ($configs as $key => $config) {
    \Ruesin\Utils\Redis::setConfig($key, $config);
}

//获取实例
$redis = \Ruesin\Utils\Redis::getInstance('default');
$redis->set('name', 'ruesin');
echo $redis->get('name') . PHP_EOL;

//关闭连接
\Ruesin\Utils\Redis::close('default');

//清理所有连接
\Ruesin\Utils\Redis::clear();