Python uses a reference counter mechanism to deal with objects, so at the end of the blocks, the my_server object will be automatically destroyed and the connection closed. You do not need to close it explicitly.

Now this is not how you are supposed to manage Redis connections. Connecting/disconnecting for each operation is too expensive, so it is much better to maintain the connection opened. With redis-py it can be done by declaring a pool of connections:

import redis

POOL = redis.ConnectionPool(host='10.0.0.1', port=6379, db=0)

def getVariable(variable_name):
    my_server = redis.Redis(connection_pool=POOL)
    response = my_server.get(variable_name)
    return response

def setVariable(variable_name, variable_value):
    my_server = redis.Redis(connection_pool=POOL)
    my_server.set(variable_name, variable_value)

Please note connection pool management is mostly automatic and done within redis-py.

redis · PyPI

https://pypi.org/project/redis/

Python client for Redis key-value store. ... redis-py can be installed using pip similar to other Python packages. Do not use sudo with pip . It is usually good to ...

Python Redis & Redis Python Client | Redis Labs

https://redislabs.com/lp/python-redis/

The Redis Enterprise Software lets you install an enterprise grade Redis Python cluster in your environment of choice, whether an on-premises (on-prem) data- ...

How to Use Redis With Python – Real Python

https://realpython.com/python-redis/

The Python Redis client library, redis-py , that you'll dive into shortly in this article, does things differently. It encapsulates an actual TCP connection to a Redis ...

Redis client library

https://redis.io/clients

Node.js; Objective-C; OCaml; Pascal; Perl; PHP; PL/SQL; Pure Data; Python; R; Racket; Rebol; Ruby ...

Welcome to redis-py's documentation! — redis-py 2.10.5 ...

https://redis-py.readthedocs.io/

This abstract class provides a Python interface to all Redis commands and an implementation of the Redis protocol. Connection and Pipeline derive from this, ...

Welcome to redis-py's documentation! — redis-py 2.10.5 ...

https://redis-py.readthedocs.io/en/latest/

redis-py. Docs » ...

Quickstart: Use Azure Cache for Redis in Python | Microsoft Docs

https://docs.microsoft.com/en-us/azure/azure-cache-for-redis/cache-python-get-started

Nov 5, 2019 ... To connect to an Azure Cache for Redis instance, cache clients need the host name, ports, and a key for the cache. Some clients might refer to ...

Managing connection to redis from Python - Stack Overflow

https://stackoverflow.com/questions/12967107/managing-connection-to-redis-from-python

Python uses a reference counter mechanism to deal with objects, so at the end of the blocks, the my_server object will be automatically ...

Python Client for Google Cloud Memorystore for Redis API ...

https://google-cloud.readthedocs.io/en/latest/redis/

As of January 1, 2020 this library no longer supports Python 2 on the latest released version. Library versions released prior to that date will continue to be ...