Skip to content

Commit

Permalink
Name threshold paramter correct for XTRIM command (#1053)
Browse files Browse the repository at this point in the history
  • Loading branch information
hcwilhelm authored Feb 26, 2025
1 parent 6e4ab0c commit 7f46ee0
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions modules/redis/src/main/scala/zio/redis/api/Streams.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/

package zio.redis.api

import zio._
import zio.redis.Input._
import zio.redis.Output._
Expand Down Expand Up @@ -1027,51 +1026,51 @@ trait Streams[G[+_]] extends RedisEnvironment[G] {
*
* @param key
* ID of the stream
* @param count
* stream length
* @param threshold
* Evicts entries as long as the stream's length exceeds the specified threshold
* @param approximate
* flag that indicates if the stream length should be exactly count or few tens of entries more
* @return
* the number of entries deleted from the stream.
*/
final def xTrimWithMaxLen[SK: Schema](
key: SK,
count: Long,
threshold: Long,
approximate: Boolean = false,
limit: Option[Long] = None
): G[Long] =
if (approximate) {
val command = RedisCommand(XTrim, Tuple2(ArbitraryKeyInput[SK](), MaxLenApproxInput), LongOutput)
command.run((key, CappedStreamType.MaxLenApprox(count, limit)))
command.run((key, CappedStreamType.MaxLenApprox(threshold, limit)))
} else {
val command = RedisCommand(XTrim, Tuple2(ArbitraryKeyInput[SK](), MaxLenExactInput), LongOutput)
command.run((key, CappedStreamType.MaxLenExact(count)))
command.run((key, CappedStreamType.MaxLenExact(threshold)))
}

/**
* Trims the stream to a given number of items, evicting older items (items with lower IDs) if needed.
*
* @param key
* ID of the stream
* @param minId
* minimal stream id
* @param threshold
* Evicts entries with IDs lower than threshold, where threshold is a stream ID
* @param approximate
* flag that indicates if the stream length should be exactly count or few tens of entries more
* @return
* the number of entries deleted from the stream.
*/
final def xTrimWithMinId[SK: Schema, I: Schema](
key: SK,
minId: I,
threshold: I,
approximate: Boolean = false,
limit: Option[Long] = None
): G[Long] =
if (approximate) {
val command = RedisCommand(XTrim, Tuple2(ArbitraryKeyInput[SK](), MinIdApproxInput[I]()), LongOutput)
command.run((key, CappedStreamType.MinIdApprox(minId, limit)))
command.run((key, CappedStreamType.MinIdApprox(threshold, limit)))
} else {
val command = RedisCommand(XTrim, Tuple2(ArbitraryKeyInput[SK](), MinIdExactInput[I]()), LongOutput)
command.run((key, CappedStreamType.MinIdExact(minId)))
command.run((key, CappedStreamType.MinIdExact(threshold)))
}
}

Expand Down

0 comments on commit 7f46ee0

Please sign in to comment.