Skip to content

Commit

Permalink
Minor documentation update + changed param from int to long + minor I…
Browse files Browse the repository at this point in the history
…T update.
  • Loading branch information
SanHalacogluImproving committed Apr 5, 2024
1 parent 8a320f1 commit 3be63d8
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
4 changes: 2 additions & 2 deletions java/client/src/main/java/glide/api/BaseClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,9 @@ public CompletableFuture<String[]> lrange(@NonNull String key, long start, long
}

@Override
public CompletableFuture<String> lindex(@NonNull String key, int index) {
public CompletableFuture<String> lindex(@NonNull String key, long index) {
return commandManager.submitNewCommand(
Lindex, new String[] {key, Integer.toString(index)}, this::handleStringOrNullResponse);
Lindex, new String[] {key, Long.toString(index)}, this::handleStringOrNullResponse);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public interface ListBaseCommands {
CompletableFuture<String[]> lrange(String key, long start, long end);

/**
* Returns the element at <code>index</code> in the list stored at <code>key</code>.<br>
* Returns the element at <code>index</code> from the list stored at <code>key</code>.<br>
* The index is zero-based, so <code>0</code> means the first element, <code>1</code> the second
* element and so on. Negative indices can be used to designate elements starting at the tail of
* the list. Here, <code>-1</code> means the last element, <code>-2</code> means the penultimate
Expand All @@ -124,7 +124,7 @@ public interface ListBaseCommands {
* assert payload2.equals('value3'); // Returns the last element in the list stored at 'myList'.
* }</pre>
*/
CompletableFuture<String> lindex(String key, int index);
CompletableFuture<String> lindex(String key, long index);

/**
* Trims an existing list so that it will contain only the specified range of elements specified.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ public T lrange(@NonNull String key, long start, long end) {
}

/**
* Returns the element at <code>index</code> in the list stored at <code>key</code>.<br>
* Returns the element at <code>index</code> from the list stored at <code>key</code>.<br>
* The index is zero-based, so <code>0</code> means the first element, <code>1</code> the second
* element and so on. Negative indices can be used to designate elements starting at the tail of
* the list. Here, <code>-1</code> means the last element, <code>-2</code> means the penultimate
Expand All @@ -584,8 +584,8 @@ public T lrange(@NonNull String key, long start, long end) {
* If <code>index</code> is out of range or if <code>key</code> does not exist, <code>null
* </code> is returned.
*/
public T lindex(@NonNull String key, int index) {
ArgsArray commandArgs = buildArgs(key, Integer.toString(index));
public T lindex(@NonNull String key, long index) {
ArgsArray commandArgs = buildArgs(key, Long.toString(index));

protobufTransaction.addCommands(buildCommand(Lindex, commandArgs));
return getThis();
Expand Down
4 changes: 2 additions & 2 deletions java/client/src/test/java/glide/api/RedisClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1089,8 +1089,8 @@ public void lrange_returns_success() {
public void lindex_returns_success() {
// setup
String key = "testKey";
int index = 2;
String[] args = new String[] {key, Integer.toString(index)};
long index = 2;
String[] args = new String[] {key, Long.toString(index)};
String value = "value";

CompletableFuture<String> testResponse = new CompletableFuture<>();
Expand Down
5 changes: 3 additions & 2 deletions java/integTest/src/test/java/glide/SharedCommandTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -593,10 +593,11 @@ public void lindex(BaseClient client) {

assertEquals(2, client.lpush(key1, valueArray).get());
assertEquals(valueArray[1], client.lindex(key1, 0).get());
assertEquals(valueArray[0], client.lindex(key1, 1).get());
assertEquals(valueArray[0], client.lindex(key1, -1).get());
assertNull(client.lindex(key1, 3).get());
assertNull(client.lindex("nonExistingKey", 3).get());
assertNull(client.lindex(key2, 3).get());

// Key exists, but it is not a List
assertEquals(OK, client.set(key2, "value").get());
Exception executionException =
assertThrows(ExecutionException.class, () -> client.lindex(key2, 0).get());
Expand Down

0 comments on commit 3be63d8

Please sign in to comment.