I have installed the following dependencies in the project:
composer req symfony-bundles/redis-bundle
composer require predis/predis
I have updated the sb_redis.yaml file with the data from the REDIS_URl environment variable.
And I'm trying to access the class Predis\Client
from the controller method, but I'm getting errors.
I've only managed to get it to work like this:
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Request;
use Doctrine\ORM\EntityRepository;
use App\Entity\AEQLogin;
use Predis\Client ;
class LoginRequestController extends AbstractController
{
/**
* @Route("/V0/login/Authenticate", name="login_request", methods={"get"})
*/
public function login_authenticate(Request $request )
{
$redis = new RedisClient(getenv('REDIS_URL'));
$redis->set('name' , 'esto es un nombre');
I answer myself, after looking for the available services with this command:
php bin/console debug:autowiring redis
I have changed
use Predis\Client ;
by
use SymfonyBundles\RedisBundle\Redis\ClientInterface;
And in the method: