Skip to content

Commit 4d77392

Browse files
christophstroblmp911de
authored andcommitted
Support ZADD params for Reactive-/RedisConnection and add addIfAbsent methods.
Closes: #1794 Original pull request: #1988.
1 parent 102ee01 commit 4d77392

21 files changed

+666
-91
lines changed

Diff for: src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java

+12-12
Original file line numberDiff line numberDiff line change
@@ -1322,20 +1322,20 @@ public void watch(byte[]... keys) {
13221322

13231323
/*
13241324
* (non-Javadoc)
1325-
* @see org.springframework.data.redis.connection.RedisZSetCommands#zAdd(byte[], double, byte[])
1325+
* @see org.springframework.data.redis.connection.RedisZSetCommands#zAdd(byte[], double, byte[], org.springframework.data.redis.connection.RedisZSetCommands.ZAddArgs)
13261326
*/
13271327
@Override
1328-
public Boolean zAdd(byte[] key, double score, byte[] value) {
1329-
return convertAndReturn(delegate.zAdd(key, score, value), Converters.identityConverter());
1328+
public Boolean zAdd(byte[] key, double score, byte[] value, ZAddArgs args) {
1329+
return convertAndReturn(delegate.zAdd(key, score, value, args), Converters.identityConverter());
13301330
}
13311331

13321332
/*
13331333
* (non-Javadoc)
1334-
* @see org.springframework.data.redis.connection.RedisZSetCommands#zAdd(byte[], java.util.Set)
1334+
* @see org.springframework.data.redis.connection.RedisZSetCommands#zAdd(byte[], java.util.Set, org.springframework.data.redis.connection.RedisZSetCommands.ZAddArgs)
13351335
*/
13361336
@Override
1337-
public Long zAdd(byte[] key, Set<Tuple> tuples) {
1338-
return convertAndReturn(delegate.zAdd(key, tuples), Converters.identityConverter());
1337+
public Long zAdd(byte[] key, Set<Tuple> tuples, ZAddArgs args) {
1338+
return convertAndReturn(delegate.zAdd(key, tuples, args), Converters.identityConverter());
13391339
}
13401340

13411341
/*
@@ -2686,20 +2686,20 @@ public Long touch(String... keys) {
26862686

26872687
/*
26882688
* (non-Javadoc)
2689-
* @see org.springframework.data.redis.connection.StringRedisConnection#zAdd(java.lang.String, double, java.lang.String)
2689+
* @see org.springframework.data.redis.connection.StringRedisConnection#zAdd(java.lang.String, double, java.lang.String, org.springframework.data.redis.connection.RedisZSetCommands.ZAddArgs)
26902690
*/
26912691
@Override
2692-
public Boolean zAdd(String key, double score, String value) {
2693-
return zAdd(serialize(key), score, serialize(value));
2692+
public Boolean zAdd(String key, double score, String value, ZAddArgs args) {
2693+
return zAdd(serialize(key), score, serialize(value), args);
26942694
}
26952695

26962696
/*
26972697
* (non-Javadoc)
2698-
* @see org.springframework.data.redis.connection.StringRedisConnection#zAdd(java.lang.String, java.util.Set)
2698+
* @see org.springframework.data.redis.connection.StringRedisConnection#zAdd(java.lang.String, java.util.Set, org.springframework.data.redis.connection.RedisZSetCommands.ZAddArgs)
26992699
*/
27002700
@Override
2701-
public Long zAdd(String key, Set<StringTuple> tuples) {
2702-
return zAdd(serialize(key), stringTupleToTuple.convert(tuples));
2701+
public Long zAdd(String key, Set<StringTuple> tuples, ZAddArgs args) {
2702+
return zAdd(serialize(key), stringTupleToTuple.convert(tuples), args);
27032703
}
27042704

27052705
/*

Diff for: src/main/java/org/springframework/data/redis/connection/DefaultedRedisConnection.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -873,15 +873,15 @@ default Cursor<byte[]> sScan(byte[] key, ScanOptions options) {
873873
/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
874874
@Override
875875
@Deprecated
876-
default Boolean zAdd(byte[] key, double score, byte[] value) {
877-
return zSetCommands().zAdd(key, score, value);
876+
default Boolean zAdd(byte[] key, double score, byte[] value, ZAddArgs args) {
877+
return zSetCommands().zAdd(key, score, value, args);
878878
}
879879

880880
/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
881881
@Override
882882
@Deprecated
883-
default Long zAdd(byte[] key, Set<Tuple> tuples) {
884-
return zSetCommands().zAdd(key, tuples);
883+
default Long zAdd(byte[] key, Set<Tuple> tuples, ZAddArgs args) {
884+
return zSetCommands().zAdd(key, tuples, args);
885885
}
886886

887887
/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */

Diff for: src/main/java/org/springframework/data/redis/connection/ReactiveZSetCommands.java

+50-7
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,20 @@ class ZAddCommand extends KeyCommand {
6363
private final boolean upsert;
6464
private final boolean returnTotalChanged;
6565
private final boolean incr;
66+
private final boolean gt;
67+
private final boolean lt;
6668

6769
private ZAddCommand(@Nullable ByteBuffer key, List<Tuple> tuples, boolean upsert, boolean returnTotalChanged,
68-
boolean incr) {
70+
boolean incr, boolean gt, boolean lt) {
6971

7072
super(key);
7173

7274
this.tuples = tuples;
7375
this.upsert = upsert;
7476
this.returnTotalChanged = returnTotalChanged;
7577
this.incr = incr;
78+
this.gt = gt;
79+
this.lt = lt;
7680
}
7781

7882
/**
@@ -98,7 +102,7 @@ public static ZAddCommand tuples(Collection<? extends Tuple> tuples) {
98102

99103
Assert.notNull(tuples, "Tuples must not be null!");
100104

101-
return new ZAddCommand(null, new ArrayList<>(tuples), false, false, false);
105+
return new ZAddCommand(null, new ArrayList<>(tuples), false, false, false, false, false);
102106
}
103107

104108
/**
@@ -111,7 +115,7 @@ public ZAddCommand to(ByteBuffer key) {
111115

112116
Assert.notNull(key, "Key must not be null!");
113117

114-
return new ZAddCommand(key, tuples, upsert, returnTotalChanged, incr);
118+
return new ZAddCommand(key, tuples, upsert, returnTotalChanged, incr, gt, lt);
115119
}
116120

117121
/**
@@ -121,7 +125,7 @@ public ZAddCommand to(ByteBuffer key) {
121125
* @return a new {@link ZAddCommand} with {@literal xx} applied.
122126
*/
123127
public ZAddCommand xx() {
124-
return new ZAddCommand(getKey(), tuples, false, returnTotalChanged, incr);
128+
return new ZAddCommand(getKey(), tuples, false, returnTotalChanged, incr, gt, lt);
125129
}
126130

127131
/**
@@ -131,7 +135,7 @@ public ZAddCommand xx() {
131135
* @return a new {@link ZAddCommand} with {@literal nx} applied.
132136
*/
133137
public ZAddCommand nx() {
134-
return new ZAddCommand(getKey(), tuples, true, returnTotalChanged, incr);
138+
return new ZAddCommand(getKey(), tuples, true, returnTotalChanged, incr, gt, lt);
135139
}
136140

137141
/**
@@ -141,7 +145,7 @@ public ZAddCommand nx() {
141145
* @return a new {@link ZAddCommand} with {@literal ch} applied.
142146
*/
143147
public ZAddCommand ch() {
144-
return new ZAddCommand(getKey(), tuples, upsert, true, incr);
148+
return new ZAddCommand(getKey(), tuples, upsert, true, incr, gt, lt);
145149
}
146150

147151
/**
@@ -151,7 +155,29 @@ public ZAddCommand ch() {
151155
* @return a new {@link ZAddCommand} with {@literal incr} applied.
152156
*/
153157
public ZAddCommand incr() {
154-
return new ZAddCommand(getKey(), tuples, upsert, upsert, true);
158+
return new ZAddCommand(getKey(), tuples, upsert, upsert, true, gt, lt);
159+
}
160+
161+
/**
162+
* Applies {@literal GT} mode. Constructs a new command
163+
* instance with all previously configured properties.
164+
*
165+
* @return a new {@link ZAddCommand} with {@literal incr} applied.
166+
* @since 2.5
167+
*/
168+
public ZAddCommand gt() {
169+
return new ZAddCommand(getKey(), tuples, upsert, upsert, incr, true, lt);
170+
}
171+
172+
/**
173+
* Applies {@literal LT} mode. Constructs a new command
174+
* instance with all previously configured properties.
175+
*
176+
* @return a new {@link ZAddCommand} with {@literal incr} applied.
177+
* @since 2.5
178+
*/
179+
public ZAddCommand lt() {
180+
return new ZAddCommand(getKey(), tuples, upsert, upsert, incr, gt, true);
155181
}
156182

157183
/**
@@ -175,6 +201,23 @@ public boolean isIncr() {
175201
return incr;
176202
}
177203

204+
/**
205+
*
206+
* @return {@literal true} if {@literal GT} is set.
207+
* @since 2.5
208+
*/
209+
public boolean isGt() {
210+
return gt;
211+
}
212+
213+
/**
214+
* @return {@literal true} if {@literal LT} is set.
215+
* @since 2.5
216+
*/
217+
public boolean isLt() {
218+
return lt;
219+
}
220+
178221
/**
179222
* @return
180223
*/

0 commit comments

Comments
 (0)