summaryrefslogtreecommitdiff
path: root/docs/examples/asyncio_examples.ipynb
diff options
context:
space:
mode:
Diffstat (limited to 'docs/examples/asyncio_examples.ipynb')
-rw-r--r--docs/examples/asyncio_examples.ipynb129
1 files changed, 76 insertions, 53 deletions
diff --git a/docs/examples/asyncio_examples.ipynb b/docs/examples/asyncio_examples.ipynb
index dab7a96..855255c 100644
--- a/docs/examples/asyncio_examples.ipynb
+++ b/docs/examples/asyncio_examples.ipynb
@@ -21,11 +21,6 @@
{
"cell_type": "code",
"execution_count": 1,
- "metadata": {
- "pycharm": {
- "name": "#%%\n"
- }
- },
"outputs": [
{
"name": "stdout",
@@ -41,27 +36,29 @@
"connection = redis.Redis()\n",
"print(f\"Ping successful: {await connection.ping()}\")\n",
"await connection.close()"
- ]
+ ],
+ "metadata": {
+ "collapsed": false,
+ "pycharm": {
+ "name": "#%%\n"
+ }
+ }
},
{
"cell_type": "markdown",
+ "source": [
+ "If you supply a custom `ConnectionPool` that is supplied to several `Redis` instances, you may want to disconnect the connection pool explicitly. Disconnecting the connection pool simply disconnects all connections hosted in the pool."
+ ],
"metadata": {
+ "collapsed": false,
"pycharm": {
"name": "#%% md\n"
}
- },
- "source": [
- "If you supply a custom `ConnectionPool` that is supplied to several `Redis` instances, you may want to disconnect the connection pool explicitly. Disconnecting the connection pool simply disconnects all connections hosted in the pool."
- ]
+ }
},
{
"cell_type": "code",
"execution_count": 2,
- "metadata": {
- "pycharm": {
- "name": "#%%\n"
- }
- },
"outputs": [],
"source": [
"import redis.asyncio as redis\n",
@@ -70,15 +67,16 @@
"await connection.close()\n",
"# Or: await connection.close(close_connection_pool=False)\n",
"await connection.connection_pool.disconnect()"
- ]
- },
- {
- "cell_type": "markdown",
+ ],
"metadata": {
+ "collapsed": false,
"pycharm": {
- "name": "#%% md\n"
+ "name": "#%%\n"
}
- },
+ }
+ },
+ {
+ "cell_type": "markdown",
"source": [
"## Transactions (Multi/Exec)\n",
"\n",
@@ -87,16 +85,17 @@
"The commands will not be reflected in Redis until execute() is called & awaited.\n",
"\n",
"Usually, when performing a bulk operation, taking advantage of a “transaction” (e.g., Multi/Exec) is to be desired, as it will also add a layer of atomicity to your bulk operation."
- ]
+ ],
+ "metadata": {
+ "collapsed": false,
+ "pycharm": {
+ "name": "#%% md\n"
+ }
+ }
},
{
"cell_type": "code",
"execution_count": 3,
- "metadata": {
- "pycharm": {
- "name": "#%%\n"
- }
- },
"outputs": [],
"source": [
"import redis.asyncio as redis\n",
@@ -106,25 +105,31 @@
" ok1, ok2 = await (pipe.set(\"key1\", \"value1\").set(\"key2\", \"value2\").execute())\n",
"assert ok1\n",
"assert ok2"
- ]
+ ],
+ "metadata": {
+ "collapsed": false,
+ "pycharm": {
+ "name": "#%%\n"
+ }
+ }
},
{
"cell_type": "markdown",
- "metadata": {},
"source": [
"## Pub/Sub Mode\n",
"\n",
"Subscribing to specific channels:"
- ]
+ ],
+ "metadata": {
+ "collapsed": false,
+ "pycharm": {
+ "name": "#%% md\n"
+ }
+ }
},
{
"cell_type": "code",
"execution_count": 4,
- "metadata": {
- "pycharm": {
- "name": "#%%\n"
- }
- },
"outputs": [
{
"name": "stdout",
@@ -165,23 +170,29 @@
" await r.publish(\"channel:1\", STOPWORD)\n",
"\n",
" await future"
- ]
+ ],
+ "metadata": {
+ "collapsed": false,
+ "pycharm": {
+ "name": "#%%\n"
+ }
+ }
},
{
"cell_type": "markdown",
- "metadata": {},
"source": [
"Subscribing to channels matching a glob-style pattern:"
- ]
+ ],
+ "metadata": {
+ "collapsed": false,
+ "pycharm": {
+ "name": "#%% md\n"
+ }
+ }
},
{
"cell_type": "code",
"execution_count": 5,
- "metadata": {
- "pycharm": {
- "name": "#%%\n"
- }
- },
"outputs": [
{
"name": "stdout",
@@ -223,11 +234,16 @@
" await r.publish(\"channel:1\", STOPWORD)\n",
"\n",
" await future"
- ]
+ ],
+ "metadata": {
+ "collapsed": false,
+ "pycharm": {
+ "name": "#%%\n"
+ }
+ }
},
{
"cell_type": "markdown",
- "metadata": {},
"source": [
"## Sentinel Client\n",
"\n",
@@ -236,16 +252,17 @@
"Calling aioredis.sentinel.Sentinel.master_for or aioredis.sentinel.Sentinel.slave_for methods will return Redis clients connected to specified services monitored by Sentinel.\n",
"\n",
"Sentinel client will detect failover and reconnect Redis clients automatically."
- ]
+ ],
+ "metadata": {
+ "collapsed": false,
+ "pycharm": {
+ "name": "#%% md\n"
+ }
+ }
},
{
"cell_type": "code",
"execution_count": null,
- "metadata": {
- "pycharm": {
- "name": "#%%\n"
- }
- },
"outputs": [],
"source": [
"import asyncio\n",
@@ -260,7 +277,13 @@
"assert ok\n",
"val = await r.get(\"key\")\n",
"assert val == b\"value\""
- ]
+ ],
+ "metadata": {
+ "collapsed": false,
+ "pycharm": {
+ "name": "#%%\n"
+ }
+ }
}
],
"metadata": {
@@ -284,4 +307,4 @@
},
"nbformat": 4,
"nbformat_minor": 1
-}
+} \ No newline at end of file