-
Notifications
You must be signed in to change notification settings - Fork 65
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
Java: Add SETRANGE
command.
#1235
Changes from 5 commits
5a93bc4
5075877
8298cb2
a7e9c2c
7906e36
163859d
1769fd5
7568dea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,6 +143,7 @@ enum RequestType { | |
Blpop = 100; | ||
RPushX = 102; | ||
LPushX = 103; | ||
SetRange = 107; | ||
} | ||
|
||
message Command { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -199,4 +199,26 @@ public interface StringBaseCommands { | |
* }</pre> | ||
*/ | ||
CompletableFuture<Long> strlen(String key); | ||
|
||
/** | ||
* Overwrites part of the string stored at <code>key</code>, starting at the specified <code> | ||
* offset</code>, for the entire length of <code>value</code>.<br> | ||
* If the <code>offset</code> is larger than the current length of the string at <code>key</code>, | ||
* the string is padded with zero bytes to make <code>offset</code> fit. Creates the <code>key | ||
* </code> if it doesn't exist. | ||
* | ||
* @see <a href="https://redis.io/commands/setrange/">redis.io</a> for details. | ||
* @param key The key of the string to update. | ||
* @param offset The position in the string where <code>value</code> should be written. | ||
* @param value The string written with <code>offset</code>. | ||
* @return The length of the string stored at <code>key</code> after it was modified. | ||
* @example | ||
* <pre>{@code | ||
* long len = client.setrange("key", 6, "GLIDE").get(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't it be Long? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @acarbonetto There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated. Both are ok and compilable |
||
* assert len == 11L; // Wew key was created with length of 11 symbols | ||
Yury-Fridlyand marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* String value = client.get("key").get(); | ||
* assert value.equals("\0\0\0\0\0\0GLIDE"); // The string was padded with zero bytes | ||
* }</pre> | ||
*/ | ||
CompletableFuture<Long> setrange(String key, int offset, String value); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,6 +83,7 @@ | |
import static redis_request.RedisRequestOuterClass.RequestType.SMembers; | ||
import static redis_request.RedisRequestOuterClass.RequestType.SRem; | ||
import static redis_request.RedisRequestOuterClass.RequestType.Select; | ||
import static redis_request.RedisRequestOuterClass.RequestType.SetRange; | ||
import static redis_request.RedisRequestOuterClass.RequestType.SetString; | ||
import static redis_request.RedisRequestOuterClass.RequestType.Strlen; | ||
import static redis_request.RedisRequestOuterClass.RequestType.TTL; | ||
|
@@ -975,6 +976,32 @@ public void strlen_returns_success() { | |
assertEquals(value, payload); | ||
} | ||
|
||
@SneakyThrows | ||
@Test | ||
public void setrange_returns_success() { | ||
// setup | ||
String key = "testKey"; | ||
int offset = 42; | ||
String str = "pewpew"; | ||
String[] arguments = new String[] {key, Integer.toString(offset), str}; | ||
Long value = 10L; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor: value -> responseValue (value is confusing in the key-value context) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are 99 tests in this file and almost all of them have variable named "value". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
CompletableFuture<Long> testResponse = new CompletableFuture<>(); | ||
testResponse.complete(value); | ||
|
||
// match on protobuf request | ||
when(commandManager.<Long>submitNewCommand(eq(SetRange), eq(arguments), any())) | ||
.thenReturn(testResponse); | ||
|
||
// exercise | ||
CompletableFuture<Long> response = service.setrange(key, offset, str); | ||
Long payload = response.get(); | ||
|
||
// verify | ||
assertEquals(testResponse, response); | ||
assertEquals(value, payload); | ||
} | ||
|
||
@SneakyThrows | ||
@Test | ||
public void hget_success() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
key
holds a value that is not a string, an error is returned.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do not document error cases for all commands to keep docs easy.
This comment is applicable to all commands - do you want to add it to a common place? readme?