Skip to content

Support ZADD Flags NX, XX, GT & LT #1988

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>2.5.0-SNAPSHOT</version>
<version>2.5.0-GH-1794-SNAPSHOT</version>

<name>Spring Data Redis</name>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1322,20 +1322,20 @@ public void watch(byte[]... keys) {

/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisZSetCommands#zAdd(byte[], double, byte[])
* @see org.springframework.data.redis.connection.RedisZSetCommands#zAdd(byte[], double, byte[], org.springframework.data.redis.connection.RedisZSetCommands.ZAddArgs)
*/
@Override
public Boolean zAdd(byte[] key, double score, byte[] value) {
return convertAndReturn(delegate.zAdd(key, score, value), Converters.identityConverter());
public Boolean zAdd(byte[] key, double score, byte[] value, ZAddArgs args) {
return convertAndReturn(delegate.zAdd(key, score, value, args), Converters.identityConverter());
}

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

/*
Expand Down Expand Up @@ -2686,20 +2686,20 @@ public Long touch(String... keys) {

/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.StringRedisConnection#zAdd(java.lang.String, double, java.lang.String)
* @see org.springframework.data.redis.connection.StringRedisConnection#zAdd(java.lang.String, double, java.lang.String, org.springframework.data.redis.connection.RedisZSetCommands.ZAddArgs)
*/
@Override
public Boolean zAdd(String key, double score, String value) {
return zAdd(serialize(key), score, serialize(value));
public Boolean zAdd(String key, double score, String value, ZAddArgs args) {
return zAdd(serialize(key), score, serialize(value), args);
}

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

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -873,15 +873,15 @@ default Cursor<byte[]> sScan(byte[] key, ScanOptions options) {
/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
@Override
@Deprecated
default Boolean zAdd(byte[] key, double score, byte[] value) {
return zSetCommands().zAdd(key, score, value);
default Boolean zAdd(byte[] key, double score, byte[] value, ZAddArgs args) {
return zSetCommands().zAdd(key, score, value, args);
}

/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
@Override
@Deprecated
default Long zAdd(byte[] key, Set<Tuple> tuples) {
return zSetCommands().zAdd(key, tuples);
default Long zAdd(byte[] key, Set<Tuple> tuples, ZAddArgs args) {
return zSetCommands().zAdd(key, tuples, args);
}

/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,20 @@ class ZAddCommand extends KeyCommand {
private final boolean upsert;
private final boolean returnTotalChanged;
private final boolean incr;
private final boolean gt;
private final boolean lt;

private ZAddCommand(@Nullable ByteBuffer key, List<Tuple> tuples, boolean upsert, boolean returnTotalChanged,
boolean incr) {
boolean incr, boolean gt, boolean lt) {

super(key);

this.tuples = tuples;
this.upsert = upsert;
this.returnTotalChanged = returnTotalChanged;
this.incr = incr;
this.gt = gt;
this.lt = lt;
}

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

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

return new ZAddCommand(null, new ArrayList<>(tuples), false, false, false);
return new ZAddCommand(null, new ArrayList<>(tuples), false, false, false, false, false);
}

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

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

return new ZAddCommand(key, tuples, upsert, returnTotalChanged, incr);
return new ZAddCommand(key, tuples, upsert, returnTotalChanged, incr, gt, lt);
}

/**
Expand All @@ -121,7 +125,7 @@ public ZAddCommand to(ByteBuffer key) {
* @return a new {@link ZAddCommand} with {@literal xx} applied.
*/
public ZAddCommand xx() {
return new ZAddCommand(getKey(), tuples, false, returnTotalChanged, incr);
return new ZAddCommand(getKey(), tuples, false, returnTotalChanged, incr, gt, lt);
}

/**
Expand All @@ -131,7 +135,7 @@ public ZAddCommand xx() {
* @return a new {@link ZAddCommand} with {@literal nx} applied.
*/
public ZAddCommand nx() {
return new ZAddCommand(getKey(), tuples, true, returnTotalChanged, incr);
return new ZAddCommand(getKey(), tuples, true, returnTotalChanged, incr, gt, lt);
}

/**
Expand All @@ -141,7 +145,7 @@ public ZAddCommand nx() {
* @return a new {@link ZAddCommand} with {@literal ch} applied.
*/
public ZAddCommand ch() {
return new ZAddCommand(getKey(), tuples, upsert, true, incr);
return new ZAddCommand(getKey(), tuples, upsert, true, incr, gt, lt);
}

/**
Expand All @@ -151,7 +155,29 @@ public ZAddCommand ch() {
* @return a new {@link ZAddCommand} with {@literal incr} applied.
*/
public ZAddCommand incr() {
return new ZAddCommand(getKey(), tuples, upsert, upsert, true);
return new ZAddCommand(getKey(), tuples, upsert, upsert, true, gt, lt);
}

/**
* Applies {@literal GT} mode. Constructs a new command
* instance with all previously configured properties.
*
* @return a new {@link ZAddCommand} with {@literal incr} applied.
* @since 2.5
*/
public ZAddCommand gt() {
return new ZAddCommand(getKey(), tuples, upsert, upsert, incr, true, lt);
}

/**
* Applies {@literal LT} mode. Constructs a new command
* instance with all previously configured properties.
*
* @return a new {@link ZAddCommand} with {@literal incr} applied.
* @since 2.5
*/
public ZAddCommand lt() {
return new ZAddCommand(getKey(), tuples, upsert, upsert, incr, gt, true);
}

/**
Expand All @@ -175,6 +201,23 @@ public boolean isIncr() {
return incr;
}

/**
*
* @return {@literal true} if {@literal GT} is set.
* @since 2.5
*/
public boolean isGt() {
return gt;
}

/**
* @return {@literal true} if {@literal LT} is set.
* @since 2.5
*/
public boolean isLt() {
return lt;
}

/**
* @return
*/
Expand Down
Loading