Helper function to extract keys from the SORT command. * * SORT ... STORE ... * * The first argument of SORT is always a key, however a list of options * follow in SQL-alike style. Here we parse just the minimum in order to * correctly identify keys in the "STORE" option. */
| 1720 | * follow in SQL-alike style. Here we parse just the minimum in order to |
| 1721 | * correctly identify keys in the "STORE" option. */ |
| 1722 | int sortGetKeys(struct redisCommand *cmd, robj **argv, int argc, getKeysResult *result) { |
| 1723 | int i, j, num, *keys, found_store = 0; |
| 1724 | UNUSED(cmd); |
| 1725 | |
| 1726 | num = 0; |
| 1727 | keys = getKeysPrepareResult(result, 2); /* Alloc 2 places for the worst case. */ |
| 1728 | keys[num++] = 1; /* <sort-key> is always present. */ |
| 1729 | |
| 1730 | /* Search for STORE option. By default we consider options to don't |
| 1731 | * have arguments, so if we find an unknown option name we scan the |
| 1732 | * next. However there are options with 1 or 2 arguments, so we |
| 1733 | * provide a list here in order to skip the right number of args. */ |
| 1734 | struct { |
| 1735 | char *name; |
| 1736 | int skip; |
| 1737 | } skiplist[] = { |
| 1738 | {"limit", 2}, |
| 1739 | {"get", 1}, |
| 1740 | {"by", 1}, |
| 1741 | {NULL, 0} /* End of elements. */ |
| 1742 | }; |
| 1743 | |
| 1744 | for (i = 2; i < argc; i++) { |
| 1745 | for (j = 0; skiplist[j].name != NULL; j++) { |
| 1746 | if (!strcasecmp(argv[i]->ptr,skiplist[j].name)) { |
| 1747 | i += skiplist[j].skip; |
| 1748 | break; |
| 1749 | } else if (!strcasecmp(argv[i]->ptr,"store") && i+1 < argc) { |
| 1750 | /* Note: we don't increment "num" here and continue the loop |
| 1751 | * to be sure to process the *last* "STORE" option if multiple |
| 1752 | * ones are provided. This is same behavior as SORT. */ |
| 1753 | found_store = 1; |
| 1754 | keys[num] = i+1; /* <store-key> */ |
| 1755 | break; |
| 1756 | } |
| 1757 | } |
| 1758 | } |
| 1759 | result->numkeys = num + found_store; |
| 1760 | return result->numkeys; |
| 1761 | } |
| 1762 | |
| 1763 | int migrateGetKeys(struct redisCommand *cmd, robj **argv, int argc, getKeysResult *result) { |
| 1764 | int i, num, first, *keys; |
nothing calls this directly
no test coverage detected