Conecta um cliente ao servidor Redis.
Sintaxe
oRedisClient:Connect([ cServer, ] [ nPort, ] [ cAuth ])
Parâmetros
Nome | Tipo | Descrição | Obrigatório | Referência | Default | Observações |
---|---|---|---|---|---|---|
cServer | Caracter | Endereço do servidor Redis na rede | Não | Não | localhost | |
nPort | Inteiro | Porta de rede do servidor | Não | Não | 6379 | Se fornecido, deve ser o segundo parâmetro |
cParameter | Caracter | Complemento do comando | Não | Não | "" | Se fornecido, deve ser o terceiro parâmetro |
Observações
O método ::Connect()
realiza a conexão a um servidor Redis, de um objeto que apenas foi instanciado através de ::New()
Os parâmetros servidor, porta e autenticação permitem a conexão com um servidor remoto (em qualquer ponto da Internet), até mesmo com acesso seguro (ou autenticado) a ele.
A propriedade ::lConnected
permite detectar se a conexão foi bem sucedida.
Depois de uma conexão bem sucedida, deve ser feita a desconexão, antes do final do programa.
Exemplos
#include 'protheus.ch' // Setup Redis Static cRedisHost := "tec-clima" Static nRedisPort := 6379 Static cRedisAuth := "" User Function redTst() Local cMsg := '' oRedisCli := tRedisClient():New() oRedisCli:Connect(cRedisHost, nRedisPort, cRedisAuth) If oRedisCli:lConnected) ConOut("Successful connection.") oRdClient:Disconnect() ConOut("The client disconnected from the server.") Return .T. EndIf cMsg := "Could not connect to the server " + cRedisHost + ", at port " cMsg += cValToChar(nRedisPort) + ", with authentication '" + cRedisAuth + "'" ConOut(cMsg) Return .F.
Exemplo 1 - Informação de todos parâmetros
#include 'protheus.ch' // Setup Redis Static cRedisHost := "tec-clima" Static nRedisPort := 6379 Static cRedisAuth := "" User Function redTst() Local cMsg := '' oRedisCli := tRedisClient():New() oRedisCli:Connect(cRedisHost, nRedisPort, cRedisAuth) If oRedisCli:lConnected) ConOut("Successful connection.") oRdClient:Disconnect() ConOut("The client disconnected from the server.") Return .T. EndIf cMsg := "Could not connect to the server " + cRedisHost + ", at port " cMsg += cValToChar(nRedisPort) + ", with authentication '" + cRedisAuth + "'" ConOut(cMsg) Return .F.
Visão Geral
Import HTML Content
Conteúdo das Ferramentas