|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "id": "8a7b6b37", |
| 6 | + "metadata": {}, |
| 7 | + "source": [ |
| 8 | + "<center>\n", |
| 9 | + " <h1 style=\"color:blue\">DataBase Connections - Redis</h1>\n", |
| 10 | + "</center>\n", |
| 11 | + "\n", |
| 12 | + "<p>Tasks:</p>\n", |
| 13 | + "\n", |
| 14 | + "* Connection\n", |
| 15 | + "* Insert\n", |
| 16 | + "* Update\n", |
| 17 | + "* Select\n", |
| 18 | + "* Return\n", |
| 19 | + "* Delete\n", |
| 20 | + "* Close Connection\n", |
| 21 | + "\n", |
| 22 | + "<br>\n", |
| 23 | + "\n", |
| 24 | + "> pip install redis" |
| 25 | + ] |
| 26 | + }, |
| 27 | + { |
| 28 | + "cell_type": "code", |
| 29 | + "execution_count": 1, |
| 30 | + "id": "7282cafe", |
| 31 | + "metadata": {}, |
| 32 | + "outputs": [], |
| 33 | + "source": [ |
| 34 | + "import redis" |
| 35 | + ] |
| 36 | + }, |
| 37 | + { |
| 38 | + "cell_type": "code", |
| 39 | + "execution_count": 2, |
| 40 | + "id": "fe0a3fb4", |
| 41 | + "metadata": {}, |
| 42 | + "outputs": [ |
| 43 | + { |
| 44 | + "data": { |
| 45 | + "text/plain": [ |
| 46 | + "'4.3.1'" |
| 47 | + ] |
| 48 | + }, |
| 49 | + "execution_count": 2, |
| 50 | + "metadata": {}, |
| 51 | + "output_type": "execute_result" |
| 52 | + } |
| 53 | + ], |
| 54 | + "source": [ |
| 55 | + "redis.__version__" |
| 56 | + ] |
| 57 | + }, |
| 58 | + { |
| 59 | + "cell_type": "markdown", |
| 60 | + "id": "04330ae9", |
| 61 | + "metadata": {}, |
| 62 | + "source": [ |
| 63 | + "<h2 style=\"color:blue\">0 - Connection</h2>" |
| 64 | + ] |
| 65 | + }, |
| 66 | + { |
| 67 | + "cell_type": "code", |
| 68 | + "execution_count": 7, |
| 69 | + "id": "24173f59", |
| 70 | + "metadata": {}, |
| 71 | + "outputs": [], |
| 72 | + "source": [ |
| 73 | + "default_host = 'localhost'\n", |
| 74 | + "default_port = 6379\n", |
| 75 | + "#default_password =\n", |
| 76 | + "\n", |
| 77 | + "r = redis.Redis(\n", |
| 78 | + " host = default_host,\n", |
| 79 | + " port = default_port\n", |
| 80 | + ")" |
| 81 | + ] |
| 82 | + }, |
| 83 | + { |
| 84 | + "cell_type": "markdown", |
| 85 | + "id": "b3905553", |
| 86 | + "metadata": {}, |
| 87 | + "source": [ |
| 88 | + "----\n", |
| 89 | + "\n", |
| 90 | + "<h2 style=\"color:blue\">1 - Insert, Update, Select, Return and Delete</h2>" |
| 91 | + ] |
| 92 | + }, |
| 93 | + { |
| 94 | + "cell_type": "code", |
| 95 | + "execution_count": 10, |
| 96 | + "id": "48359734", |
| 97 | + "metadata": {}, |
| 98 | + "outputs": [], |
| 99 | + "source": [ |
| 100 | + "storaged_value = None" |
| 101 | + ] |
| 102 | + }, |
| 103 | + { |
| 104 | + "cell_type": "code", |
| 105 | + "execution_count": 15, |
| 106 | + "id": "57307cb0", |
| 107 | + "metadata": {}, |
| 108 | + "outputs": [ |
| 109 | + { |
| 110 | + "name": "stdout", |
| 111 | + "output_type": "stream", |
| 112 | + "text": [ |
| 113 | + "b\"Hey there, I'm using Redis\"\n" |
| 114 | + ] |
| 115 | + } |
| 116 | + ], |
| 117 | + "source": [ |
| 118 | + "# Set a single phrase and return it\n", |
| 119 | + "\n", |
| 120 | + "r.set('Phrase', 'Hey there, I\\'m using Redis')\n", |
| 121 | + "storaged_value = r.get('Phrase')\n", |
| 122 | + "\n", |
| 123 | + "print(storaged_value)" |
| 124 | + ] |
| 125 | + }, |
| 126 | + { |
| 127 | + "cell_type": "code", |
| 128 | + "execution_count": 16, |
| 129 | + "id": "1e590e66", |
| 130 | + "metadata": {}, |
| 131 | + "outputs": [ |
| 132 | + { |
| 133 | + "name": "stdout", |
| 134 | + "output_type": "stream", |
| 135 | + "text": [ |
| 136 | + "b\"What's up, I'm using Redis\"\n" |
| 137 | + ] |
| 138 | + } |
| 139 | + ], |
| 140 | + "source": [ |
| 141 | + "# Updating the Variable\n", |
| 142 | + "\n", |
| 143 | + "r.set('Phrase', 'What\\'s up, I\\'m using Redis')\n", |
| 144 | + "storaged_value = r.get('Phrase')\n", |
| 145 | + "\n", |
| 146 | + "print(storaged_value)" |
| 147 | + ] |
| 148 | + }, |
| 149 | + { |
| 150 | + "cell_type": "code", |
| 151 | + "execution_count": 17, |
| 152 | + "id": "90beafb7", |
| 153 | + "metadata": {}, |
| 154 | + "outputs": [ |
| 155 | + { |
| 156 | + "name": "stdout", |
| 157 | + "output_type": "stream", |
| 158 | + "text": [ |
| 159 | + "None\n" |
| 160 | + ] |
| 161 | + } |
| 162 | + ], |
| 163 | + "source": [ |
| 164 | + "# Deleting the Variable\n", |
| 165 | + "\n", |
| 166 | + "r.delete('Phrase')\n", |
| 167 | + "storaged_value = r.get('Phrase')\n", |
| 168 | + "\n", |
| 169 | + "print(storaged_value)" |
| 170 | + ] |
| 171 | + }, |
| 172 | + { |
| 173 | + "cell_type": "markdown", |
| 174 | + "id": "78780dd3", |
| 175 | + "metadata": {}, |
| 176 | + "source": [ |
| 177 | + "----\n", |
| 178 | + "\n", |
| 179 | + "<h2 style=\"color:blue\">2 - Closing the Connection</h2>" |
| 180 | + ] |
| 181 | + }, |
| 182 | + { |
| 183 | + "cell_type": "markdown", |
| 184 | + "id": "65a8a9ec", |
| 185 | + "metadata": {}, |
| 186 | + "source": [ |
| 187 | + "<p>As far Redis uses <b>Connection Pool</b> (<i>the connectioon is saved in the memory and can be used again over the computer execution</i>) type, yoou don't have to oworry about closing the connectioon. Redis can close it automatically when you shut doown the computer or stop the Redis Service.</p>" |
| 188 | + ] |
| 189 | + }, |
| 190 | + { |
| 191 | + "cell_type": "markdown", |
| 192 | + "id": "5308e0af", |
| 193 | + "metadata": {}, |
| 194 | + "source": [ |
| 195 | + "----" |
| 196 | + ] |
| 197 | + }, |
| 198 | + { |
| 199 | + "cell_type": "markdown", |
| 200 | + "id": "5e55df25", |
| 201 | + "metadata": {}, |
| 202 | + "source": [ |
| 203 | + "<center>\n", |
| 204 | + " <img src='thats all.jpg'>\n", |
| 205 | + "</center>" |
| 206 | + ] |
| 207 | + }, |
| 208 | + { |
| 209 | + "cell_type": "code", |
| 210 | + "execution_count": null, |
| 211 | + "id": "e5c5707a", |
| 212 | + "metadata": {}, |
| 213 | + "outputs": [], |
| 214 | + "source": [] |
| 215 | + } |
| 216 | + ], |
| 217 | + "metadata": { |
| 218 | + "kernelspec": { |
| 219 | + "display_name": "Python 3", |
| 220 | + "language": "python", |
| 221 | + "name": "python3" |
| 222 | + }, |
| 223 | + "language_info": { |
| 224 | + "codemirror_mode": { |
| 225 | + "name": "ipython", |
| 226 | + "version": 3 |
| 227 | + }, |
| 228 | + "file_extension": ".py", |
| 229 | + "mimetype": "text/x-python", |
| 230 | + "name": "python", |
| 231 | + "nbconvert_exporter": "python", |
| 232 | + "pygments_lexer": "ipython3", |
| 233 | + "version": "3.8.8" |
| 234 | + } |
| 235 | + }, |
| 236 | + "nbformat": 4, |
| 237 | + "nbformat_minor": 5 |
| 238 | +} |
0 commit comments