question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Get Query for Retrieving all Keys

See original GitHub issue

What is the equivalent KV client query for performing the following operation to retrieve all keys?

etcdctl get "" --prefix=true

I tried the following query, it didn’t work.

 CompletableFuture<GetResponse> futureResponse =
      client.getKVClient().get(ByteSequence.fromString(""),
          GetOption.newBuilder().withPrefix(ByteSequence.fromString("true")).build());

 GetResponse response = futureResponse.get();

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
indrabasakcommented, May 30, 2018

Here is a complete example using withRange:

@Override
public Map<String, String> findAllKeys() {
    try {
        ByteSequence key = ByteSequence.fromString("\0");
        GetOption option = GetOption.newBuilder()
                .withSortField(GetOption.SortTarget.KEY)
                .withSortOrder(GetOption.SortOrder.DESCEND)
                .withRange(key)
                .build();

        CompletableFuture<GetResponse> futureResponse =
                client.getKVClient().get(key, option);

        GetResponse response = futureResponse.get();
        if (response.getKvs().isEmpty()) {
            log.info("Failed to retrieve any key.");
            return null;
        }


        Map<String, String> keyValueMap = new HashMap<>();
        for (KeyValue kv : response.getKvs()) {
            keyValueMap.put(kv.getKey().toStringUtf8(),
                    kv.getValue().toStringUtf8());
        }

        log.info("Retrieved " + response.getKvs().size() + " keys.");

        return keyValueMap;

    } catch (Exception e) {
        throw new DatabaseException(
                "Failed to retrieve any key.", e);
    }
}
2reactions
xiang90commented, Dec 29, 2017

we probably need to document this somewhere, or provide a const to make it clear.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Get All Keys in Redis | Tutorial by Chartio
Retrieving All Existing Keys ... By following KEYS with an asterisk ( * ) – which acts as a wildcard search – we're...
Read more >
Redis command to get all available keys? - Stack Overflow
Try to look at KEYS command. KEYS * will list all keys stored in redis. EDIT: please note the warning at the top...
Read more >
How can I see All Redis Keys - Linux Hint
Redis GET all Keys ... To list the keys in the Redis data store, use the KEYS command followed by a specific pattern....
Read more >
How To Get All QueryString Keys In ASP.NET - C# Corner
This blog describes what is QueryString and how to get all QueryString values in ASP.NET page.
Read more >
KEYS - Redis
Find all keys matching the given pattern.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found