首页 > 解决方案 > 使用 symfony 配置 Phpredis 客户端时遇到问题

问题描述

我在使用 Snc\RedisBundle 捆绑配置 Phpredis 时遇到问题。我正在使用 symfony 4.4 版。当我安装Predis 客户端时,如果我安装 Snc\RedisBundle,它会删除 Snc\RedisBundle,Predis 也会发生同样的情况。默认情况下 Snc\RedisBundle 包使用 PhpRedis 客户端。不知道我在配置中做错了什么,这导致了这个问题。

snc_redis.yaml

snc_redis:
    class:
        phpredis_client:
            'Snc\RedisBundle\Client\Phpredis\Client'
    clients:
        default:
            type: phpredis
            alias: default
            dsn: redis://127.0.0.1:6379 # (*)
            logging: '%kernel.debug%'
            options:
                replication: sentinel
                service: mymaster
                parameters:
                    database: 1
                    password:

服务.yaml

services:
Snc\RedisBundle\Client\Phpredis\Client: '@snc_redis.default'

RedisController.php

use Snc\RedisBundle\Client\Phpredis\Client;
/** @var  Client */
    private $redisClient;

    public function __construct(Client $client)
    {
        $this->redisClient = $client;
    }
   /**
     * @Route("/keys", name="keys")
     */
    public function indexAction()
    {
        $redisKeys = $this->redisClient->keys('*');
        return $this->json(['keys' => $redisKeys]);
    }

我收到错误警告:找不到类 'Container97esFst\Client_541ffe9'

标签: phpsymfonyredisphpredis

解决方案


推荐阅读