spring-data-redis icon indicating copy to clipboard operation
spring-data-redis copied to clipboard

Add overloads to `StreamOperations` accepting `XAddOptions`

Open sanwzzz opened this issue 1 year ago • 5 comments

HI

sanwzzz avatar May 24 '24 09:05 sanwzzz

Hi,

I am currently using redisTemplate.opsForStream() to operate on Redis streams. When using the add method, I want to support more parameters such as MAXID and MINID. However, it is not supported at the moment. I noticed that RedisStreamCommands already provides XAddOptions, but currently (in version 3.3.X), there is no way to set these options, and only the default None is called.

Is it possible to enhance the DefaultStreamOperations.add method to support these parameters?

Example

sanwzzz avatar May 24 '24 09:05 sanwzzz

default RecordId add(Record<K, ?> record, XAddOptions ops) {
    return add(record, null)
};
RecordId add(Record<K, ?> record, XAddOptions ops);

sanwzzz avatar May 24 '24 09:05 sanwzzz

Not exactly sure why you've posted details about DefaultStreamOperations. In any case, adding options for the XADD operations are held by XAddOptions. minId and maxlen are already supported, so not sure what you're asking for. Please elaborate.

mp911de avatar Jun 24 '24 13:06 mp911de

Not exactly sure why you've posted details about DefaultStreamOperations. In any case, adding options for the XADD operations are held by XAddOptions. minId and maxlen are already supported, so not sure what you're asking for. Please elaborate.

I want to set the XAddOptions parameter in redisTemplate.opsForStream().add(...) , but there is no method to set the XAddOptions parameter.

Is it possible to add the following API RecordId add(Record<K, ? > record, XAddOptions ops);

sanwzzz avatar Jun 25 '24 03:06 sanwzzz

Ah, I got it. All the screenshots are pretty distracting and contribute a lot of noise to this ticket. I went ahead and removed these.

It is fine to add overloads accepting XAddOptions in StreamOperations and ReactiveStreamOperations.

mp911de avatar Jun 27 '24 11:06 mp911de

Hello, @mp911de May I take this issue?

I've looked through issue and code. I am planning to add interface method RecordId add(Record<K, ?> record, XAddOptions options) and override this method in DefaultStreamOperations. and also same with ReactiveStreamOperations

Do you expect the client code should be like this?

XAddOptions options = XAddOptions.maxlen(1000);
redisTemplate.opsForStream().add("stream", Map.of("key", "value"), options);

if this is the way you implied, i'm happy to make a pr with a few tests to support this change.

jinkshower avatar Jul 06 '24 12:07 jinkshower

Is it possible set global default options? Clip_2024-07-09_15-07-35

sanwzzz avatar Jul 09 '24 07:07 sanwzzz