Hackerss.com

Hackerss.com is a community of amazing hackers

Hackerss is a community for developers, data scientitst, ethical hackers, hardware enthusiasts or any person that want to learn / share their knowledge of any aspect of digital technology.

Create account Log in
hackerss
hackerss

Posted on

Python Connect to redis database


import redis

def connect_redis():
    """
    Connect to redis database.

    Returns
    -------
    redis.Redis
        The redis database connection.
    """

    #connect to redis database
    return redis.Redis(host='localhost', port=6379, db=0)

#example
redis_db = connect_redis()
#output
print(redis_db)  #<redis.client.Redis object at 0x7f8b9d9b5e90>
Enter fullscreen mode Exit fullscreen mode

Top comments (0)