My codebase is in python. And this is how I access redis.
import os
import redis
from dotenv import load_dotenv
load_dotenv()
host = os.getenv("REDIS_HOST")
port = int(os.getenv("REDIS_PORT"))
host, port = host, 6379
class RedisCache(redis.Redis):
def __init__(self):
self.deserializer = lambda m: json.loads(m.decode("utf-8"))
self.serializer = lambda m: json.dumps(m)
super().__init__(
host=host, port=master_port, db=0
)
def get(self, key):
return self.deserializer(super().get(key))
In the host if i give localhost:
this is the profiler. The socket.socket function in redis is taking 1second and the entire api is taking 1.03seconds
if i change the host from localhost to 127.0.0.1
the entire api itself is taking 30ms
in redis-dist.conf file bind is defined for 127.0.0.1
localhost in hosts file is defined for both 127.0.0.1 and ::1(ipv6). even after removing ipv6 it is same.