|
7 | 7 | "# Connection Examples" |
8 | 8 | ] |
9 | 9 | }, |
10 | | - { |
11 | | - "cell_type": "code", |
12 | | - "execution_count": 1, |
13 | | - "metadata": {}, |
14 | | - "outputs": [], |
15 | | - "source": [ |
16 | | - "import redis" |
17 | | - ] |
18 | | - }, |
19 | 10 | { |
20 | 11 | "cell_type": "markdown", |
21 | 12 | "metadata": {}, |
|
40 | 31 | } |
41 | 32 | ], |
42 | 33 | "source": [ |
| 34 | + "import redis\n", |
| 35 | + "\n", |
43 | 36 | "connection = redis.Redis()\n", |
44 | 37 | "connection.ping()" |
45 | 38 | ] |
|
68 | 61 | } |
69 | 62 | ], |
70 | 63 | "source": [ |
71 | | - "decode_connection = redis.Redis(decode_responses=True)\n", |
72 | | - "connection.ping()" |
| 64 | + "import redis\n", |
| 65 | + "\n", |
| 66 | + "decoded_connection = redis.Redis(decode_responses=True)\n", |
| 67 | + "decoded_connection.ping()" |
73 | 68 | ] |
74 | 69 | }, |
75 | 70 | { |
|
96 | 91 | } |
97 | 92 | ], |
98 | 93 | "source": [ |
| 94 | + "import redis\n", |
| 95 | + "\n", |
99 | 96 | "user_connection = redis.Redis(host='localhost', port=6380, username='dvora', password='redis', decode_responses=True)\n", |
100 | 97 | "user_connection.ping()" |
101 | 98 | ] |
102 | 99 | }, |
103 | | - { |
104 | | - "cell_type": "markdown", |
105 | | - "metadata": {}, |
106 | | - "source": [ |
107 | | - "## Connecting to a Redis instance via SSL." |
108 | | - ] |
109 | | - }, |
110 | | - { |
111 | | - "cell_type": "code", |
112 | | - "execution_count": 5, |
113 | | - "metadata": {}, |
114 | | - "outputs": [ |
115 | | - { |
116 | | - "data": { |
117 | | - "text/plain": [ |
118 | | - "True" |
119 | | - ] |
120 | | - }, |
121 | | - "execution_count": 5, |
122 | | - "metadata": {}, |
123 | | - "output_type": "execute_result" |
124 | | - } |
125 | | - ], |
126 | | - "source": [ |
127 | | - "ssl_connection = redis.Redis(host='localhost', port=6666, ssl=True, ssl_cert_reqs=\"none\")\n", |
128 | | - "ssl_connection.ping()" |
129 | | - ] |
130 | | - }, |
131 | | - { |
132 | | - "cell_type": "markdown", |
133 | | - "metadata": {}, |
134 | | - "source": [ |
135 | | - "## Connecting to a Redis instance via SSL, while specifying a self-signed SSL certificate." |
136 | | - ] |
137 | | - }, |
138 | | - { |
139 | | - "cell_type": "code", |
140 | | - "execution_count": 6, |
141 | | - "metadata": {}, |
142 | | - "outputs": [ |
143 | | - { |
144 | | - "data": { |
145 | | - "text/plain": [ |
146 | | - "True" |
147 | | - ] |
148 | | - }, |
149 | | - "execution_count": 6, |
150 | | - "metadata": {}, |
151 | | - "output_type": "execute_result" |
152 | | - } |
153 | | - ], |
154 | | - "source": [ |
155 | | - "import os\n", |
156 | | - "\n", |
157 | | - "ROOT = os.path.join(os.getcwd(), \"..\", \"..\")\n", |
158 | | - "CERT_DIR = os.path.abspath(os.path.join(ROOT, \"docker\", \"stunnel\", \"keys\"))\n", |
159 | | - "ssl_certfile=os.path.join(CERT_DIR, \"server-cert.pem\")\n", |
160 | | - "ssl_keyfile=os.path.join(CERT_DIR, \"server-key.pem\")\n", |
161 | | - "ssl_ca_certs=os.path.join(CERT_DIR, \"server-cert.pem\")\n", |
162 | | - "\n", |
163 | | - "ssl_cert_conn = redis.Redis(\n", |
164 | | - " host=\"localhost\",\n", |
165 | | - " port=6666,\n", |
166 | | - " ssl=True,\n", |
167 | | - " ssl_certfile=ssl_certfile,\n", |
168 | | - " ssl_keyfile=ssl_keyfile,\n", |
169 | | - " ssl_cert_reqs=\"required\",\n", |
170 | | - " ssl_ca_certs=ssl_ca_certs,\n", |
171 | | - ")\n", |
172 | | - "ssl_cert_conn.ping()" |
173 | | - ] |
174 | | - }, |
175 | 100 | { |
176 | 101 | "cell_type": "markdown", |
177 | 102 | "metadata": {}, |
|
203 | 128 | } |
204 | 129 | ], |
205 | 130 | "source": [ |
206 | | - "url_connection = redis.from_url(\"rediss://localhost:6666?ssl_cert_reqs=none&decode_responses=True&health_check_interval=2\")\n", |
| 131 | + "url_connection = redis.from_url(\"redis://localhost:6379?decode_responses=True&health_check_interval=2\")\n", |
207 | 132 | "\n", |
208 | 133 | "url_connection.ping()" |
209 | 134 | ] |
|
0 commit comments