XAUTOCLAIM [COUNT ] [JUSTID] * * Gets ownership of one or multiple messages in the Pending Entries List * of a given stream consumer group. * * For each PEL entry, if its idle time greater or equal to , * then the message new owner becomes the specified . * If the minimum idle time specified is zero, messages a
| 3053 | * successfully claimed, so that the caller is able to understand |
| 3054 | * what messages it is now in charge of. */ |
| 3055 | void xautoclaimCommand(client *c) { |
| 3056 | streamCG *group = NULL; |
| 3057 | robj *o = lookupKeyRead(c->db,c->argv[1]); |
| 3058 | long long minidle; /* Minimum idle time argument, in milliseconds. */ |
| 3059 | long count = 100; /* Maximum entries to claim. */ |
| 3060 | streamID startid; |
| 3061 | int startex; |
| 3062 | int justid = 0; |
| 3063 | |
| 3064 | /* Parse idle/start/end/count arguments ASAP if needed, in order to report |
| 3065 | * syntax errors before any other error. */ |
| 3066 | if (getLongLongFromObjectOrReply(c,c->argv[4],&minidle,"Invalid min-idle-time argument for XAUTOCLAIM") != C_OK) |
| 3067 | return; |
| 3068 | if (minidle < 0) minidle = 0; |
| 3069 | |
| 3070 | if (streamParseIntervalIDOrReply(c,c->argv[5],&startid,&startex,0) != C_OK) |
| 3071 | return; |
| 3072 | if (startex && streamIncrID(&startid) != C_OK) { |
| 3073 | addReplyError(c,"invalid start ID for the interval"); |
| 3074 | return; |
| 3075 | } |
| 3076 | |
| 3077 | int j = 6; /* options start at argv[6] */ |
| 3078 | while(j < c->argc) { |
| 3079 | int moreargs = (c->argc-1) - j; /* Number of additional arguments. */ |
| 3080 | char *opt = c->argv[j]->ptr; |
| 3081 | if (!strcasecmp(opt,"COUNT") && moreargs) { |
| 3082 | if (getRangeLongFromObjectOrReply(c,c->argv[j+1],1,LONG_MAX,&count,"COUNT must be > 0") != C_OK) |
| 3083 | return; |
| 3084 | j++; |
| 3085 | } else if (!strcasecmp(opt,"JUSTID")) { |
| 3086 | justid = 1; |
| 3087 | } else { |
| 3088 | addReplyErrorObject(c,shared.syntaxerr); |
| 3089 | return; |
| 3090 | } |
| 3091 | j++; |
| 3092 | } |
| 3093 | |
| 3094 | if (o) { |
| 3095 | if (checkType(c,o,OBJ_STREAM)) |
| 3096 | return; /* Type error. */ |
| 3097 | group = streamLookupCG(o->ptr,c->argv[2]->ptr); |
| 3098 | } |
| 3099 | |
| 3100 | /* No key or group? Send an error given that the group creation |
| 3101 | * is mandatory. */ |
| 3102 | if (o == NULL || group == NULL) { |
| 3103 | addReplyErrorFormat(c,"-NOGROUP No such key '%s' or consumer group '%s'", |
| 3104 | (char*)c->argv[1]->ptr, |
| 3105 | (char*)c->argv[2]->ptr); |
| 3106 | return; |
| 3107 | } |
| 3108 | |
| 3109 | /* Do the actual claiming. */ |
| 3110 | streamConsumer *consumer = NULL; |
| 3111 | long long attempts = count*10; |
| 3112 |
nothing calls this directly
no test coverage detected