@@ -703,7 +703,6 @@ class Redis(RedisModuleCommands, CoreCommands, object):
703
703
'CLUSTER SET-CONFIG-EPOCH' : bool_ok ,
704
704
'CLUSTER SETSLOT' : bool_ok ,
705
705
'CLUSTER SLAVES' : parse_cluster_nodes ,
706
- 'COMMAND' : int ,
707
706
'COMMAND COUNT' : int ,
708
707
'CONFIG GET' : parse_config_get ,
709
708
'CONFIG RESETSTAT' : bool_ok ,
@@ -891,19 +890,25 @@ def __init__(self, host='localhost', port=6379,
891
890
self .response_callbacks = CaseInsensitiveDict (
892
891
self .__class__ .RESPONSE_CALLBACKS )
893
892
893
+ # preload our class with the available redis commands
894
+ try :
895
+ self .__redis_commands__ ()
896
+ except RedisError :
897
+ pass
898
+
894
899
def __repr__ (self ):
895
900
return "%s<%s>" % (type (self ).__name__ , repr (self .connection_pool ))
896
901
897
902
def set_response_callback (self , command , callback ):
898
903
"Set a custom Response Callback"
899
904
self .response_callbacks [command ] = callback
900
905
901
- def load_external_module (self , modname , funcname , func ):
906
+ def load_external_module (self , funcname , func ,
907
+ ):
902
908
"""
903
909
This function can be used to add externally defined redis modules,
904
910
and their namespaces to the redis client.
905
- modname - A string containing the name of the redis module to look for
906
- in the redis info block.
911
+
907
912
funcname - A string containing the name of the function to create
908
913
func - The function, being added to this class.
909
914
@@ -914,31 +919,25 @@ def load_external_module(self, modname, funcname, func):
914
919
from redis import Redis
915
920
from foomodule import F
916
921
r = Redis()
917
- r.load_external_module("foomod", " foo", F)
922
+ r.load_external_module("foo", F)
918
923
r.foo().dothing('your', 'arguments')
919
924
920
925
For a concrete example see the reimport of the redisjson module in
921
926
tests/test_connection.py::test_loading_external_modules
922
927
"""
923
- mods = self .loaded_modules
924
- if modname .lower () not in mods :
925
- raise ModuleError ("{} is not loaded in redis." .format (modname ))
926
928
setattr (self , funcname , func )
927
929
928
- @property
929
- def loaded_modules (self ):
930
- key = '__redis_modules__'
931
- mods = getattr (self , key , None )
932
- if mods is not None :
933
- return mods
934
-
930
+ def __redis_commands__ (self ):
931
+ """Store the list of available commands, for our redis instance."""
932
+ cmds = getattr (self , '__commands__' , None )
933
+ if cmds is not None :
934
+ return cmds
935
935
try :
936
- mods = {f .get ('name' ).lower (): f .get ('ver' )
937
- for f in self .info ().get ('modules' )}
938
- except TypeError :
939
- mods = []
940
- setattr (self , key , mods )
941
- return mods
936
+ cmds = [c [0 ].upper ().decode () for c in self .command ()]
937
+ except AttributeError : # if encoded
938
+ cmds = [c [0 ].upper () for c in self .command ()]
939
+ self .__commands__ = cmds
940
+ return cmds
942
941
943
942
def pipeline (self , transaction = True , shard_hint = None ):
944
943
"""
0 commit comments