Extend SugarDB Commands Using Lua Scripts (#155)

* Extend SugarDB by creating new commands using Lua - @kelvinmwinuka
This commit is contained in:
Kelvin Mwinuka
2024-12-12 09:50:43 +08:00
committed by GitHub
parent 3b15061dbc
commit 108bf97b4d
41 changed files with 9111 additions and 13573 deletions

View File

@@ -1381,6 +1381,7 @@ Adds all the specified members with the specified scores to the sorted set at th
"CH" modifies the result to return total number of members changed + added, instead of only new members added.
"INCR" modifies the command to act like ZINCRBY, only one score/member pair can be specified in this mode.`,
Sync: true,
Type: "BUILT_IN",
KeyExtractionFunc: zaddKeyFunc,
HandlerFunc: handleZADD,
},
@@ -1392,6 +1393,7 @@ Adds all the specified members with the specified scores to the sorted set at th
If the key does not exist, 0 is returned, otherwise the cardinality of the sorted set is returned.
If the key holds a value that is not a sorted set, this command will return an error.`,
Sync: false,
Type: "BUILT_IN",
KeyExtractionFunc: zcardKeyFunc,
HandlerFunc: handleZCARD,
},
@@ -1404,6 +1406,7 @@ Returns the number of elements in the sorted set key with scores in the range of
If the key does not exist, a count of 0 is returned, otherwise return the count.
If the key holds a value that is not a sorted set, an error is returned.`,
Sync: false,
Type: "BUILT_IN",
KeyExtractionFunc: zcountKeyFunc,
HandlerFunc: handleZCOUNT,
},
@@ -1414,6 +1417,7 @@ If the key holds a value that is not a sorted set, an error is returned.`,
Description: `(ZDIFF key [key...] [WITHSCORES])
Computes the difference between all the sorted sets specified in the list of keys and returns the result.`,
Sync: false,
Type: "BUILT_IN",
KeyExtractionFunc: zdiffKeyFunc,
HandlerFunc: handleZDIFF,
},
@@ -1425,6 +1429,7 @@ Computes the difference between all the sorted sets specified in the list of key
Computes the difference between all the sorted sets specifies in the list of keys. Stores the result in destination.
If the base set (first key) does not exist, return 0, otherwise, return the cardinality of the diff.`,
Sync: true,
Type: "BUILT_IN",
KeyExtractionFunc: zdiffstoreKeyFunc,
HandlerFunc: handleZDIFFSTORE,
},
@@ -1436,6 +1441,7 @@ If the base set (first key) does not exist, return 0, otherwise, return the card
Increments the score of the specified sorted set's member by the increment. If the member does not exist, it is created.
If the key does not exist, it is created with new sorted set and the member added with the increment as its score.`,
Sync: true,
Type: "BUILT_IN",
KeyExtractionFunc: zincrbyKeyFunc,
HandlerFunc: handleZINCRBY,
},
@@ -1446,6 +1452,7 @@ If the key does not exist, it is created with new sorted set and the member adde
Description: `(ZINTER key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE <SUM | MIN | MAX>] [WITHSCORES]).
Computes the intersection of the sets in the keys, with weights, aggregate and scores`,
Sync: false,
Type: "BUILT_IN",
KeyExtractionFunc: zinterKeyFunc,
HandlerFunc: handleZINTER,
},
@@ -1457,6 +1464,7 @@ Computes the intersection of the sets in the keys, with weights, aggregate and s
(ZINTERSTORE destination key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE <SUM | MIN | MAX>] [WITHSCORES]).
Computes the intersection of the sets in the keys, with weights, aggregate and scores. The result is stored in destination.`,
Sync: true,
Type: "BUILT_IN",
KeyExtractionFunc: zinterstoreKeyFunc,
HandlerFunc: handleZINTERSTORE,
},
@@ -1468,6 +1476,7 @@ Computes the intersection of the sets in the keys, with weights, aggregate and s
Pop a 'count' elements from multiple sorted sets. MIN or MAX determines whether to pop elements with the lowest or highest scores
respectively.`,
Sync: true,
Type: "BUILT_IN",
KeyExtractionFunc: zmpopKeyFunc,
HandlerFunc: handleZMPOP,
},
@@ -1479,6 +1488,7 @@ respectively.`,
Returns the associated scores of the specified member in the sorted set.
Returns nil for members that do not exist in the set`,
Sync: false,
Type: "BUILT_IN",
KeyExtractionFunc: zmscoreKeyFunc,
HandlerFunc: handleZMSCORE,
},
@@ -1489,6 +1499,7 @@ Returns nil for members that do not exist in the set`,
Description: `(ZPOPMAX key [count])
Removes and returns 'count' number of members in the sorted set with the highest scores. Default count is 1.`,
Sync: true,
Type: "BUILT_IN",
KeyExtractionFunc: zpopKeyFunc,
HandlerFunc: handleZPOP,
},
@@ -1499,6 +1510,7 @@ Removes and returns 'count' number of members in the sorted set with the highest
Description: `(ZPOPMIN key [count])
Removes and returns 'count' number of members in the sorted set with the lowest scores. Default count is 1.`,
Sync: true,
Type: "BUILT_IN",
KeyExtractionFunc: zpopKeyFunc,
HandlerFunc: handleZPOP,
},
@@ -1511,6 +1523,7 @@ Return a list of length equivalent to count containing random members of the sor
If count is negative, repeated elements are allowed. If count is positive, the returned elements will be distinct.
WITHSCORES modifies the result to include scores in the result.`,
Sync: false,
Type: "BUILT_IN",
KeyExtractionFunc: zrandmemberKeyFunc,
HandlerFunc: handleZRANDMEMBER,
},
@@ -1521,6 +1534,7 @@ WITHSCORES modifies the result to include scores in the result.`,
Description: `(ZRANK key member [WITHSCORE])
Returns the rank of the specified member in the sorted set. WITHSCORE modifies the result to also return the score.`,
Sync: false,
Type: "BUILT_IN",
KeyExtractionFunc: zrankKeyFunc,
HandlerFunc: handleZRANK,
},
@@ -1532,6 +1546,7 @@ Returns the rank of the specified member in the sorted set. WITHSCORE modifies t
Returns the rank of the member in the sorted set in reverse order.
WITHSCORE modifies the result to include the score.`,
Sync: false,
Type: "BUILT_IN",
KeyExtractionFunc: zrevrankKeyFunc,
HandlerFunc: handleZRANK,
},
@@ -1542,6 +1557,7 @@ WITHSCORE modifies the result to include the score.`,
Description: `(ZREM key member [member ...]) Removes the listed members from the sorted set.
Returns the number of elements removed.`,
Sync: true,
Type: "BUILT_IN",
KeyExtractionFunc: zremKeyFunc,
HandlerFunc: handleZREM,
},
@@ -1551,6 +1567,7 @@ Returns the number of elements removed.`,
Categories: []string{constants.SortedSetCategory, constants.ReadCategory, constants.FastCategory},
Description: `(ZSCORE key member) Returns the score of the member in the sorted set.`,
Sync: false,
Type: "BUILT_IN",
KeyExtractionFunc: zscoreKeyFunc,
HandlerFunc: handleZSCORE,
},
@@ -1560,6 +1577,7 @@ Returns the number of elements removed.`,
Categories: []string{constants.SortedSetCategory, constants.WriteCategory, constants.SlowCategory},
Description: `(ZREMRANGEBYLEX key min max) Removes the elements in the lexicographical range between min and max`,
Sync: true,
Type: "BUILT_IN",
KeyExtractionFunc: zremrangebylexKeyFunc,
HandlerFunc: handleZREMRANGEBYLEX,
},
@@ -1570,6 +1588,7 @@ Returns the number of elements removed.`,
Description: `(ZREMRANGEBYRANK key start stop) Removes the elements in the rank range between start and stop.
The elements are ordered from lowest score to highest score`,
Sync: true,
Type: "BUILT_IN",
KeyExtractionFunc: zremrangebyrankKeyFunc,
HandlerFunc: handleZREMRANGEBYRANK,
},
@@ -1579,6 +1598,7 @@ The elements are ordered from lowest score to highest score`,
Categories: []string{constants.SortedSetCategory, constants.WriteCategory, constants.SlowCategory},
Description: `(ZREMRANGEBYSCORE key min max) Removes the elements whose scores are in the range between min and max`,
Sync: true,
Type: "BUILT_IN",
KeyExtractionFunc: zremrangebyscoreKeyFunc,
HandlerFunc: handleZREMRANGEBYSCORE,
},
@@ -1590,6 +1610,7 @@ The elements are ordered from lowest score to highest score`,
lexicographical range between min and max. Returns 0, if the keys does not exist or if all the members do not have
the same score. If the value held at key is not a sorted set, an error is returned.`,
Sync: false,
Type: "BUILT_IN",
KeyExtractionFunc: zlexcountKeyFunc,
HandlerFunc: handleZLEXCOUNT,
},
@@ -1600,6 +1621,7 @@ the same score. If the value held at key is not a sorted set, an error is return
Description: `(ZRANGE key start stop [BYSCORE | BYLEX] [REV] [LIMIT offset count]
[WITHSCORES]) Returns the range of elements in the sorted set.`,
Sync: false,
Type: "BUILT_IN",
KeyExtractionFunc: zrangeKeyCount,
HandlerFunc: handleZRANGE,
},
@@ -1610,6 +1632,7 @@ the same score. If the value held at key is not a sorted set, an error is return
Description: `ZRANGESTORE destination source start stop [BYSCORE | BYLEX] [REV] [LIMIT offset count]
[WITHSCORES] Retrieve the range of elements in the sorted set and store it in destination.`,
Sync: true,
Type: "BUILT_IN",
KeyExtractionFunc: zrangeStoreKeyFunc,
HandlerFunc: handleZRANGESTORE,
},
@@ -1622,6 +1645,7 @@ the same score. If the value held at key is not a sorted set, an error is return
a sorted set are multiplied by the corresponding weight in WEIGHTS. Aggregate determines how the scores are combined.
WITHSCORES option determines whether to return the result with scores included.`,
Sync: false,
Type: "BUILT_IN",
KeyExtractionFunc: zunionKeyFunc,
HandlerFunc: handleZUNION,
},
@@ -1634,6 +1658,7 @@ WITHSCORES option determines whether to return the result with scores included.`
a sorted set are multiplied by the corresponding weight in WEIGHTS. Aggregate determines how the scores are combined.
The resulting union is stored at the destination key.`,
Sync: true,
Type: "BUILT_IN",
KeyExtractionFunc: zunionstoreKeyFunc,
HandlerFunc: handleZUNIONSTORE,
},