Error 97 connecting to localhost:6379. Address family not supported by protocol
Labels: name: area: memory, name: auto:bug

### Issue you'd like to raise.

HI, I try to use  RedisChatMessageHistory but there is an error:
Error 97 connecting to localhost:6379. Address family not supported by protocol

However, another URL is defined:

```
REDIS_URL = f"redis://default:mypassword@redis-17697.c304.europe-west1-2.gce.cloud.redislabs.com:17697/0"
history = RedisChatMessageHistory(session_id='2', url=REDIS_URL, key_prefix='LILOK')
```

The Redis server is external, the VPC is disabled for the Lambda.

**Full error:**

```
[ERROR] ConnectionError: Error 97 connecting to localhost:6379. Address family not supported by protocol.
Traceback (most recent call last):
  File "/var/task/lambda_function.py", line 45, in lambda_handler
    history.add_user_message(text)
  File "/opt/python/langchain/schema/chat_history.py", line 46, in add_user_message
    self.add_message(HumanMessage(content=message))
  File "/opt/python/langchain/memory/chat_message_histories/redis.py", line 56, in add_message
    self.redis_client.lpush(self.key, json.dumps(_message_to_dict(message)))
  File "/opt/python/redis/commands/core.py", line 2734, in lpush
    return self.execute_command("LPUSH", name, *values)
  File "/opt/python/redis/client.py", line 505, in execute_command
    conn = self.connection or pool.get_connection(command_name, **options)
  File "/opt/python/redis/connection.py", line 1073, in get_connection
    connection.connect()
  File "/opt/python/redis/connection.py", line 265, in connect
    raise ConnectionError(self._error_message(e))
```
**Full code:**
```
import os
import json
import requests

from langchain.memory import RedisChatMessageHistory
from langchain import OpenAI
from langchain.chains.conversation.memory import ConversationBufferMemory
from langchain.chains import ConversationChain
TELEGRAM_TOKEN = 'mytoken'
TELEGRAM_URL = f"https://api.telegram.org/bot{TELEGRAM_TOKEN}/"

def lambda_handler(event, context):


    REDIS_URL = f"redis://default:mypassword@redis-17697.c304.europe-west1-2.gce.cloud.redislabs.com:17697/0"
    history = RedisChatMessageHistory(session_id='2', url=REDIS_URL, key_prefix='LILOK')
    llm = OpenAI(model_name='text-davinci-003', 
             temperature=0, 
             max_tokens = 256)
             
    memory = ConversationBufferMemory()
    conversation = ConversationChain(
        llm=llm, 
        verbose=True, 
        memory=memory
    )
    history = RedisChatMessageHistory("foo")
    # Log the received event for debugging
    print("Received event: ", json.dumps(event, indent=4))
    
    message = json.loads(event['body'])

    # Check if 'message' key exists in the event
    if 'message' in message:
        chat_id = message['message']['chat']['id']
        text = message['message'].get('text', '')
        
        if text == '/start':
             send_telegram_message(chat_id, "Hi!")

        else:
            history.add_user_message(text)
            result = conversation.predict(input=history.messages)
            
            history.add_ai_message(result)
            send_telegram_message(chat_id, result)
    else:
        print("No 'message' key found in the received event")
        return {
            'statusCode': 400,
            'body': json.dumps("Bad Request: No 'message' key")
        }

    return {
        'statusCode': 200
    }

def send_telegram_message(chat_id, message):
    url = TELEGRAM_URL + f"sendMessage?chat_id={chat_id}&text={message}"
    requests.get(url)

```









Please advise

### Suggestion:

_No response_