diff --git a/docs/examples/redis-stream-example.ipynb b/docs/examples/redis-stream-example.ipynb index eb1f2e9a20..60f4ddd3d3 100644 --- a/docs/examples/redis-stream-example.ipynb +++ b/docs/examples/redis-stream-example.ipynb @@ -108,7 +108,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "[[b'skey', [(b'1657571033115-0', {b'ts': b'1657571033.1128936', b'v': b'0'}), (b'1657571033117-0', {b'ts': b'1657571033.1176307', b'v': b'1'})]]]\n" + "[[b'skey', [(b'1710790167982-0', {b'ts': b'1710790167.9824948', b'v': b'0'}), (b'1710790167983-0', {b'ts': b'1710790167.9830241', b'v': b'1'})]]]\n" ] } ], @@ -135,8 +135,8 @@ "output_type": "stream", "text": [ "got data from stream: b'skey'\n", - "id: b'1657571033115-0' value: b'0'\n", - "id: b'1657571033117-0' value: b'1'\n" + "id: b'1710790167982-0' value: b'0'\n", + "id: b'1710790167983-0' value: b'1'\n" ] } ], @@ -165,8 +165,8 @@ "name": "stdout", "output_type": "stream", "text": [ - "id: b'1657571033115-0' value: b'0'\n", - "id: b'1657571033117-0' value: b'1'\n" + "id: b'1710790167982-0' value: b'0'\n", + "id: b'1710790167983-0' value: b'1'\n" ] } ], @@ -192,8 +192,8 @@ "name": "stdout", "output_type": "stream", "text": [ - "id: b'1657571033118-0' value: b'2'\n", - "id: b'1657571033119-0' value: b'3'\n" + "id: b'1710790167983-1' value: b'2'\n", + "id: b'1710790167983-2' value: b'3'\n" ] } ], @@ -213,8 +213,8 @@ "name": "stdout", "output_type": "stream", "text": [ - "id: b'1657571033119-1' value: b'4'\n", - "id: b'1657571033121-0' value: b'5'\n" + "id: b'1710790167983-3' value: b'4'\n", + "id: b'1710790167983-4' value: b'5'\n" ] } ], @@ -255,6 +255,34 @@ "print( f\"stream length: {r.xlen( stream_key )}\")" ] }, + { + "cell_type": "markdown", + "source": [ + "to get the last entry in the stream" + ], + "metadata": {} + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[b'skey', [(b'1710790167984-0', {b'ts': b'1710790167.9839962', b'v': b'9'})]]]\n", + "stream length: 10\n" + ] + } + ], + "source": [ + "# read the last available message\n", + "l = r.xread( count=1, streams={stream_key: '+'} )\n", + "print(l)\n", + "print( f\"stream length: {r.xlen( stream_key )}\")" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -298,8 +326,8 @@ "name": "stdout", "output_type": "stream", "text": [ - "got from b'skey' the entry [(b'1657571033115-0', {b'ts': b'1657571033.1128936', b'v': b'0'})]\n", - "got from b's2key' the entry [(b'1657571042111-0', {b'v': b'1000'})]\n" + "got from b'skey' the entry [(b'1710790167982-0', {b'ts': b'1710790167.9824948', b'v': b'0'})]\n", + "got from b's2key' the entry [(b'1710790173142-0', {b'v': b'1000'})]\n" ] } ], @@ -425,8 +453,8 @@ "name": "stdout", "output_type": "stream", "text": [ - "got element b'1657571033115-0'from stream b'skey'\n", - "got element b'1657571033117-0'from stream b'skey'\n" + "got element b'1710790167982-0'from stream b'skey'\n", + "got element b'1710790167983-0'from stream b'skey'\n" ] } ], @@ -453,8 +481,8 @@ "name": "stdout", "output_type": "stream", "text": [ - "got element b'1657571033118-0'from stream b'skey'\n", - "got element b'1657571033119-0'from stream b'skey'\n" + "got element b'1710790167983-1'from stream b'skey'\n", + "got element b'1710790167983-2'from stream b'skey'\n" ] } ], @@ -484,10 +512,10 @@ "name": "stdout", "output_type": "stream", "text": [ - "got element b'1657571033115-0'from stream b'skey'\n", - "got element b'1657571033117-0'from stream b'skey'\n", - "got element b'1657571042111-0'from stream b's2key'\n", - "got element b'1657571042113-0'from stream b's2key'\n" + "got element b'1710790167982-0'from stream b'skey'\n", + "got element b'1710790167983-0'from stream b'skey'\n", + "got element b'1710790173142-0'from stream b's2key'\n", + "got element b'1710790173143-0'from stream b's2key'\n" ] } ], @@ -546,8 +574,8 @@ "name": "stdout", "output_type": "stream", "text": [ - "got element b'1657571033118-0'from stream b'skey'\n", - "got element b'1657571033119-0'from stream b'skey'\n" + "got element b'1710790167983-1'from stream b'skey'\n", + "got element b'1710790167983-2'from stream b'skey'\n" ] } ], @@ -593,22 +621,22 @@ "name": "stdout", "output_type": "stream", "text": [ - "got element b'1657571033119-1'from stream b'skey'\n", - "got element b'1657571033121-0'from stream b'skey'\n", - "got element b'1657571033121-1'from stream b'skey'\n", - "got element b'1657571033121-2'from stream b'skey'\n", - "got element b'1657571033122-0'from stream b'skey'\n", - "got element b'1657571033122-1'from stream b'skey'\n", - "got element b'1657571049557-0'from stream b'skey'\n", - "got element b'1657571049557-1'from stream b'skey'\n", - "got element b'1657571049558-0'from stream b'skey'\n", - "got element b'1657571049559-0'from stream b'skey'\n", - "got element b'1657571049559-1'from stream b'skey'\n", - "got element b'1657571049559-2'from stream b'skey'\n", - "got element b'1657571049560-0'from stream b'skey'\n", - "got element b'1657571049562-0'from stream b'skey'\n", - "got element b'1657571049563-0'from stream b'skey'\n", - "got element b'1657571049563-1'from stream b'skey'\n", + "got element b'1710790167983-3'from stream b'skey'\n", + "got element b'1710790167983-4'from stream b'skey'\n", + "got element b'1710790167983-5'from stream b'skey'\n", + "got element b'1710790167983-6'from stream b'skey'\n", + "got element b'1710790167983-7'from stream b'skey'\n", + "got element b'1710790167984-0'from stream b'skey'\n", + "got element b'1710790173157-0'from stream b'skey'\n", + "got element b'1710790173158-0'from stream b'skey'\n", + "got element b'1710790173158-1'from stream b'skey'\n", + "got element b'1710790173158-2'from stream b'skey'\n", + "got element b'1710790173158-3'from stream b'skey'\n", + "got element b'1710790173158-4'from stream b'skey'\n", + "got element b'1710790173158-5'from stream b'skey'\n", + "got element b'1710790173159-0'from stream b'skey'\n", + "got element b'1710790173159-1'from stream b'skey'\n", + "got element b'1710790173159-2'from stream b'skey'\n", "2 pending messages on 'skey' for group 'grp1'\n" ] }