Skip to content

Commit f0d7921

Browse files
authored
Merge branch 'master' into patch-1
2 parents e433d3d + 6751de2 commit f0d7921

File tree

5 files changed

+138
-100
lines changed

5 files changed

+138
-100
lines changed

.github/wordlist.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ bysource
7474
charset
7575
del
7676
dev
77+
docstring
78+
docstrings
7779
eg
7880
exc
7981
firsttimersonly

CONTRIBUTING.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,19 @@ using `invoke standalone-tests`; similarly, RedisCluster tests can be run by usi
8181
Each run of tests starts and stops the various dockers required. Sometimes
8282
things get stuck, an `invoke clean` can help.
8383

84+
## Documentation
85+
86+
If relevant, update the code documentation, via docstrings, or in `/docs`.
87+
88+
You can check how the documentation looks locally by running `invoke build-docs`
89+
and loading the generated HTML files in a browser.
90+
91+
Historically there is a mix of styles in the docstrings, but the preferred way
92+
of documenting code is by applying the
93+
[Google style](https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html).
94+
Type hints should be added according to PEP484, and should not be repeated in
95+
the docstrings.
96+
8497
### Docker Tips
8598

8699
Following are a few tips that can help you work with the Docker-based

docs/conf.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# All configuration values have a default; values that are commented out
1111
# serve to show the default.
1212

13+
import datetime
1314
import os
1415
import sys
1516

@@ -30,19 +31,23 @@
3031
"nbsphinx",
3132
"sphinx_gallery.load_style",
3233
"sphinx.ext.autodoc",
33-
"sphinx_autodoc_typehints",
34-
"sphinx.ext.doctest",
3534
"sphinx.ext.viewcode",
3635
"sphinx.ext.autosectionlabel",
36+
"sphinx.ext.napoleon",
3737
]
3838

39+
# Napoleon settings. We only accept Google-style docstrings.
40+
napoleon_google_docstring = True
41+
napoleon_numpy_docstring = False
42+
3943
# AutosectionLabel settings.
4044
# Uses a <page>:<label> schema which doesn't work for duplicate sub-section
4145
# labels, so set max depth.
4246
autosectionlabel_prefix_document = True
4347
autosectionlabel_maxdepth = 2
4448

4549
# AutodocTypehints settings.
50+
autodoc_typehints = 'description'
4651
always_document_param_types = True
4752
typehints_defaults = "comma"
4853

@@ -60,7 +65,8 @@
6065

6166
# General information about the project.
6267
project = "redis-py"
63-
copyright = "2023, Redis Inc"
68+
current_year = datetime.datetime.now().year
69+
copyright = f"{current_year}, Redis Inc"
6470

6571
# The version info for the project you're documenting, acts as replacement for
6672
# |version| and |release|, also used in various other places throughout the

docs/examples/redis-stream-example.ipynb

Lines changed: 65 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
"name": "stdout",
109109
"output_type": "stream",
110110
"text": [
111-
"[[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"
111+
"[[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"
112112
]
113113
}
114114
],
@@ -135,8 +135,8 @@
135135
"output_type": "stream",
136136
"text": [
137137
"got data from stream: b'skey'\n",
138-
"id: b'1657571033115-0' value: b'0'\n",
139-
"id: b'1657571033117-0' value: b'1'\n"
138+
"id: b'1710790167982-0' value: b'0'\n",
139+
"id: b'1710790167983-0' value: b'1'\n"
140140
]
141141
}
142142
],
@@ -165,8 +165,8 @@
165165
"name": "stdout",
166166
"output_type": "stream",
167167
"text": [
168-
"id: b'1657571033115-0' value: b'0'\n",
169-
"id: b'1657571033117-0' value: b'1'\n"
168+
"id: b'1710790167982-0' value: b'0'\n",
169+
"id: b'1710790167983-0' value: b'1'\n"
170170
]
171171
}
172172
],
@@ -192,8 +192,8 @@
192192
"name": "stdout",
193193
"output_type": "stream",
194194
"text": [
195-
"id: b'1657571033118-0' value: b'2'\n",
196-
"id: b'1657571033119-0' value: b'3'\n"
195+
"id: b'1710790167983-1' value: b'2'\n",
196+
"id: b'1710790167983-2' value: b'3'\n"
197197
]
198198
}
199199
],
@@ -213,8 +213,8 @@
213213
"name": "stdout",
214214
"output_type": "stream",
215215
"text": [
216-
"id: b'1657571033119-1' value: b'4'\n",
217-
"id: b'1657571033121-0' value: b'5'\n"
216+
"id: b'1710790167983-3' value: b'4'\n",
217+
"id: b'1710790167983-4' value: b'5'\n"
218218
]
219219
}
220220
],
@@ -255,6 +255,34 @@
255255
"print( f\"stream length: {r.xlen( stream_key )}\")"
256256
]
257257
},
258+
{
259+
"cell_type": "markdown",
260+
"source": [
261+
"to get the last entry in the stream"
262+
],
263+
"metadata": {}
264+
},
265+
{
266+
"cell_type": "code",
267+
"execution_count": 1,
268+
"metadata": {},
269+
"outputs": [
270+
{
271+
"name": "stdout",
272+
"output_type": "stream",
273+
"text": [
274+
"[[b'skey', [(b'1710790167984-0', {b'ts': b'1710790167.9839962', b'v': b'9'})]]]\n",
275+
"stream length: 10\n"
276+
]
277+
}
278+
],
279+
"source": [
280+
"# read the last available message\n",
281+
"l = r.xread( count=1, streams={stream_key: '+'} )\n",
282+
"print(l)\n",
283+
"print( f\"stream length: {r.xlen( stream_key )}\")"
284+
]
285+
},
258286
{
259287
"cell_type": "markdown",
260288
"metadata": {},
@@ -298,8 +326,8 @@
298326
"name": "stdout",
299327
"output_type": "stream",
300328
"text": [
301-
"got from b'skey' the entry [(b'1657571033115-0', {b'ts': b'1657571033.1128936', b'v': b'0'})]\n",
302-
"got from b's2key' the entry [(b'1657571042111-0', {b'v': b'1000'})]\n"
329+
"got from b'skey' the entry [(b'1710790167982-0', {b'ts': b'1710790167.9824948', b'v': b'0'})]\n",
330+
"got from b's2key' the entry [(b'1710790173142-0', {b'v': b'1000'})]\n"
303331
]
304332
}
305333
],
@@ -425,8 +453,8 @@
425453
"name": "stdout",
426454
"output_type": "stream",
427455
"text": [
428-
"got element b'1657571033115-0'from stream b'skey'\n",
429-
"got element b'1657571033117-0'from stream b'skey'\n"
456+
"got element b'1710790167982-0'from stream b'skey'\n",
457+
"got element b'1710790167983-0'from stream b'skey'\n"
430458
]
431459
}
432460
],
@@ -453,8 +481,8 @@
453481
"name": "stdout",
454482
"output_type": "stream",
455483
"text": [
456-
"got element b'1657571033118-0'from stream b'skey'\n",
457-
"got element b'1657571033119-0'from stream b'skey'\n"
484+
"got element b'1710790167983-1'from stream b'skey'\n",
485+
"got element b'1710790167983-2'from stream b'skey'\n"
458486
]
459487
}
460488
],
@@ -484,10 +512,10 @@
484512
"name": "stdout",
485513
"output_type": "stream",
486514
"text": [
487-
"got element b'1657571033115-0'from stream b'skey'\n",
488-
"got element b'1657571033117-0'from stream b'skey'\n",
489-
"got element b'1657571042111-0'from stream b's2key'\n",
490-
"got element b'1657571042113-0'from stream b's2key'\n"
515+
"got element b'1710790167982-0'from stream b'skey'\n",
516+
"got element b'1710790167983-0'from stream b'skey'\n",
517+
"got element b'1710790173142-0'from stream b's2key'\n",
518+
"got element b'1710790173143-0'from stream b's2key'\n"
491519
]
492520
}
493521
],
@@ -546,8 +574,8 @@
546574
"name": "stdout",
547575
"output_type": "stream",
548576
"text": [
549-
"got element b'1657571033118-0'from stream b'skey'\n",
550-
"got element b'1657571033119-0'from stream b'skey'\n"
577+
"got element b'1710790167983-1'from stream b'skey'\n",
578+
"got element b'1710790167983-2'from stream b'skey'\n"
551579
]
552580
}
553581
],
@@ -593,22 +621,22 @@
593621
"name": "stdout",
594622
"output_type": "stream",
595623
"text": [
596-
"got element b'1657571033119-1'from stream b'skey'\n",
597-
"got element b'1657571033121-0'from stream b'skey'\n",
598-
"got element b'1657571033121-1'from stream b'skey'\n",
599-
"got element b'1657571033121-2'from stream b'skey'\n",
600-
"got element b'1657571033122-0'from stream b'skey'\n",
601-
"got element b'1657571033122-1'from stream b'skey'\n",
602-
"got element b'1657571049557-0'from stream b'skey'\n",
603-
"got element b'1657571049557-1'from stream b'skey'\n",
604-
"got element b'1657571049558-0'from stream b'skey'\n",
605-
"got element b'1657571049559-0'from stream b'skey'\n",
606-
"got element b'1657571049559-1'from stream b'skey'\n",
607-
"got element b'1657571049559-2'from stream b'skey'\n",
608-
"got element b'1657571049560-0'from stream b'skey'\n",
609-
"got element b'1657571049562-0'from stream b'skey'\n",
610-
"got element b'1657571049563-0'from stream b'skey'\n",
611-
"got element b'1657571049563-1'from stream b'skey'\n",
624+
"got element b'1710790167983-3'from stream b'skey'\n",
625+
"got element b'1710790167983-4'from stream b'skey'\n",
626+
"got element b'1710790167983-5'from stream b'skey'\n",
627+
"got element b'1710790167983-6'from stream b'skey'\n",
628+
"got element b'1710790167983-7'from stream b'skey'\n",
629+
"got element b'1710790167984-0'from stream b'skey'\n",
630+
"got element b'1710790173157-0'from stream b'skey'\n",
631+
"got element b'1710790173158-0'from stream b'skey'\n",
632+
"got element b'1710790173158-1'from stream b'skey'\n",
633+
"got element b'1710790173158-2'from stream b'skey'\n",
634+
"got element b'1710790173158-3'from stream b'skey'\n",
635+
"got element b'1710790173158-4'from stream b'skey'\n",
636+
"got element b'1710790173158-5'from stream b'skey'\n",
637+
"got element b'1710790173159-0'from stream b'skey'\n",
638+
"got element b'1710790173159-1'from stream b'skey'\n",
639+
"got element b'1710790173159-2'from stream b'skey'\n",
612640
"2 pending messages on 'skey' for group 'grp1'\n"
613641
]
614642
}

redis/commands/core.py

Lines changed: 49 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -199,69 +199,58 @@ def acl_setuser(
199199
"""
200200
Create or update an ACL user.
201201
202-
Create or update the ACL for ``username``. If the user already exists,
202+
Create or update the ACL for `username`. If the user already exists,
203203
the existing ACL is completely overwritten and replaced with the
204204
specified values.
205205
206-
``enabled`` is a boolean indicating whether the user should be allowed
207-
to authenticate or not. Defaults to ``False``.
208-
209-
``nopass`` is a boolean indicating whether the can authenticate without
210-
a password. This cannot be True if ``passwords`` are also specified.
211-
212-
``passwords`` if specified is a list of plain text passwords
213-
to add to or remove from the user. Each password must be prefixed with
214-
a '+' to add or a '-' to remove. For convenience, the value of
215-
``passwords`` can be a simple prefixed string when adding or
216-
removing a single password.
217-
218-
``hashed_passwords`` if specified is a list of SHA-256 hashed passwords
219-
to add to or remove from the user. Each hashed password must be
220-
prefixed with a '+' to add or a '-' to remove. For convenience,
221-
the value of ``hashed_passwords`` can be a simple prefixed string when
222-
adding or removing a single password.
223-
224-
``categories`` if specified is a list of strings representing category
225-
permissions. Each string must be prefixed with either a '+' to add the
226-
category permission or a '-' to remove the category permission.
227-
228-
``commands`` if specified is a list of strings representing command
229-
permissions. Each string must be prefixed with either a '+' to add the
230-
command permission or a '-' to remove the command permission.
231-
232-
``keys`` if specified is a list of key patterns to grant the user
233-
access to. Keys patterns allow '*' to support wildcard matching. For
234-
example, '*' grants access to all keys while 'cache:*' grants access
235-
to all keys that are prefixed with 'cache:'. ``keys`` should not be
236-
prefixed with a '~'.
237-
238-
``reset`` is a boolean indicating whether the user should be fully
239-
reset prior to applying the new ACL. Setting this to True will
240-
remove all existing passwords, flags and privileges from the user and
241-
then apply the specified rules. If this is False, the user's existing
242-
passwords, flags and privileges will be kept and any new specified
243-
rules will be applied on top.
244-
245-
``reset_keys`` is a boolean indicating whether the user's key
246-
permissions should be reset prior to applying any new key permissions
247-
specified in ``keys``. If this is False, the user's existing
248-
key permissions will be kept and any new specified key permissions
249-
will be applied on top.
250-
251-
``reset_channels`` is a boolean indicating whether the user's channel
252-
permissions should be reset prior to applying any new channel permissions
253-
specified in ``channels``.If this is False, the user's existing
254-
channel permissions will be kept and any new specified channel permissions
255-
will be applied on top.
256-
257-
``reset_passwords`` is a boolean indicating whether to remove all
258-
existing passwords and the 'nopass' flag from the user prior to
259-
applying any new passwords specified in 'passwords' or
260-
'hashed_passwords'. If this is False, the user's existing passwords
261-
and 'nopass' status will be kept and any new specified passwords
262-
or hashed_passwords will be applied on top.
263-
264-
For more information see https://redis.io/commands/acl-setuser
206+
For more information, see https://redis.io/commands/acl-setuser
207+
208+
Args:
209+
username: The name of the user whose ACL is to be created or updated.
210+
enabled: Indicates whether the user should be allowed to authenticate.
211+
Defaults to `False`.
212+
nopass: Indicates whether the user can authenticate without a password.
213+
This cannot be `True` if `passwords` are also specified.
214+
passwords: A list of plain text passwords to add to or remove from the user.
215+
Each password must be prefixed with a '+' to add or a '-' to
216+
remove. For convenience, a single prefixed string can be used
217+
when adding or removing a single password.
218+
hashed_passwords: A list of SHA-256 hashed passwords to add to or remove
219+
from the user. Each hashed password must be prefixed with
220+
a '+' to add or a '-' to remove. For convenience, a single
221+
prefixed string can be used when adding or removing a
222+
single password.
223+
categories: A list of strings representing category permissions. Each string
224+
must be prefixed with either a '+' to add the category
225+
permission or a '-' to remove the category permission.
226+
commands: A list of strings representing command permissions. Each string
227+
must be prefixed with either a '+' to add the command permission
228+
or a '-' to remove the command permission.
229+
keys: A list of key patterns to grant the user access to. Key patterns allow
230+
'*' to support wildcard matching. For example, '*' grants access to
231+
all keys while 'cache:*' grants access to all keys that are prefixed
232+
with 'cache:'. `keys` should not be prefixed with a '~'.
233+
reset: Indicates whether the user should be fully reset prior to applying
234+
the new ACL. Setting this to `True` will remove all existing
235+
passwords, flags, and privileges from the user and then apply the
236+
specified rules. If `False`, the user's existing passwords, flags,
237+
and privileges will be kept and any new specified rules will be
238+
applied on top.
239+
reset_keys: Indicates whether the user's key permissions should be reset
240+
prior to applying any new key permissions specified in `keys`.
241+
If `False`, the user's existing key permissions will be kept and
242+
any new specified key permissions will be applied on top.
243+
reset_channels: Indicates whether the user's channel permissions should be
244+
reset prior to applying any new channel permissions
245+
specified in `channels`. If `False`, the user's existing
246+
channel permissions will be kept and any new specified
247+
channel permissions will be applied on top.
248+
reset_passwords: Indicates whether to remove all existing passwords and the
249+
`nopass` flag from the user prior to applying any new
250+
passwords specified in `passwords` or `hashed_passwords`.
251+
If `False`, the user's existing passwords and `nopass`
252+
status will be kept and any new specified passwords or
253+
hashed passwords will be applied on top.
265254
"""
266255
encoder = self.get_encoder()
267256
pieces: List[EncodableT] = [username]

0 commit comments

Comments
 (0)