首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从voldemort存储中一次获取所有键值对?

如何从voldemort存储中一次获取所有键值对?
EN

Stack Overflow用户
提问于 2011-11-26 22:31:45
回答 1查看 1.5K关注 0票数 2
代码语言:javascript
复制
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());

现在,如何一次从存储中获取所有键-值对?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-11-27 00:32:51

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

代码语言:javascript
复制
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);
    }

}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8279113

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档