Method: Redis::Commands::Streams#xtrim

Defined in:
lib/redis/commands/streams.rb

#xtrim(key, maxlen, strategy: 'MAXLEN', approximate: true) ⇒ Integer #xtrim(key, minid, strategy: 'MINID', approximate: true) ⇒ Integer

Trims older entries of the stream if needed.

Examples:

Without options

redis.xtrim('mystream', 1000)

With options

redis.xtrim('mystream', 1000, approximate: true)

With strategy

redis.xtrim('mystream', '1-0', strategy: 'MINID')

Overloads:

  • #xtrim(key, maxlen, strategy: 'MAXLEN', approximate: true) ⇒ Integer

    Parameters:

    • key (String)

      the stream key

    • maxlen (Integer)

      max length of entries

    • strategy (String) (defaults to: 'MAXLEN')

      the limit strategy, must be MAXLEN

    • approximate (Boolean) (defaults to: true)

      whether to add ~ modifier of maxlen or not

    • limit (Integer)

      maximum count of entries to be evicted

  • #xtrim(key, minid, strategy: 'MINID', approximate: true) ⇒ Integer

    Parameters:

    • key (String)

      the stream key

    • minid (String)

      minimum id of entries

    • strategy (String) (defaults to: 'MINID')

      the limit strategy, must be MINID

    • approximate (Boolean) (defaults to: true)

      whether to add ~ modifier of minid or not

    • limit (Integer)

      maximum count of entries to be evicted

Returns:

  • (Integer)

    the number of entries actually deleted



92
93
94
95
96
97
98
99
100
# File 'lib/redis/commands/streams.rb', line 92

def xtrim(key, len_or_id, strategy: 'MAXLEN', approximate: false, limit: nil)
  strategy = strategy.to_s.upcase

  args = [:xtrim, key, strategy]
  args << '~' if approximate
  args << len_or_id
  args.concat(['LIMIT', limit]) if limit
  send_command(args)
end