Skip to content

Merge master #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Nov 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/release-drafter-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ autolabeler:
branch:
- '/feature-.+'
categories:
- title: 'Breaking Changes'
- title: '🔥 Breaking Changes'
labels:
- 'breakingchange'
- title: '🚀 New Features'
Expand Down
13 changes: 13 additions & 0 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: 2

python:
install:
- requirements: ./docs/requirements.txt

build:
os: ubuntu-20.04
tools:
python: "3.9"

sphinx:
configuration: docs/conf.py
16 changes: 8 additions & 8 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@

# General information about the project.
project = "redis-py"
copyright = "2016, Andy McCurdy"
copyright = "2021, Redis Inc."

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = "2.10.5"
version = "4.0.9"
# The full version, including alpha/beta/rc tags.
release = "2.10.5"
release = "4.0.0"

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down Expand Up @@ -191,7 +191,7 @@
("index",
"redis-py.tex",
"redis-py Documentation",
"Andy McCurdy",
"Redis Inc",
"manual"),
]

Expand Down Expand Up @@ -240,7 +240,7 @@
"index",
"redis-py",
"redis-py Documentation",
"Andy McCurdy",
"Redis Inc",
"redis-py",
"One line description of project.",
"Miscellaneous",
Expand All @@ -257,6 +257,6 @@
# texinfo_show_urls = 'footnote'

epub_title = "redis-py"
epub_author = "Andy McCurdy"
epub_publisher = "Andy McCurdy"
epub_copyright = "2011, Andy McCurdy"
epub_author = "Redis Inc"
epub_publisher = "Redis Inc"
epub_copyright = "2021, Redis Inc"
16 changes: 16 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,21 @@ Contents:
.. automodule:: redis
:members:

.. automodule:: redis.backoff
:members:

.. automodule:: redis.connection
:members:

.. automodule:: redis.commands
:members:

.. automodule:: redis.exceptions
:members:

.. automodule:: redis.lock
:members:

.. automodule:: redis.sentinel
:members:

190 changes: 0 additions & 190 deletions docs/make.bat

This file was deleted.

2 changes: 2 additions & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sphinx<2
docutils<0.18
41 changes: 20 additions & 21 deletions redis/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,6 @@ class Redis(RedisModuleCommands, CoreCommands, object):
'CLUSTER SET-CONFIG-EPOCH': bool_ok,
'CLUSTER SETSLOT': bool_ok,
'CLUSTER SLAVES': parse_cluster_nodes,
'COMMAND': int,
'COMMAND COUNT': int,
'CONFIG GET': parse_config_get,
'CONFIG RESETSTAT': bool_ok,
Expand Down Expand Up @@ -891,19 +890,25 @@ def __init__(self, host='localhost', port=6379,
self.response_callbacks = CaseInsensitiveDict(
self.__class__.RESPONSE_CALLBACKS)

# preload our class with the available redis commands
try:
self.__redis_commands__()
except RedisError:
pass

def __repr__(self):
return "%s<%s>" % (type(self).__name__, repr(self.connection_pool))

def set_response_callback(self, command, callback):
"Set a custom Response Callback"
self.response_callbacks[command] = callback

def load_external_module(self, modname, funcname, func):
def load_external_module(self, funcname, func,
):
"""
This function can be used to add externally defined redis modules,
and their namespaces to the redis client.
modname - A string containing the name of the redis module to look for
in the redis info block.

funcname - A string containing the name of the function to create
func - The function, being added to this class.

Expand All @@ -914,31 +919,25 @@ def load_external_module(self, modname, funcname, func):
from redis import Redis
from foomodule import F
r = Redis()
r.load_external_module("foomod", "foo", F)
r.load_external_module("foo", F)
r.foo().dothing('your', 'arguments')

For a concrete example see the reimport of the redisjson module in
tests/test_connection.py::test_loading_external_modules
"""
mods = self.loaded_modules
if modname.lower() not in mods:
raise ModuleError("{} is not loaded in redis.".format(modname))
setattr(self, funcname, func)

@property
def loaded_modules(self):
key = '__redis_modules__'
mods = getattr(self, key, None)
if mods is not None:
return mods

def __redis_commands__(self):
"""Store the list of available commands, for our redis instance."""
cmds = getattr(self, '__commands__', None)
if cmds is not None:
return cmds
try:
mods = {f.get('name').lower(): f.get('ver')
for f in self.info().get('modules')}
except TypeError:
mods = []
setattr(self, key, mods)
return mods
cmds = [c[0].upper().decode() for c in self.command()]
except AttributeError: # if encoded
cmds = [c[0].upper() for c in self.command()]
self.__commands__ = cmds
return cmds

def pipeline(self, transaction=True, shard_hint=None):
"""
Expand Down
10 changes: 8 additions & 2 deletions redis/commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2520,10 +2520,13 @@ def zrange(self, name, start, end, desc=False, withscores=False,
``offset`` and ``num`` are specified, then return a slice of the range.
Can't be provided when using ``bylex``.
"""
# Supports old implementation: need to support ``desc`` also for version < 6.2.0
if not byscore and not bylex and (offset is None and num is None) and desc:
# Need to support ``desc`` also when using old redis version
# because it was supported in 3.5.3 (of redis-py)
if not byscore and not bylex and (offset is None and num is None) \
and desc:
return self.zrevrange(name, start, end, withscores,
score_cast_func)

return self._zrange('ZRANGE', None, name, start, end, desc, byscore,
bylex, withscores, score_cast_func, offset, num)

Expand Down Expand Up @@ -3312,6 +3315,9 @@ def command_info(self):
def command_count(self):
return self.execute_command('COMMAND COUNT')

def command(self):
return self.execute_command('COMMAND')


class Script:
"An executable Lua script object returned by ``register_script``"
Expand Down
Loading