0

I installed phpredis via pecl to my docker container (running with PHP-7.4.1-apache-buster):

RUN pecl install -f redis-5.3.1 && docker-php-ext-enable redis

I am connected to the redis server, but for all the commands I get: ERR: unknown command

$redis->select(1);

$redis->getLastError();

$redis->set('test', 'test');

$redis->getLastError();

$redis->get('test');

$redis->getLastError();

Where getLastError() returns:

'ERR unknown command 'SELECT'�'

'ERR unknown command 'SET'�'

'ERR unknown command 'GET'�'

It looks like error message contains some wrongly encoded character, which might be the cause of the problem.

I already tried to install different versions: 5.3.1 and 5.2.0 but the result is the same.

Daniel Kemeny
  • 640
  • 1
  • 5
  • 11

1 Answers1

0

Solved:

Our redis was in sentinel mode:

$redis->info();
//"redis_mode": "sentinel",

That means that first I needed to connect with RedisSentinel, then get the master address and then connect to that master as follows:

// connect to sentinel
$sentinel = new RedisSentinel('ip', 'port', 10);

// get the master ip and port you want to use
$address = $sentinel->getMasterAddrByName('your-master-name');

$redis = new Redis();
// connect to that master
$redis->pconnect($address[0], $address[1], 10);

// select the db
$redis->select(1);

// ready
Daniel Kemeny
  • 640
  • 1
  • 5
  • 11