MCPcopy Create free account
hub / github.com/F-Stack/f-stack / streamParseAddOrTrimArgsOrReply

Function streamParseAddOrTrimArgsOrReply

app/redis-6.2.6/src/t_stream.c:896–1024  ·  view source on GitHub ↗

Parse the arguments of XADD/XTRIM. * * See streamAddTrimArgs for more details about the arguments handled. * * This function returns the position of the ID argument (relevant only to XADD). * On error -1 is returned and a reply is sent. */

Source from the content-addressed store, hash-verified

894 * This function returns the position of the ID argument (relevant only to XADD).
895 * On error -1 is returned and a reply is sent. */
896static int streamParseAddOrTrimArgsOrReply(client *c, streamAddTrimArgs *args, int xadd) {
897 /* Initialize arguments to defaults */
898 memset(args, 0, sizeof(*args));
899
900 /* Parse options. */
901 int i = 2; /* This is the first argument position where we could
902 find an option, or the ID. */
903 int limit_given = 0;
904 for (; i < c->argc; i++) {
905 int moreargs = (c->argc-1) - i; /* Number of additional arguments. */
906 char *opt = c->argv[i]->ptr;
907 if (xadd && opt[0] == '*' && opt[1] == '\0') {
908 /* This is just a fast path for the common case of auto-ID
909 * creation. */
910 break;
911 } else if (!strcasecmp(opt,"maxlen") && moreargs) {
912 if (args->trim_strategy != TRIM_STRATEGY_NONE) {
913 addReplyError(c,"syntax error, MAXLEN and MINID options at the same time are not compatible");
914 return -1;
915 }
916 args->approx_trim = 0;
917 char *next = c->argv[i+1]->ptr;
918 /* Check for the form MAXLEN ~ <count>. */
919 if (moreargs >= 2 && next[0] == '~' && next[1] == '\0') {
920 args->approx_trim = 1;
921 i++;
922 } else if (moreargs >= 2 && next[0] == '=' && next[1] == '\0') {
923 i++;
924 }
925 if (getLongLongFromObjectOrReply(c,c->argv[i+1],&args->maxlen,NULL)
926 != C_OK) return -1;
927
928 if (args->maxlen < 0) {
929 addReplyError(c,"The MAXLEN argument must be >= 0.");
930 return -1;
931 }
932 i++;
933 args->trim_strategy = TRIM_STRATEGY_MAXLEN;
934 args->trim_strategy_arg_idx = i;
935 } else if (!strcasecmp(opt,"minid") && moreargs) {
936 if (args->trim_strategy != TRIM_STRATEGY_NONE) {
937 addReplyError(c,"syntax error, MAXLEN and MINID options at the same time are not compatible");
938 return -1;
939 }
940 args->approx_trim = 0;
941 char *next = c->argv[i+1]->ptr;
942 /* Check for the form MINID ~ <id>|<age>. */
943 if (moreargs >= 2 && next[0] == '~' && next[1] == '\0') {
944 args->approx_trim = 1;
945 i++;
946 } else if (moreargs >= 2 && next[0] == '=' && next[1] == '\0') {
947 i++;
948 }
949
950 if (streamParseStrictIDOrReply(c,c->argv[i+1],&args->minid,0) != C_OK)
951 return -1;
952
953 i++;

Callers 2

xaddCommandFunction · 0.85
xtrimCommandFunction · 0.85

Calls 6

memsetFunction · 0.85
strcasecmpFunction · 0.85
addReplyErrorFunction · 0.85
addReplyErrorObjectFunction · 0.85

Tested by

no test coverage detected