Skip to content

Commit deaaa53

Browse files
dvora-hchayim
andauthored
Connection examples (#1835)
Co-authored-by: Chayim I. Kirshen <[email protected]>
1 parent 1b7d5bb commit deaaa53

File tree

9 files changed

+452
-3
lines changed

9 files changed

+452
-3
lines changed

docs/conf.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
# Add any Sphinx extension module names here, as strings. They can be
2828
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
2929
extensions = [
30+
"nbsphinx",
31+
"sphinx_gallery.load_style",
3032
"sphinx.ext.autodoc",
3133
"sphinx.ext.doctest",
3234
"sphinx.ext.viewcode",
@@ -73,7 +75,7 @@
7375

7476
# List of patterns, relative to source directory, that match files and
7577
# directories to ignore when looking for source files.
76-
exclude_patterns = ["_build"]
78+
exclude_patterns = ["_build", "**.ipynb_checkponts"]
7779

7880
# The reST default role (used for this markup: `text`) to use for all
7981
# documents.

docs/examples.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Examples
2+
########
3+
4+
.. toctree::
5+
:maxdepth: 3
6+
:glob:
7+
8+
examples/connection_example
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"### Connect to redis running locally with default parameters "
8+
]
9+
},
10+
{
11+
"cell_type": "code",
12+
"execution_count": 40,
13+
"metadata": {},
14+
"outputs": [
15+
{
16+
"name": "stdout",
17+
"output_type": "stream",
18+
"text": [
19+
"True\n"
20+
]
21+
}
22+
],
23+
"source": [
24+
"import redis\n",
25+
"r = redis.Redis()\n",
26+
"print(r.ping())"
27+
]
28+
},
29+
{
30+
"cell_type": "markdown",
31+
"metadata": {},
32+
"source": [
33+
"### Overwrite default parameters - connect to redis on specific host and port using username and password"
34+
]
35+
},
36+
{
37+
"cell_type": "code",
38+
"execution_count": 39,
39+
"metadata": {},
40+
"outputs": [
41+
{
42+
"name": "stdout",
43+
"output_type": "stream",
44+
"text": [
45+
"True\n"
46+
]
47+
}
48+
],
49+
"source": [
50+
"import redis\n",
51+
"r = redis.Redis(host='localhost', port=6380, username='dvora', password='redis')\n",
52+
"print(r.ping())"
53+
]
54+
},
55+
{
56+
"cell_type": "markdown",
57+
"metadata": {},
58+
"source": [
59+
"### Create a SSL wrapped TCP socket connection"
60+
]
61+
},
62+
{
63+
"cell_type": "code",
64+
"execution_count": 38,
65+
"metadata": {},
66+
"outputs": [
67+
{
68+
"name": "stdout",
69+
"output_type": "stream",
70+
"text": [
71+
"True\n"
72+
]
73+
}
74+
],
75+
"source": [
76+
"import redis\n",
77+
"r = redis.Redis(host='localhost', port=6666, ssl=True, ssl_cert_reqs=\"none\")\n",
78+
"print(r.ping())"
79+
]
80+
},
81+
{
82+
"cell_type": "markdown",
83+
"metadata": {},
84+
"source": [
85+
"### Add more parameters..."
86+
]
87+
},
88+
{
89+
"cell_type": "code",
90+
"execution_count": 37,
91+
"metadata": {},
92+
"outputs": [
93+
{
94+
"name": "stdout",
95+
"output_type": "stream",
96+
"text": [
97+
"True\n"
98+
]
99+
}
100+
],
101+
"source": [
102+
"import os\n",
103+
"import redis\n",
104+
"\n",
105+
"ROOT = os.path.join(os.getcwd(), \"..\")\n",
106+
"CERT_DIR = os.path.abspath(os.path.join(ROOT, \"docker\", \"stunnel\", \"keys\"))\n",
107+
"\n",
108+
"r = redis.Redis(\n",
109+
" host=\"localhost\",\n",
110+
" port=6666,\n",
111+
" ssl=True,\n",
112+
" ssl_certfile=os.path.join(CERT_DIR, \"server-cert.pem\"),\n",
113+
" ssl_keyfile=os.path.join(CERT_DIR, \"server-key.pem\"),\n",
114+
" ssl_cert_reqs=\"required\",\n",
115+
" ssl_ca_certs=os.path.join(CERT_DIR, \"server-cert.pem\"),\n",
116+
")\n",
117+
"print(r.ping())"
118+
]
119+
},
120+
{
121+
"cell_type": "markdown",
122+
"metadata": {},
123+
"source": [
124+
"### Connect to redis client object configured from given URL\n",
125+
"##### Three URL schemes are supported:\n",
126+
"\n",
127+
"##### - `redis://` creates a TCP socket connection. See more at:\n",
128+
"##### <https://www.iana.org/assignments/uri-schemes/prov/redis>\n",
129+
"##### - `rediss://` creates a SSL wrapped TCP socket connection. See more at:\n",
130+
"##### <https://www.iana.org/assignments/uri-schemes/prov/rediss>\n",
131+
"##### - ``unix://``: creates a Unix Domain Socket connection.\n",
132+
"\n",
133+
"##### Parameters are passed through querystring"
134+
]
135+
},
136+
{
137+
"cell_type": "code",
138+
"execution_count": 36,
139+
"metadata": {},
140+
"outputs": [
141+
{
142+
"name": "stdout",
143+
"output_type": "stream",
144+
"text": [
145+
"True\n"
146+
]
147+
}
148+
],
149+
"source": [
150+
"import redis\n",
151+
"r = redis.from_url(\"rediss://localhost:6666?ssl_cert_reqs=none\")\n",
152+
"print(r.ping())"
153+
]
154+
}
155+
],
156+
"metadata": {
157+
"interpreter": {
158+
"hash": "d45c99ba0feda92868abafa8257cbb4709c97f1a0b5dc62bbeebdf89d4fad7fe"
159+
},
160+
"kernelspec": {
161+
"display_name": "Python 3 (ipykernel)",
162+
"language": "python",
163+
"name": "python3"
164+
},
165+
"language_info": {
166+
"codemirror_mode": {
167+
"name": "ipython",
168+
"version": 3
169+
},
170+
"file_extension": ".py",
171+
"mimetype": "text/x-python",
172+
"name": "python",
173+
"nbconvert_exporter": "python",
174+
"pygments_lexer": "ipython3",
175+
"version": "3.9.9"
176+
}
177+
},
178+
"nbformat": 4,
179+
"nbformat_minor": 2
180+
}
File renamed without changes.

0 commit comments

Comments
 (0)