Árvore de páginas

Você está vendo a versão antiga da página. Ver a versão atual.

Comparar com o atual Ver Histórico da Página

« Anterior Versão 18 Próxima »

Conecta um cliente ao servidor Redis.

Sintaxe

oRedisClient:Connect([ cServer, ] [ nPort, ] [ cAuth ])

Parâmetros

NomeTipoDescriçãoObrigatórioReferênciaDefaultObservações
cServer
Caracter

Endereço do servidor Redis na rede

NãoNãolocalhost
nPortInteiroPorta de rede do servidorNãoNão6379Se fornecido, deve ser o segundo parâmetro
cParameter
CaracterComplemento do comandoNãoNã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

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.

Exemplo 1 - Omissão de nPort, segundo parâmetro  

#include 'protheus.ch'
 
#define DEFAULT_REDIS_PORT 6379

// Setup Redis
Static cRedisHost := "tec-clima"
Static cRedisAuth := ""
 
User Function redTst()
  Local cMsg := ''

  // Creation of client object
  oRedisCli := tRedisClient():New()

  // Connection to the server, using default port 6379
  oRedisCli:Connect(cRedisHost, , 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(6379) + ", with authentication '" + cRedisAuth + "'" 
  ConOut(cMsg)

Return .F.
  • Sem rótulos