PHP code example of abclove / redis

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

    

abclove / redis example snippets


    /**
     * 扩展类库 - Redis扩展
     */
    'redis' => array(
        //Redis链接配置项
        'servers'   => array(
            'host'      => '127.0.0.1', //Redis服务器地址
            'port'      => '6379', //Redis端口号
            'prefix'    => 'PhalApi:', //Redis-key前缀
            'auth'      => 'phalapi', //Redis链接密码
        ),
        // Redis分库对应关系
        'DB'        => array(
            'dev'  => 1,
            'user' => 2,
            'code' => 3,
            'tpl'  => 4,
        ),
        // Redis分库对应序列化值前缀
        'serialize' => array(
            'dev'  => 'dev_serialize:',
            'user' => 'user_serialize:',
            'code' => 'code_serialize:',
            'tpl'  => 'tpl_serialize:',
        ),

        // Redis分库对应键名前缀
        'prefix'    => array(
            'dev'  => 'dev:',
            'user' => 'user:',
            'code' => 'code:',
            'tpl'  => 'tpl:',
        ),



// 惰性加载Redis
\PhalApi\DI()->redis = function () {
    return new \Abclove\Redis\Lite(\PhalApi\DI()->config->get("app.redis.servers"));
}