From 931eb0366333dfcd92d560ab8b76a73a51284cd3 Mon Sep 17 00:00:00 2001 From: dvora-h Date: Wed, 22 Dec 2021 10:41:00 +0200 Subject: [PATCH 1/6] fixing exception in listen --- redis/client.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/redis/client.py b/redis/client.py index ae4fae2ace..16ffbb01fd 100755 --- a/redis/client.py +++ b/redis/client.py @@ -1530,6 +1530,8 @@ def handle_message(self, response, ignore_subscribe_messages=False): with a message handler, the handler is invoked instead of a parsed message being returned. """ + if response is None: + return None message_type = str_if_bytes(response[0]) if message_type == "pmessage": message = { From 14a19a77415b77186ecb22d94f9591ffedc460e7 Mon Sep 17 00:00:00 2001 From: dvora-h Date: Mon, 27 Dec 2021 13:23:40 +0200 Subject: [PATCH 2/6] create connection example notebook --- examples/connection_example.ipynb | 181 ++++++++++++++++++++++++++++++ tox.ini | 2 +- 2 files changed, 182 insertions(+), 1 deletion(-) create mode 100644 examples/connection_example.ipynb diff --git a/examples/connection_example.ipynb b/examples/connection_example.ipynb new file mode 100644 index 0000000000..b235509eb4 --- /dev/null +++ b/examples/connection_example.ipynb @@ -0,0 +1,181 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Connect to redis running locally with default parameters " + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n" + ] + } + ], + "source": [ + "import redis\n", + "r = redis.Redis()\n", + "print(r.ping())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Overwrite default parameters - connect to redis on specific host and port using username and password" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n" + ] + } + ], + "source": [ + "import redis\n", + "r = redis.Redis(host='localhost', port=6380, username='dvora', password='redis')\n", + "print(r.ping())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Create a SSL wrapped TCP socket connection" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n" + ] + } + ], + "source": [ + "import redis\n", + "r = redis.Redis(host='localhost', port=6666, ssl=True, ssl_cert_reqs=\"none\")\n", + "print(r.ping())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Add more parameters..." + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n" + ] + } + ], + "source": [ + "import os\n", + "import redis\n", + "\n", + "ROOT = os.path.join(os.getcwd(), \"..\")\n", + "CERT_DIR = os.path.abspath(os.path.join(ROOT, \"docker\", \"stunnel\", \"keys\"))\n", + "\n", + "r = redis.Redis(\n", + " host=\"localhost\",\n", + " port=6666,\n", + " ssl=True,\n", + " ssl_certfile=os.path.join(CERT_DIR, \"server-cert.pem\"),\n", + " ssl_keyfile=os.path.join(CERT_DIR, \"server-key.pem\"),\n", + " ssl_cert_reqs=\"required\",\n", + " ssl_ca_certs=os.path.join(CERT_DIR, \"server-cert.pem\"),\n", + ")\n", + "print(r.ping())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Connect to redis client object configured from given URL\n", + "##### Three URL schemes are supported:\n", + "\n", + "##### - `redis://` creates a TCP socket connection. See more at:\n", + "##### \n", + "##### - `rediss://` creates a SSL wrapped TCP socket connection. See more at:\n", + "##### \n", + "##### - ``unix://``: creates a Unix Domain Socket connection.\n", + "\n", + "##### Parameters are passed through querystring" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n" + ] + } + ], + "source": [ + "import redis\n", + "r = redis.from_url(\"rediss://localhost:6666?ssl_cert_reqs=none\")\n", + "print(r.ping())" + ] + } + ], + "metadata": { + "interpreter": { + "hash": "d45c99ba0feda92868abafa8257cbb4709c97f1a0b5dc62bbeebdf89d4fad7fe" + }, + "kernelspec": { + "display_name": "Python 3.8.12 64-bit ('venv': venv)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.12" + }, + "orig_nbformat": 4 + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/tox.ini b/tox.ini index b574d17b57..f36e9b36c9 100644 --- a/tox.ini +++ b/tox.ini @@ -136,7 +136,7 @@ skipsdist = true skip_install = true deps = -r {toxinidir}/dev_requirements.txt docker = {[testenv]docker} -commands = /usr/bin/echo +commands = /usr/bin/echo docker_up run_before = {[testenv]run_before} [testenv:linters] From 28b78a3a84310efc1b1f2750c593075f077902e1 Mon Sep 17 00:00:00 2001 From: dvora-h Date: Tue, 28 Dec 2021 09:29:30 +0200 Subject: [PATCH 3/6] remove changes in client.py --- redis/client.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/redis/client.py b/redis/client.py index 16ffbb01fd..ae4fae2ace 100755 --- a/redis/client.py +++ b/redis/client.py @@ -1530,8 +1530,6 @@ def handle_message(self, response, ignore_subscribe_messages=False): with a message handler, the handler is invoked instead of a parsed message being returned. """ - if response is None: - return None message_type = str_if_bytes(response[0]) if message_type == "pmessage": message = { From b09c44a0ce7f26f58dc8bfe620d81dc307ccd5ed Mon Sep 17 00:00:00 2001 From: "Chayim I. Kirshen" Date: Tue, 28 Dec 2021 10:47:07 +0200 Subject: [PATCH 4/6] language changes --- examples/connection_example.ipynb | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/examples/connection_example.ipynb b/examples/connection_example.ipynb index b235509eb4..dbccb6c328 100644 --- a/examples/connection_example.ipynb +++ b/examples/connection_example.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Connect to redis running locally with default parameters " + "### Connecting to a default Redis instance, running locally." ] }, { @@ -30,7 +30,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Overwrite default parameters - connect to redis on specific host and port using username and password" + "### Connecting to a redis instance, specifying a host and port with credentials." ] }, { @@ -56,7 +56,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Create a SSL wrapped TCP socket connection" + "### Connecting to a Redis instance via SSL." ] }, { @@ -82,7 +82,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Add more parameters..." + "### Connecting to a Redis instance via SSL, while specifying a self-signed SSL certificate." ] }, { @@ -121,16 +121,13 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Connect to redis client object configured from given URL\n", + "### Connecting to Redis instances by specifying a URL scheme.\n", + "##### Parameters are passed to the following schems, as parameters to the url scheme.\n\n", "##### Three URL schemes are supported:\n", "\n", - "##### - `redis://` creates a TCP socket connection. See more at:\n", - "##### \n", - "##### - `rediss://` creates a SSL wrapped TCP socket connection. See more at:\n", - "##### \n", - "##### - ``unix://``: creates a Unix Domain Socket connection.\n", - "\n", - "##### Parameters are passed through querystring" + "##### - `redis://` creates a TCP socket connection. \n", + "##### - `rediss://` creates a SSL wrapped TCP socket connection. \n", + "##### - ``unix://``: creates a Unix Domain Socket connection.\n" ] }, { @@ -158,7 +155,7 @@ "hash": "d45c99ba0feda92868abafa8257cbb4709c97f1a0b5dc62bbeebdf89d4fad7fe" }, "kernelspec": { - "display_name": "Python 3.8.12 64-bit ('venv': venv)", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -172,9 +169,8 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.12" - }, - "orig_nbformat": 4 + "version": "3.9.9" + } }, "nbformat": 4, "nbformat_minor": 2 From 8f4cdc7be430eff0484b0680c7c680d32969f0c5 Mon Sep 17 00:00:00 2001 From: "Chayim I. Kirshen" Date: Tue, 28 Dec 2021 12:43:15 +0200 Subject: [PATCH 5/6] generating jupyter notebooks into readthedocs --- docs/conf.py | 4 +- docs/examples.rst | 8 + .../connection_example-checkpoint.ipynb | 180 ++++++++++++++++++ {examples => docs/examples}/README.md | 0 .../examples}/connection_example.ipynb | 27 ++- docs/index.rst | 1 + docs/requirements.txt | 4 + tasks.py | 1 + tox.ini | 2 +- 9 files changed, 215 insertions(+), 12 deletions(-) create mode 100644 docs/examples.rst create mode 100644 docs/examples/.ipynb_checkpoints/connection_example-checkpoint.ipynb rename {examples => docs/examples}/README.md (100%) rename {examples => docs/examples}/connection_example.ipynb (77%) diff --git a/docs/conf.py b/docs/conf.py index 7e83e42156..0f11442232 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -27,6 +27,8 @@ # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones. extensions = [ + "nbsphinx", + "sphinx_gallery.load_style", "sphinx.ext.autodoc", "sphinx.ext.doctest", "sphinx.ext.viewcode", @@ -73,7 +75,7 @@ # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. -exclude_patterns = ["_build"] +exclude_patterns = ["_build", "**.ipynb_checkponts"] # The reST default role (used for this markup: `text`) to use for all # documents. diff --git a/docs/examples.rst b/docs/examples.rst new file mode 100644 index 0000000000..1a82182869 --- /dev/null +++ b/docs/examples.rst @@ -0,0 +1,8 @@ +Examples +######## + +.. toctree:: + :maxdepth: 3 + :glob: + + examples/connection_example diff --git a/docs/examples/.ipynb_checkpoints/connection_example-checkpoint.ipynb b/docs/examples/.ipynb_checkpoints/connection_example-checkpoint.ipynb new file mode 100644 index 0000000000..04de8fe1c5 --- /dev/null +++ b/docs/examples/.ipynb_checkpoints/connection_example-checkpoint.ipynb @@ -0,0 +1,180 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Connect to redis running locally with default parameters " + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n" + ] + } + ], + "source": [ + "import redis\n", + "r = redis.Redis()\n", + "print(r.ping())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Overwrite default parameters - connect to redis on specific host and port using username and password" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n" + ] + } + ], + "source": [ + "import redis\n", + "r = redis.Redis(host='localhost', port=6380, username='dvora', password='redis')\n", + "print(r.ping())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Create a SSL wrapped TCP socket connection" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n" + ] + } + ], + "source": [ + "import redis\n", + "r = redis.Redis(host='localhost', port=6666, ssl=True, ssl_cert_reqs=\"none\")\n", + "print(r.ping())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Add more parameters..." + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n" + ] + } + ], + "source": [ + "import os\n", + "import redis\n", + "\n", + "ROOT = os.path.join(os.getcwd(), \"..\")\n", + "CERT_DIR = os.path.abspath(os.path.join(ROOT, \"docker\", \"stunnel\", \"keys\"))\n", + "\n", + "r = redis.Redis(\n", + " host=\"localhost\",\n", + " port=6666,\n", + " ssl=True,\n", + " ssl_certfile=os.path.join(CERT_DIR, \"server-cert.pem\"),\n", + " ssl_keyfile=os.path.join(CERT_DIR, \"server-key.pem\"),\n", + " ssl_cert_reqs=\"required\",\n", + " ssl_ca_certs=os.path.join(CERT_DIR, \"server-cert.pem\"),\n", + ")\n", + "print(r.ping())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Connect to redis client object configured from given URL\n", + "##### Three URL schemes are supported:\n", + "\n", + "##### - `redis://` creates a TCP socket connection. See more at:\n", + "##### \n", + "##### - `rediss://` creates a SSL wrapped TCP socket connection. See more at:\n", + "##### \n", + "##### - ``unix://``: creates a Unix Domain Socket connection.\n", + "\n", + "##### Parameters are passed through querystring" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n" + ] + } + ], + "source": [ + "import redis\n", + "r = redis.from_url(\"rediss://localhost:6666?ssl_cert_reqs=none\")\n", + "print(r.ping())" + ] + } + ], + "metadata": { + "interpreter": { + "hash": "d45c99ba0feda92868abafa8257cbb4709c97f1a0b5dc62bbeebdf89d4fad7fe" + }, + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.9" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/examples/README.md b/docs/examples/README.md similarity index 100% rename from examples/README.md rename to docs/examples/README.md diff --git a/examples/connection_example.ipynb b/docs/examples/connection_example.ipynb similarity index 77% rename from examples/connection_example.ipynb rename to docs/examples/connection_example.ipynb index dbccb6c328..b19edb3a7c 100644 --- a/examples/connection_example.ipynb +++ b/docs/examples/connection_example.ipynb @@ -4,7 +4,14 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Connecting to a default Redis instance, running locally." + "# Connection Examples" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Connecting to a default Redis instance, running locally." ] }, { @@ -30,7 +37,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Connecting to a redis instance, specifying a host and port with credentials." + "## Connecting to a redis instance, specifying a host and port with credentials." ] }, { @@ -56,7 +63,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Connecting to a Redis instance via SSL." + "## Connecting to a Redis instance via SSL." ] }, { @@ -82,7 +89,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Connecting to a Redis instance via SSL, while specifying a self-signed SSL certificate." + "## Connecting to a Redis instance via SSL, while specifying a self-signed SSL certificate." ] }, { @@ -121,13 +128,13 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Connecting to Redis instances by specifying a URL scheme.\n", - "##### Parameters are passed to the following schems, as parameters to the url scheme.\n\n", - "##### Three URL schemes are supported:\n", + "## Connecting to Redis instances by specifying a URL scheme.\n", + "Parameters are passed to the following schems, as parameters to the url scheme.\n\n", + "Three URL schemes are supported:\n", "\n", - "##### - `redis://` creates a TCP socket connection. \n", - "##### - `rediss://` creates a SSL wrapped TCP socket connection. \n", - "##### - ``unix://``: creates a Unix Domain Socket connection.\n" + "- `redis://` creates a TCP socket connection. \n", + "- `rediss://` creates a SSL wrapped TCP socket connection. \n", + "- ``unix://``: creates a Unix Domain Socket connection.\n" ] }, { diff --git a/docs/index.rst b/docs/index.rst index d088708e50..cbf5115cde 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -71,6 +71,7 @@ Module Documentation exceptions lock retry + examples Contributing ************* diff --git a/docs/requirements.txt b/docs/requirements.txt index 6dc905f6b3..2fe0b41e5f 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,3 +1,7 @@ sphinx<2 docutils<0.18 sphinx-rtd-theme +nbsphinx +sphinx_gallery +sphinx +iphython diff --git a/tasks.py b/tasks.py index 98ed483fb1..0d856bf14a 100644 --- a/tasks.py +++ b/tasks.py @@ -29,6 +29,7 @@ def devenv(c): @task def build_docs(c): """Generates the sphinx documentation.""" + _generate_keys() run("tox -e docs") diff --git a/tox.ini b/tox.ini index f36e9b36c9..d9ffad81bf 100644 --- a/tox.ini +++ b/tox.ini @@ -158,7 +158,7 @@ basepython = pypy3 basepython = pypy3 [testenv:docs] -deps_files = docs/requirements.txt +deps = -r docs/requirements.txt docker = changedir = {toxinidir}/docs allowlist_externals = make From 708d8d917fe99b18b90909d4087f5dbf0fe42572 Mon Sep 17 00:00:00 2001 From: dvora-h Date: Tue, 28 Dec 2021 17:09:32 +0200 Subject: [PATCH 6/6] add more examples --- docs/examples/connection_example.ipynb | 172 +++++++++++++++++-------- docs/requirements.txt | 3 +- 2 files changed, 122 insertions(+), 53 deletions(-) diff --git a/docs/examples/connection_example.ipynb b/docs/examples/connection_example.ipynb index b19edb3a7c..af5193e0d7 100644 --- a/docs/examples/connection_example.ipynb +++ b/docs/examples/connection_example.ipynb @@ -7,6 +7,15 @@ "# Connection Examples" ] }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import redis" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -16,21 +25,51 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "connection = redis.Redis()\n", + "connection.ping()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### by default Redis return binary responses, to decode them use decode_responses=True" + ] + }, + { + "cell_type": "code", + "execution_count": 3, "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "True\n" - ] + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ - "import redis\n", - "r = redis.Redis()\n", - "print(r.ping())" + "decode_connection = redis.Redis(decode_responses=True)\n", + "connection.ping()" ] }, { @@ -42,21 +81,23 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 4, "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "True\n" - ] + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ - "import redis\n", - "r = redis.Redis(host='localhost', port=6380, username='dvora', password='redis')\n", - "print(r.ping())" + "user_connection = redis.Redis(host='localhost', port=6380, username='dvora', password='redis', decode_responses=True)\n", + "user_connection.ping()" ] }, { @@ -68,21 +109,23 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 5, "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "True\n" - ] + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ - "import redis\n", - "r = redis.Redis(host='localhost', port=6666, ssl=True, ssl_cert_reqs=\"none\")\n", - "print(r.ping())" + "ssl_connection = redis.Redis(host='localhost', port=6666, ssl=True, ssl_cert_reqs=\"none\")\n", + "ssl_connection.ping()" ] }, { @@ -94,34 +137,39 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 6, "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "True\n" - ] + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ "import os\n", - "import redis\n", "\n", - "ROOT = os.path.join(os.getcwd(), \"..\")\n", + "ROOT = os.path.join(os.getcwd(), \"..\", \"..\")\n", "CERT_DIR = os.path.abspath(os.path.join(ROOT, \"docker\", \"stunnel\", \"keys\"))\n", + "ssl_certfile=os.path.join(CERT_DIR, \"server-cert.pem\")\n", + "ssl_keyfile=os.path.join(CERT_DIR, \"server-key.pem\")\n", + "ssl_ca_certs=os.path.join(CERT_DIR, \"server-cert.pem\")\n", "\n", - "r = redis.Redis(\n", + "ssl_cert_conn = redis.Redis(\n", " host=\"localhost\",\n", " port=6666,\n", " ssl=True,\n", - " ssl_certfile=os.path.join(CERT_DIR, \"server-cert.pem\"),\n", - " ssl_keyfile=os.path.join(CERT_DIR, \"server-key.pem\"),\n", + " ssl_certfile=ssl_certfile,\n", + " ssl_keyfile=ssl_keyfile,\n", " ssl_cert_reqs=\"required\",\n", - " ssl_ca_certs=os.path.join(CERT_DIR, \"server-cert.pem\"),\n", + " ssl_ca_certs=ssl_ca_certs,\n", ")\n", - "print(r.ping())" + "ssl_cert_conn.ping()" ] }, { @@ -129,7 +177,8 @@ "metadata": {}, "source": [ "## Connecting to Redis instances by specifying a URL scheme.\n", - "Parameters are passed to the following schems, as parameters to the url scheme.\n\n", + "Parameters are passed to the following schems, as parameters to the url scheme.\n", + "\n", "Three URL schemes are supported:\n", "\n", "- `redis://` creates a TCP socket connection. \n", @@ -139,21 +188,42 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 7, "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "True\n" - ] + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ - "import redis\n", - "r = redis.from_url(\"rediss://localhost:6666?ssl_cert_reqs=none\")\n", - "print(r.ping())" + "url_connection = redis.from_url(\"rediss://localhost:6666?ssl_cert_reqs=none&decode_responses=True&health_check_interval=2\")\n", + "\n", + "url_connection.ping()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Connecting to a Sentinel instance" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from redis.sentinel import Sentinel\n", + "sentinel = Sentinel([('localhost', 26379)], socket_timeout=0.1)\n", + "sentinel.discover_master(\"redis-py-test\")" ] } ], @@ -176,7 +246,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.9" + "version": "3.8.12" } }, "nbformat": 4, diff --git a/docs/requirements.txt b/docs/requirements.txt index 2fe0b41e5f..bbb7dc6149 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -3,5 +3,4 @@ docutils<0.18 sphinx-rtd-theme nbsphinx sphinx_gallery -sphinx -iphython +ipython