Skip to content

Commit

Permalink
add support for zPopMax
Browse files Browse the repository at this point in the history
  • Loading branch information
Menno de Boer committed Sep 12, 2023
1 parent b84283e commit b8942a0
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/Database/Redis/Schema.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)]
Expand Down

0 comments on commit b8942a0

Please sign in to comment.