mirror of
https://github.com/redis/redis.git
synced 2026-04-21 03:01:35 -04:00
The PR extends RM_Call with 3 new capabilities using new flags that are given to RM_Call as part of the `fmt` argument. It aims to assist modules that are getting a list of commands to be executed from the user (not hard coded as part of the module logic), think of a module that implements a new scripting language... * `S` - Run the command in a script mode, this means that it will raise an error if a command which are not allowed inside a script (flaged with the `deny-script` flag) is invoked (like SHUTDOWN). In addition, on script mode, write commands are not allowed if there is not enough good replicas (as configured with `min-replicas-to-write`) and/or a disk error happened. * `W` - no writes mode, Redis will reject any command that is marked with `write` flag. Again can be useful to modules that implement a new scripting language and wants to prevent any write commands. * `E` - Return errors as RedisModuleCallReply. Today the errors that happened before the command was invoked (like unknown commands or acl error) return a NULL reply and set errno. This might be missing important information about the failure and it is also impossible to just pass the error to the user using RM_ReplyWithCallReply. This new flag allows you to get a RedisModuleCallReply object with the relevant error message and treat it as if it was an error that was raised by the command invocation. Tests were added to verify the new code paths. In addition small refactoring was done to share some code between modules, scripts, and `processCommand` function: 1. `getAclErrorMessage` was added to `acl.c` to unified to log message extraction from the acl result 2. `checkGoodReplicasStatus` was added to `replication.c` to check the status of good replicas. It is used on `scriptVerifyWriteCommandAllow`, `RM_Call`, and `processCommand`. 3. `writeCommandsGetDiskErrorMessage` was added to `server.c` to get the error message on persistence failure. Again it is used on `scriptVerifyWriteCommandAllow`, `RM_Call`, and `processCommand`.
59 lines
2.8 KiB
C
59 lines
2.8 KiB
C
/*
|
|
* Copyright (c) 2009-2021, Redis Labs Ltd.
|
|
* All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions are met:
|
|
*
|
|
* * Redistributions of source code must retain the above copyright notice,
|
|
* this list of conditions and the following disclaimer.
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
* documentation and/or other materials provided with the distribution.
|
|
* * Neither the name of Redis nor the names of its contributors may be used
|
|
* to endorse or promote products derived from this software without
|
|
* specific prior written permission.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
*/
|
|
|
|
#ifndef SRC_CALL_REPLY_H_
|
|
#define SRC_CALL_REPLY_H_
|
|
|
|
#include "resp_parser.h"
|
|
|
|
typedef struct CallReply CallReply;
|
|
|
|
CallReply *callReplyCreate(sds reply, list *deferred_error_list, void *private_data);
|
|
CallReply *callReplyCreateError(sds reply, void *private_data);
|
|
int callReplyType(CallReply *rep);
|
|
const char *callReplyGetString(CallReply *rep, size_t *len);
|
|
long long callReplyGetLongLong(CallReply *rep);
|
|
double callReplyGetDouble(CallReply *rep);
|
|
int callReplyGetBool(CallReply *rep);
|
|
size_t callReplyGetLen(CallReply *rep);
|
|
CallReply *callReplyGetArrayElement(CallReply *rep, size_t idx);
|
|
CallReply *callReplyGetSetElement(CallReply *rep, size_t idx);
|
|
int callReplyGetMapElement(CallReply *rep, size_t idx, CallReply **key, CallReply **val);
|
|
CallReply *callReplyGetAttribute(CallReply *rep);
|
|
int callReplyGetAttributeElement(CallReply *rep, size_t idx, CallReply **key, CallReply **val);
|
|
const char *callReplyGetBigNumber(CallReply *rep, size_t *len);
|
|
const char *callReplyGetVerbatim(CallReply *rep, size_t *len, const char **format);
|
|
const char *callReplyGetProto(CallReply *rep, size_t *len);
|
|
void *callReplyGetPrivateData(CallReply *rep);
|
|
int callReplyIsResp3(CallReply *rep);
|
|
list *callReplyDeferredErrorList(CallReply *rep);
|
|
void freeCallReply(CallReply *rep);
|
|
|
|
#endif /* SRC_CALL_REPLY_H_ */
|