From b8942a0ccb08c0bc1f641f09215426771d173755 Mon Sep 17 00:00:00 2001 From: Menno de Boer Date: Wed, 16 Aug 2023 10:30:38 +0200 Subject: [PATCH] add support for zPopMax --- src/Database/Redis/Schema.hs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Database/Redis/Schema.hs b/src/Database/Redis/Schema.hs index ff07a26..26a241a 100644 --- a/src/Database/Redis/Schema.hs +++ b/src/Database/Redis/Schema.hs @@ -56,7 +56,7 @@ module Database.Redis.Schema , day, hour, minute, second , throw, throwMsg , sInsert, sDelete, sContains, sSize - , Priority(..), zInsert, zSize, zCount, zDelete, zIncrBy, zPopMin, bzPopMin, zRangeByScoreLimit, zRange, zRevRange, zScanOpts, zUnionStoreWeights + , Priority(..), zInsert, zSize, zCount, zDelete, zIncrBy, zPopMax, zPopMin, bzPopMin, zRangeByScoreLimit, zRange, zRevRange, zScanOpts, zUnionStoreWeights , txSInsert, txSDelete, txSContains, txSSize , MapItem(..) , RecordField(..), RecordItem(..), Record @@ -1022,6 +1022,20 @@ zIncrBy (toIdentifier -> keyBS) incr (toBS -> val)= >>= expectRight "zincrby" <&> Priority +-- | Remove given number of largest elements from a sorted set. +-- Available since Redis 5.0.0 +zPopMax :: forall ref a. (Ref ref, ValueType ref ~ [(Priority, a)], Serializable a) => ref -> Integer -> RedisM (RefInstance ref) [(Priority, a)] +zPopMax (toIdentifier -> keyBS) cnt = + Redis (zpopmax keyBS cnt) + >>= expectRight "zpopmax call" + >>= expectRight "zpopmax decode" . fromBSMany' + where fromBSMany' = traverse $ \(valBS,sc) -> maybe (Left valBS) (Right . (Priority sc,)) $ fromBS valBS + +-- | ZPOPMAX as it should be in the Hedis library (but it isn't yet) +-- Available since Redis 5.0.0 +zpopmax :: Hedis.RedisCtx m f => ByteString -> Integer -> m (f [(ByteString, Double)]) +zpopmax k c = Hedis.sendRequest ["ZPOPMAX", k, toBS c] + -- | Remove given number of smallest elements from a sorted set. -- Available since Redis 5.0.0 zPopMin :: forall ref a. (Ref ref, ValueType ref ~ [(Priority, a)], Serializable a) => ref -> Integer -> RedisM (RefInstance ref) [(Priority, a)]