gpt4 book ai didi

java - 如何从伏地魔商店一次获取所有键值对?

转载 作者:行者123 更新时间:2023-12-04 06:06:34 25 4
gpt4 key购买 nike

int maxThreads = 300;
ClientConfig clientConfig = new ClientConfig();
clientConfig.setMaxThreads(maxThreads);
clientConfig.setMaxConnectionsPerNode(maxThreads);
clientConfig.setConnectionTimeout(500, TimeUnit.MILLISECONDS);
clientConfig.setBootstrapUrls(env.getVoldemortAddress());

StoreClientFactory factory = new SocketStoreClientFactory(clientConfig);
StoreClient<String, String> client = factory.getStoreClient(env.getPrefixStoreName());

现在怎么做才能一次从存储中获取所有键值对?

最佳答案

您必须使用 AdminClient获取所有 key 。此类旨在用于有用且经常需要的管理功能,但在应用程序级别应谨慎使用(如果有的话)。 See here.

public static void main(String [] args) {

String bootStrapUrl = "tcp://localhost:6666";
String storeName = "test";

int maxThreads = 300;
ClientConfig clientConfig = new ClientConfig();
clientConfig.setMaxThreads(maxThreads);
clientConfig.setMaxConnectionsPerNode(maxThreads);
clientConfig.setConnectionTimeout(500, TimeUnit.MILLISECONDS);
clientConfig.setBootstrapUrls(bootStrapUrl);

StoreClientFactory factory = new SocketStoreClientFactory(clientConfig);
StoreClient<String, String> client = factory.getStoreClient(storeName);

int nodeId = 0;
List<Integer> partitionList = new ArrayList<Integer>();
partitionList.add(0);
partitionList.add(1);
AdminClient adminClient = new AdminClient(bootStrapUrl, new AdminClientConfig());
Iterator<ByteArray> iterator = adminClient.fetchKeys(nodeId, storeName, partitionList, null);

String key = null;
String value = null;
while (iterator.hasNext()) {
key = new String(iterator.next().get());
value = client.getValue(key);
System.out.println("Key-Value-Pair::" + key + ":" + value);
}

}

关于java - 如何从伏地魔商店一次获取所有键值对?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8279113/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com