Skip to content
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

Remove Request.nullArg() #462

Merged
merged 1 commit into from
Aug 8, 2024
Merged
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
35 changes: 8 additions & 27 deletions src/main/java/io/vertx/redis/client/Request.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ static Request cmd(Command command, Object... args) {
@Fluent
default Request arg(String arg) {
if (arg == null) {
return nullArg();
throw new IllegalArgumentException("Null argument not allowed");
}
return arg(arg.getBytes(StandardCharsets.UTF_8));
}
Expand All @@ -98,7 +98,7 @@ default Request arg(String arg) {
@Fluent
default Request arg(String arg, String enc) {
if (arg == null) {
return nullArg();
throw new IllegalArgumentException("Null argument not allowed");
}
return arg(arg.getBytes(Charset.forName(enc)));
}
Expand Down Expand Up @@ -190,23 +190,21 @@ default Request arg(double arg) {
/**
* Adds a JsonObject argument, the encoding will serialize the json as key0, value0, key1, value1, ... keyN, valueN.
* This is a non-optimized serialization and will just use the string encoding of the values for non buffers.
* <p>
* All {@code null} values will follow the encoding rules of {@link #nullArg()}.
*
* @return self
* @throws IllegalArgumentException when values are of type JsonArray or JsonObject
* @throws IllegalArgumentException when values are {@code null} or of type JsonArray or JsonObject
*/
@Fluent
default Request arg(JsonObject arg) {
if (arg == null) {
nullArg();
throw new IllegalArgumentException("Null argument not allowed");
} else {
for (Map.Entry<String, Object> kv : arg) {
arg(kv.getKey());
Object val = kv.getValue();

if (val == null) {
nullArg();
throw new IllegalArgumentException("Null argument not allowed");
} else if (val instanceof Buffer) {
arg((Buffer) val);
} else if (val instanceof JsonArray || val instanceof JsonObject) {
Expand All @@ -222,20 +220,18 @@ default Request arg(JsonObject arg) {
/**
* Adds a JsonArray argument, the encoding will serialize the json as value0, value1, ... valueN.
* This is a non-optimized serialization and will just use the string encoding of the values for non buffers.
* <p>
* All {@code null} values will follow the encoding rules of {@link #nullArg()}.
*
* @return self
* @throws IllegalArgumentException when values are of type JsonArray or JsonObject
* @throws IllegalArgumentException when values are {@code null} or of type JsonArray or JsonObject
*/
@Fluent
default Request arg(JsonArray arg) {
if (arg == null) {
nullArg();
throw new IllegalArgumentException("Null argument not allowed");
} else {
for (Object el : arg) {
if (el == null) {
nullArg();
throw new IllegalArgumentException("Null argument not allowed");
} else if (el instanceof Buffer) {
arg((Buffer) el);
} else if (el instanceof JsonArray || el instanceof JsonObject) {
Expand All @@ -248,21 +244,6 @@ default Request arg(JsonArray arg) {
return this;
}

/**
* @return self
* @deprecated REDIS does not support {@code null} as a parameter, only as response. This was a deviation from the
* official protocol which should be avoided. Other clients explicitly do not allow this.
* <p>
* Adds a {@code null} encoded string. Redis does not allow storing the {@code null} value by itself. This method
* will encode any null value as the four character long string {@code "null"}.
* <p>
* As a recommendation, this method should not be used directly unless this is the intented behavior. It is present
* to handle special cases such as encoding of {@link JsonObject} and {@link JsonArray} which may contain null values.
*/
@Fluent
@Deprecated
Request nullArg();

/**
* Get the Command that is to be used by this request.
*
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/vertx/redis/client/impl/RedisAPIImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public Future<Response> send(Command cmd, String... args) {
if (args != null) {
for (String o : args) {
if (o == null) {
req.nullArg();
throw new IllegalArgumentException("Null argument not allowed");
} else {
req.arg(o);
}
Expand Down
12 changes: 2 additions & 10 deletions src/main/java/io/vertx/redis/client/impl/RequestImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,20 +105,12 @@ public Request arg(boolean arg) {
return this;
}

// null

@Override
public Request nullArg() {
args.add(null);
return this;
}

// bulk string

@Override
public Request arg(byte[] arg) {
if (arg == null) {
return nullArg();
throw new IllegalArgumentException("Null argument not allowed");
}

args.add(arg);
Expand All @@ -128,7 +120,7 @@ public Request arg(byte[] arg) {
@Override
public Request arg(Buffer arg) {
if (arg == null) {
return nullArg();
throw new IllegalArgumentException("Null argument not allowed");
}

if (arg.length() == 0) {
Expand Down
11 changes: 6 additions & 5 deletions src/test/java/io/vertx/test/redis/RedisClient5Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.junit.runner.RunWith;

import static io.vertx.redis.client.Command.GET;
import static io.vertx.redis.client.Command.HGETALL;
import static io.vertx.redis.client.Command.HSET;
import static io.vertx.redis.client.Command.SET;
import static io.vertx.redis.client.Request.cmd;
Expand Down Expand Up @@ -78,13 +79,13 @@ public void testJson(TestContext should) {
final String mykey = randomKey();

JsonObject json = new JsonObject()
.putNull("nullKey");
.put("key", "value");

client.send(cmd(HSET).arg(mykey).arg(json))
.onSuccess(res -> {
System.out.println(res);
.compose(ignored -> client.send(cmd(HGETALL).arg(mykey)))
.onComplete(should.asyncAssertSuccess(value -> {
should.assertEquals("value", value.get("key").toString());
test.complete();
})
.onFailure(should::fail);
}));
}
}
10 changes: 5 additions & 5 deletions src/test/java/io/vertx/test/redis/RedisClient6Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,14 @@ public void testJson(TestContext should) {
final String mykey = randomKey();

JsonObject json = new JsonObject()
.putNull("nullKey");
.put("key", "value");

client.send(cmd(HSET).arg(mykey).arg(json))
.onSuccess(res -> {
System.out.println(res);
.compose(ignored -> client.send(cmd(HGETALL).arg(mykey)))
.onComplete(should.asyncAssertSuccess(value -> {
should.assertEquals("value", value.get("key").toString());
test.complete();
})
.onFailure(should::fail);
}));
}

@Test
Expand Down
10 changes: 5 additions & 5 deletions src/test/java/io/vertx/test/redis/RedisClient7Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,14 @@ public void testJson(TestContext should) {
final String mykey = randomKey();

JsonObject json = new JsonObject()
.putNull("nullKey");
.put("key", "value");

client.send(cmd(HSET).arg(mykey).arg(json))
.onSuccess(res -> {
System.out.println(res);
.compose(ignored -> client.send(cmd(HGETALL).arg(mykey)))
.onComplete(should.asyncAssertSuccess(value -> {
should.assertEquals("value", value.get("key").toString());
test.complete();
})
.onFailure(should::fail);
}));
}

@Test(timeout = 10_000L)
Expand Down
11 changes: 6 additions & 5 deletions src/test/java/io/vertx/test/redis/RedisClientPikaSecureTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.testcontainers.containers.GenericContainer;

import static io.vertx.redis.client.Command.GET;
import static io.vertx.redis.client.Command.HGETALL;
import static io.vertx.redis.client.Command.HSET;
import static io.vertx.redis.client.Command.SET;
import static io.vertx.redis.client.Request.cmd;
Expand Down Expand Up @@ -81,13 +82,13 @@ public void testJson(TestContext should) {
final String mykey = randomKey();

JsonObject json = new JsonObject()
.putNull("nullKey");
.put("key", "value");

client.send(cmd(HSET).arg(mykey).arg(json))
.onSuccess(res -> {
System.out.println(res);
.compose(ignored -> client.send(cmd(HGETALL).arg(mykey)))
.onComplete(should.asyncAssertSuccess(value -> {
should.assertEquals("value", value.get("key").toString());
test.complete();
})
.onFailure(should::fail);
}));
}
}
11 changes: 6 additions & 5 deletions src/test/java/io/vertx/test/redis/RedisClientPikaTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.testcontainers.containers.GenericContainer;

import static io.vertx.redis.client.Command.GET;
import static io.vertx.redis.client.Command.HGETALL;
import static io.vertx.redis.client.Command.HSET;
import static io.vertx.redis.client.Command.SET;
import static io.vertx.redis.client.Request.cmd;
Expand Down Expand Up @@ -79,13 +80,13 @@ public void testJson(TestContext should) {
final String mykey = randomKey();

JsonObject json = new JsonObject()
.putNull("nullKey");
.put("key", "value");

client.send(cmd(HSET).arg(mykey).arg(json))
.onSuccess(res -> {
System.out.println(res);
.compose(ignored -> client.send(cmd(HGETALL).arg(mykey)))
.onComplete(should.asyncAssertSuccess(value -> {
should.assertEquals("value", value.get("key").toString());
test.complete();
})
.onFailure(should::fail);
}));
}
}
Loading