Skip to content

Commit

Permalink
Document XREAD of last message (+) (#3188)
Browse files Browse the repository at this point in the history
XREAD now supports reading the last message in the stream, with the +
special Id. The code already supports this, so just add some
documentation to an existing Jupyter notebook.

Fixes #3155

Co-authored-by: Gabriel Erzse <gabriel.erzse@redis.com>
  • Loading branch information
gerzse and gerzse authored May 15, 2024
1 parent 68d6d53 commit 0b20087
Showing 1 changed file with 65 additions and 37 deletions.
102 changes: 65 additions & 37 deletions docs/examples/redis-stream-example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
],
Expand All @@ -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"
]
}
],
Expand Down Expand Up @@ -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"
]
}
],
Expand All @@ -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"
]
}
],
Expand All @@ -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"
]
}
],
Expand Down Expand Up @@ -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": {},
Expand Down Expand Up @@ -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"
]
}
],
Expand Down Expand Up @@ -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"
]
}
],
Expand All @@ -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"
]
}
],
Expand Down Expand Up @@ -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"
]
}
],
Expand Down Expand Up @@ -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"
]
}
],
Expand Down Expand Up @@ -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"
]
}
Expand Down

0 comments on commit 0b20087

Please sign in to comment.