laravel5.x配置redis和redis集群

laravel版本5.3.*

laravel使用redis作为缓存
config/cache.php文件设置
    -> 'default' => env('CACHE_DRIVER', 'redis')
redis单机配置(config/database.php):

'redis' => [
        'cluster' => true,
        'options' => [
            'cluster' => 'redis', //使用原生集群
        ],
        'default1' => [
            'host' => env('REDIS_CLUSTER_HOST1', '127.0.0.1'),
            'password' => env('REDIS_CLUSTER_PASSWORD1', null),
            'port' => env('REDIS_CLUSTER_PORT1', 7000),
            'database' => 0,
        ],
        'default2' => [
            'host' => env('REDIS_CLUSTER_HOST2', '127.0.0.1'),
            'password' => env('REDIS_CLUSTER_PASSWORD2', null),
            'port' => env('REDIS_CLUSTER_PORT2', 7000),
            'database' => 0,
        ],
        'default3' => [
            'host' => env('REDIS_CLUSTER_HOST3', '127.0.0.1'),
            'password' => env('REDIS_CLUSTER_PASSWORD3', null),
            'port' => env('REDIS_CLUSTER_PORT3', 7000),
            'database' => 0,
        ],
        ...
    ],
laravel中使用redis, 可以继续框架自带的Cache方法
例如: 
    \Cache::has($key) 判断key是否存在
    \Cache::get($key) 获取key值
    \Cache::add($key, $val, 过期时间s);  添加
    .....
    
    
发布了20 篇原创文章 · 获赞 8 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/web_snail/article/details/90412629