Redis - Get started

How do I provision a Redis PaaS?

To get started, go to ITCare and search for your target global service where you'll create your new Redis deployment.

Search for your Global Service in the top search bar and click on it to display its information page.

Once in your Global Service, click on the Create Resource button, select Redis and the required version.

Fill in the form:

  • Select a topology

  • Define the name of the future deployment

  • Sizing

  • Storage requirements for each instance

  • Target location

  • Target network

  • Management options (backup, monitoring, 24/7, remote site replication)

Click Next once all fields have been filled in.

In the customization step :

  • Enter the password for the administrator account to be provided

  • Select the required persistence options

  • Enable or disable TLS encryption

Then click on Next.

Passwords are not saved by cegedim.cloud. Be sure to save your password!

Review the summary before submitting the form.

Provisioning can take up to 2 hours, depending on the current automation load.

Once the deployment is ready, you'll be notified by e-mail.

How to connect to a standalone Redis instance?

This code describes how to connect to Redis when the topology is a single instance. This code is deliberately simplified (errors are not handled), and is intended for demonstration purposes only.

The Python language is used. We assume that the Redis instance is named pcluredis01.hosting.cegedim.cloud.

Python example without TLS
import redis
 
def main():
    try:
        myRedis = redis.Redis(host='pcluredis01.hosting.cegedim.cloud', port=6379, db=0, password='1MyStrongPassword!', username='redis', decode_responses=True)
        pong = myRedis.ping()
        print(pong) # should be True
        myRedis.set('mykey','myvalue')
        print(myRedis.get('mykey')) # should be myvalue
        myRedis.close()
    except Exception as ex:
        print(ex)
 
if __name__ == "__main__":
    main()
Python example with TLS
import redis
 
def main():
    try:
        myRedis = redis.Redis(host='pcluredis01.hosting.cegedim.cloud', port=6379, db=0, password='1MyStrongPassword!', username='redis', decode_responses=True)
        pong = myRedis.ping()
        print(pong) # should be True
        myRedis.set('mykey','myvalue')
        print(myRedis.get('mykey')) # should be myvalue
        myRedis.close()
    except Exception as ex:
        print(ex)
 
if __name__ == "__main__":
    main()

How do I connect to a Redis cluster?

This code describes how to connect to Redis in a cluster topology (with Sentinel). This is deliberately simplified (errors are not handled), and is intended for demonstration purposes only.

The Python language is used.

We assume that the Redis cluster is named redis-cluster with a "pclu" prefix. There are therefore 3 instances in this cluster:

  • pcluredis01.hosting.cegedim.cloud

  • pcluredis02.hosting.cegedim.cloud

  • pcluredis03.hosting.cegedim.cloud

Two samples are available, with and without TLS.

Python example without TLS
from redis.sentinel import Sentinel
import redis
 
def main():
    try:
        mySentinel = Sentinel(
          [
            ('pcluredis01.hosting.cegedim.cloud', 26379),
            ('pcluredis02.hosting.cegedim.cloud', 26379),
            ('pcluredis03.hosting.cegedim.cloud', 26379)
          ],
          sentinel_kwargs={
            'username': 'redis',
            'password': '1MyStrongPassword!',
            'socket_connect_timeout': 0.5
          }
        )
         
        master_host, master_port = mySentinel.discover_master('redis-cluster')
        print("Redis master address: {}, TCP port {}".format(master_host, master_port))
        myMaster = redis.Redis(
          host=master_host,
          port=master_port,
          db=0,
          password='1MyStrongPassword!',
          username='redis',
          decode_responses=True
        )
        pong = myMaster.ping()
        print(pong) # should be True
        myMaster.set('mykey','myvalue')
        print(myMaster.get('mykey')) # should be myvalue
        myMaster.close()
        replicas = mySentinel.discover_slaves('redis-cluster')
        for replica in replicas:
            replica_host = replica[0]
            replica_port = replica[1]
            myReplica = redis.Redis(host=replica_host, port=replica_port, db=0, password='1MyStrongPassword!', username='redis', decode_responses=True)
            print("replica address {} port {} mykey {}".format(replica_host, replica_port, myReplica.get('mykey'))) # should be myvalue
            myReplica.close()
         
    except Exception as ex:
        print(ex)
 
if __name__ == "__main__":
    main()
Python example with TLS
from redis.sentinel import Sentinel
import redis
 
def main():
    try:
        mySentinel = Sentinel(
          [
            ('pcluredis01.hosting.cegedim.cloud', 26379),
            ('pcluredis02.hosting.cegedim.cloud', 26379),
            ('pcluredis03.hosting.cegedim.cloud', 26379)
          ],
          sentinel_kwargs={
            'username': 'redis',
            'password': '1MyStrongPassword!',
            'ssl': True,
            'ssl_ca_certs': '/tmp/ca-redis.crt',
            'ssl_cert_reqs': None,
            'ssl_certfile': None,
            'ssl_keyfile': None,
            'ssl_check_hostname': False,
            'socket_connect_timeout': 0.5
          }
        )
         
        master_host, master_port = mySentinel.discover_master('redis-cluster')
        print("Redis master address: {}, TCP port {}".format(master_host, master_port))
        myMaster = redis.Redis(
          host=master_host,
          port=master_port,
          db=0,
          password='1MyStrongPassword!',
          username='redis',
          decode_responses=True,
          ssl=True,
          ssl_ca_certs='/tmp/ca-redis.crt'
        )
        pong = myMaster.ping()
        print(pong) # should be True
        myMaster.set('mykey','myvalue')
        print(myMaster.get('mykey')) # should be myvalue
        myMaster.close()
        replicas = mySentinel.discover_slaves('redis-cluster')
        for replica in replicas:
            replica_host = replica[0]
            replica_port = replica[1]
            myReplica = redis.Redis(host=replica_host, port=replica_port, db=0, password='1MyStrongPassword!', username='redis', decode_responses=True, ssl=True, ssl_ca_certs='/tmp/ca-redis.crt')
            print("replica address {} port {} mykey {}".format(replica_host, replica_port, myReplica.get('mykey'))) # should be myvalue
            myReplica.close()
         
    except Exception as ex:
        print(ex)
 
if __name__ == "__main__":
    main()

Last updated