@@ -703,7 +703,6 @@ class Redis(RedisModuleCommands, CoreCommands, object):
703703 'CLUSTER SET-CONFIG-EPOCH' : bool_ok ,
704704 'CLUSTER SETSLOT' : bool_ok ,
705705 'CLUSTER SLAVES' : parse_cluster_nodes ,
706- 'COMMAND' : int ,
707706 'COMMAND COUNT' : int ,
708707 'CONFIG GET' : parse_config_get ,
709708 'CONFIG RESETSTAT' : bool_ok ,
@@ -891,19 +890,25 @@ def __init__(self, host='localhost', port=6379,
891890 self .response_callbacks = CaseInsensitiveDict (
892891 self .__class__ .RESPONSE_CALLBACKS )
893892
893+ # preload our class with the available redis commands
894+ try :
895+ self .__redis_commands__ ()
896+ except RedisError :
897+ pass
898+
894899 def __repr__ (self ):
895900 return "%s<%s>" % (type (self ).__name__ , repr (self .connection_pool ))
896901
897902 def set_response_callback (self , command , callback ):
898903 "Set a custom Response Callback"
899904 self .response_callbacks [command ] = callback
900905
901- def load_external_module (self , modname , funcname , func ):
906+ def load_external_module (self , funcname , func ,
907+ ):
902908 """
903909 This function can be used to add externally defined redis modules,
904910 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+
907912 funcname - A string containing the name of the function to create
908913 func - The function, being added to this class.
909914
@@ -914,31 +919,25 @@ def load_external_module(self, modname, funcname, func):
914919 from redis import Redis
915920 from foomodule import F
916921 r = Redis()
917- r.load_external_module("foomod", " foo", F)
922+ r.load_external_module("foo", F)
918923 r.foo().dothing('your', 'arguments')
919924
920925 For a concrete example see the reimport of the redisjson module in
921926 tests/test_connection.py::test_loading_external_modules
922927 """
923- mods = self .loaded_modules
924- if modname .lower () not in mods :
925- raise ModuleError ("{} is not loaded in redis." .format (modname ))
926928 setattr (self , funcname , func )
927929
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
935935 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
942941
943942 def pipeline (self , transaction = True , shard_hint = None ):
944943 """
0 commit comments