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

Function zremrangeGenericCommand

app/redis-6.2.6/src/t_zset.c:1891–1996  ·  view source on GitHub ↗

Implements ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZREMRANGEBYLEX commands. */

Source from the content-addressed store, hash-verified

1889
1890/* Implements ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZREMRANGEBYLEX commands. */
1891void zremrangeGenericCommand(client *c, zrange_type rangetype) {
1892 robj *key = c->argv[1];
1893 robj *zobj;
1894 int keyremoved = 0;
1895 unsigned long deleted = 0;
1896 zrangespec range;
1897 zlexrangespec lexrange;
1898 long start, end, llen;
1899 char *notify_type = NULL;
1900
1901 /* Step 1: Parse the range. */
1902 if (rangetype == ZRANGE_RANK) {
1903 notify_type = "zremrangebyrank";
1904 if ((getLongFromObjectOrReply(c,c->argv[2],&start,NULL) != C_OK) ||
1905 (getLongFromObjectOrReply(c,c->argv[3],&end,NULL) != C_OK))
1906 return;
1907 } else if (rangetype == ZRANGE_SCORE) {
1908 notify_type = "zremrangebyscore";
1909 if (zslParseRange(c->argv[2],c->argv[3],&range) != C_OK) {
1910 addReplyError(c,"min or max is not a float");
1911 return;
1912 }
1913 } else if (rangetype == ZRANGE_LEX) {
1914 notify_type = "zremrangebylex";
1915 if (zslParseLexRange(c->argv[2],c->argv[3],&lexrange) != C_OK) {
1916 addReplyError(c,"min or max not valid string range item");
1917 return;
1918 }
1919 } else {
1920 serverPanic("unknown rangetype %d", (int)rangetype);
1921 }
1922
1923 /* Step 2: Lookup & range sanity checks if needed. */
1924 if ((zobj = lookupKeyWriteOrReply(c,key,shared.czero)) == NULL ||
1925 checkType(c,zobj,OBJ_ZSET)) goto cleanup;
1926
1927 if (rangetype == ZRANGE_RANK) {
1928 /* Sanitize indexes. */
1929 llen = zsetLength(zobj);
1930 if (start < 0) start = llen+start;
1931 if (end < 0) end = llen+end;
1932 if (start < 0) start = 0;
1933
1934 /* Invariant: start >= 0, so this test will be true when end < 0.
1935 * The range is empty when start > end or start >= length. */
1936 if (start > end || start >= llen) {
1937 addReply(c,shared.czero);
1938 goto cleanup;
1939 }
1940 if (end >= llen) end = llen-1;
1941 }
1942
1943 /* Step 3: Perform the range deletion operation. */
1944 if (zobj->encoding == OBJ_ENCODING_ZIPLIST) {
1945 switch(rangetype) {
1946 case ZRANGE_AUTO:
1947 case ZRANGE_RANK:
1948 zobj->ptr = zzlDeleteRangeByRank(zobj->ptr,start+1,end+1,&deleted);

Callers 3

zremrangebyrankCommandFunction · 0.85
zremrangebyscoreCommandFunction · 0.85
zremrangebylexCommandFunction · 0.85

Calls 15

getLongFromObjectOrReplyFunction · 0.85
zslParseRangeFunction · 0.85
addReplyErrorFunction · 0.85
zslParseLexRangeFunction · 0.85
lookupKeyWriteOrReplyFunction · 0.85
checkTypeFunction · 0.85
zsetLengthFunction · 0.85
addReplyFunction · 0.85
zzlDeleteRangeByRankFunction · 0.85
zzlDeleteRangeByScoreFunction · 0.85
zzlDeleteRangeByLexFunction · 0.85
zzlLengthFunction · 0.85

Tested by

no test coverage detected