Skip to content
Draft
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
31 changes: 31 additions & 0 deletions src/main/java/com/basho/riak/client/api/commands/kv/ListKeys.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright 2013 Basho Technologies Inc
* Copyright 2022-2026 Workday, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -78,11 +79,13 @@ public final class ListKeys extends StreamableRiakCommand.StreamableRiakCommandW
{
private final Namespace namespace;
private final int timeout;
private final int keysLimit;

ListKeys(Builder builder) throws ListException
{
this.namespace = builder.namespace;
this.timeout = builder.timeout;
this.keysLimit = builder.keysLimit;

if (!builder.allowListing)
{
Expand Down Expand Up @@ -113,6 +116,11 @@ protected ListKeysOperation buildCoreOperation(boolean streamResults)
builder.withTimeout(timeout);
}

if (keysLimit > 0)
{
builder.withKeysLimit(keysLimit);
}

builder.streamResults(streamResults);

return builder.build();
Expand Down Expand Up @@ -169,6 +177,7 @@ public static class Builder
{
private final Namespace namespace;
private int timeout;
private int keysLimit;
private boolean allowListing;

/**
Expand Down Expand Up @@ -214,6 +223,23 @@ public Builder withTimeout(int timeout)
return this;
}

/**
* Limit the number of keys returned by the server.
* <p>
* When set, Riak returns at most {@code keysLimit} keys. Any keys up
* to the limit may be returned, in no particular order, and two
* identical requests may return different key sets.
* A non-positive value means unlimited (the field is not sent).
* </p>
* @param keysLimit the maximum number of keys to return.
* @return a reference to this object.
*/
public Builder withKeysLimit(int keysLimit)
{
this.keysLimit = keysLimit;
return this;
}

/**
* Construct the ListKeys command.
* @return A ListKeys command.
Expand All @@ -231,6 +257,7 @@ public int hashCode()
int result = 1;
result = prime * result + (namespace != null ? namespace.hashCode() : 0);
result = prime * result + timeout;
result = prime * result + keysLimit;
return result;
}

Expand Down Expand Up @@ -259,6 +286,10 @@ public boolean equals(Object obj)
{
return false;
}
if (this.keysLimit != other.keysLimit)
{
return false;
}
return true;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright 2013 Basho Technologies Inc
* Copyright 2022-2026 Workday, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -114,6 +115,29 @@ public Builder withTimeout(int timeout)
return this;
}

/**
* Limit the number of keys returned by the server.
* <p>
* When set, Riak returns at most {@code keysLimit} keys. Any keys up
* to the limit may be returned, in no particular order, and two
* identical requests may return different key sets.
* A value of 0 means unlimited so is not a legal value here.
* Builder rejects non-positive values.
* Omit the call for unlimited.
* </p>
* @param keysLimit the maximum number of keys to return (must be &gt; 0).
* @return a reference to this object.
*/
public Builder withKeysLimit(int keysLimit)
{
if (keysLimit <= 0)
{
throw new IllegalArgumentException("Keys limit can not be zero or less");
}
reqBuilder.setKeysLimit(keysLimit);
return this;
}

/**
* Set the streamResults flag.
*
Expand Down