def _wrap(self, method, *args, **kwargs): """对执行的命令进行验证 Args: method: redis的方法 """ LOG.debug("redis adapter execute method:%s, args=%s, kwargs=%s", method, args, kwargs) try: key = args[0] except IndexError: raise ValueError('method %s requires a key param as the first argument' % method) if method.upper() in NOT_SUPPORT_COMMANDS: LOG.error('%s is not supported by codis', method) raise NotSupportCommandError('method %s is not supported by codis, key=%s' % (method, key)) codis_func = getattr(self.api, method) return codis_func(*args, **kwargs)
def rename(self, old_name, new_name): """重命名redis的key Args: old_name: 旧版本key new_name: 新key Returns: False: 如果key不存在 True: key存在并且设置成功 """ try: self.api.rename(mkey(old_name), mkey(new_name)) return True except ResponseError as exc: LOG.error("zyredis rename error, error info=%s", exc) return False
def _wrap(self, method, *args, **kwargs): '''打包pipeline的方法 Args: method: pipeline要执行的方法 args: pipeline执行方法的参数 kwargs: pipeline字典参数 ''' LOG.debug("pipeline execute method:%s, args=%s, kwargs=%s", method, args, kwargs) try: key = args[0] except: raise ValueError("'%s' requires a key param as the first argument" % method) if not self.transaction and method.upper() in NOT_SUPPORT_COMMANDS: LOG.error('%s is not supported by codis', method) raise NotSupportCommandError('method %s is not supported by codis, key=%s' % (method, key)) # 执行codis f = getattr(self.codis_pipeline, method) f(*args, **kwargs)
def _wrap(self, method, *args, **kwargs): """对执行的命令进行验证 Args: method: redis的方法 """ LOG.debug("redis adapter execute method:%s, args=%s, kwargs=%s", method, args, kwargs) try: key = args[0] except IndexError: raise ValueError( 'method %s requires a key param as the first argument' % method) if method.upper() in NOT_SUPPORT_COMMANDS: LOG.error('%s is not supported by codis', method) raise NotSupportCommandError( 'method %s is not supported by codis, key=%s' % (method, key)) codis_func = getattr(self.api, method) return codis_func(*args, **kwargs)
def _wrap(self, method, *args, **kwargs): '''打包pipeline的方法 Args: method: pipeline要执行的方法 args: pipeline执行方法的参数 kwargs: pipeline字典参数 ''' LOG.debug("pipeline execute method:%s, args=%s, kwargs=%s", method, args, kwargs) try: key = args[0] except: raise ValueError( "'%s' requires a key param as the first argument" % method) if not self.transaction and method.upper() in NOT_SUPPORT_COMMANDS: LOG.error('%s is not supported by codis', method) raise NotSupportCommandError( 'method %s is not supported by codis, key=%s' % (method, key)) # 执行codis f = getattr(self.codis_pipeline, method) f(*args, **kwargs)