A
A
Alex Plotnikov2018-02-14 19:09:24
PHP
Alex Plotnikov, 2018-02-14 19:09:24

How to check redis connection with password from php?

Greetings, the question is, how from php, without any libraries, having ip, port, auth pass for redis, check that the connection is possible and the faith data?
Thank you!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Melkij, 2018-02-14
@TrueDevs

There's a simple text protocol. You
open a socket, a bit of conversation, and now you know if they want to communicate with you. Then close the socket.

A
Alex Plotnikov, 2018-02-14
@TrueDevs

leave a snippet

$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
$res = socket_connect($socket, $address, $port);
    if($res){
        echo 'Redis connected';
        socket_write ( $socket , 'auth password'.PHP_EOL );
        echo socket_read($socket, 100); //если все ОК, получаем ответ: +OK\r\n
    }
socket_close ( $socket );

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question