当前位置: 首页>>代码示例>>C++>>正文


C++ DB::Get方法代码示例

本文整理汇总了C++中DB::Get方法的典型用法代码示例。如果您正苦于以下问题:C++ DB::Get方法的具体用法?C++ DB::Get怎么用?C++ DB::Get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DB的用法示例。


在下文中一共展示了DB::Get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Process

        virtual void Process(){
            string key = client_->cmd_part[1];
            string val;
            if(db.Get(key, &val))
                sprintf(client_->writebuf, "VALUE %s %d\r\n%s\r\n", 
                        key.c_str(), (int)key.length(), val.c_str());
            else
                sprintf(client_->writebuf, "NOT_FOUND\r\n");

            get_ready_to_write(client_);
        }
开发者ID:zhangbiao2009,项目名称:code_excercise,代码行数:11,代码来源:server.cpp

示例2: main

int main(int argc, char** argv) {
    srand (time(NULL));

    if(argc != 3){
        cout<<"invalid parameter!!"<<endl;
        return 0;
    }
    string key, val;
    int type = atoi(argv[1]);
    int counter = 0;

    if(type == 3){
        key = argv[2];
    }
    else{
        counter = atoi(argv[2]);
    }

    cout<<"type:"<<type<<endl;
    cout<<"counter:"<<counter<<endl;


  DB* db;
  Options options;
  // Optimize RocksDB. This is the easiest way to get RocksDB to perform well
  options.IncreaseParallelism();
  options.OptimizeLevelStyleCompaction();
  // create the DB if it's not already present
  options.create_if_missing = true;

  // open DB
  Status s = DB::Open(options, kDBPath, &db);
  assert(s.ok());


  if(type == 3){
      s = db->Get(ReadOptions(), key, &val);
      cout<<"ret:"<<val<<endl;
  }
  else if(type == 1){
      time_t now = time(NULL);
      for(int i = 0; i < counter ; i++){
          key = "key_" + boost::lexical_cast<string>(i);
          val = "val_" + boost::lexical_cast<string>(i)+"_" +boost::lexical_cast<string>(now);

          s = db->Put(WriteOptions(), key, val);
      }
  }
  else if(type == 2){
      int k;
      for(int i = 0; i < counter ; i++){
          k = rand() % counter;

          key = "key_" + boost::lexical_cast<string>(k);

          s = db->Get(ReadOptions(), key, &val);
      }
      cout<<key<<":"<<val<<endl;
  }
    delete db;
    return 0;
}
开发者ID:zoozo,项目名称:test,代码行数:62,代码来源:test.cpp

示例3: fsck

int fsck(int argc, char** argv) {
  const char* path;

  if(argc == 2) {
    path = argv[1];
  } else {
    path = "./harq.db";
  }

  std::cout << "Checking " << path << "...\n";

  Options opts;
  opts.paranoid_checks = true;

  ReadOptions ro;
  ro.verify_checksums = true;

  DB* db;
  Status s = DB::Open(opts, path, &db);
  if(!s.ok()) {
    std::cout << "Unable to open: " << s.ToString() << "\n";
    return 1;
  }

  std::string val;
  wire::QueueConfiguration cfg;

  s = db->Get(ro, "!harq.config", &val);
  if(!s.ok()) {
    std::cout << "Unable to read configuration: " << s.ToString() << "\n";
    return 1;
  }

  if(!cfg.ParseFromString(val)) {
    std::cout << "Corrupt configuration detected.\n";
    return 1;
  }

  std::cout << cfg.queues_size() << " queues detected.\n";

  bool some_bad = false;

  for(int i = 0; i < cfg.queues_size(); i++) {
    const wire::QueueDeclaration& decl = cfg.queues(i);

    std::cout << "name: " << decl.name() << "\n";

    switch(decl.type()) {
    case wire::QueueDeclaration::eBroadcast:
      std::cout << "  type: broadcast\n";
      break;
    case wire::QueueDeclaration::eTransient:
      std::cout << "  type: transient\n";
      break;
    case wire::QueueDeclaration::eDurable:
      std::cout << "  type: durable\n";
      break;
    default:
      std::cout << "  type: UNKNOWN(" << decl.type() << ")\n";
      break;
    }

    s = db->Get(ro, decl.name(), &val);
    if(!s.ok()) {
      std::cout << "  Unable to find queue on disk!\n";
    } else {
      wire::Queue qi;
      if(!qi.ParseFromString(val)) {
        std::cout << "  Queue information corrupt on disk!\n";
      } else {
        std::cout << "  total messages: " << qi.size() << "\n"
                  << "  ranges:\n";

        for(int j = 0; j < qi.ranges_size(); j++) {
          const wire::MessageRange& range = qi.ranges(j);
          std::cout << "    " << range.start() << " - "
                    << range.start() + range.count() << "\n";
        }

        int valid = 0;

        for(int j = 0; j < qi.ranges_size(); j++) {
          const wire::MessageRange& range = qi.ranges(j);

          int fin = range.start() + range.count();

          for(int m = range.start(); m < fin; m++) {
            std::stringstream tmp;
            tmp << decl.name() << ":" << m;

            s = db->Get(ro, tmp.str(), &val);
            if(!s.ok()) {
              std::cerr << "Missing message '" << tmp.str() << "'\n";
            } else {
              wire::Message msg;
              if(!msg.ParseFromString(val)) {
                some_bad = true;
                std::cerr << "Corrupt message detected '" << tmp.str() << "'\n";
              } else {
                valid++;
//.........这里部分代码省略.........
开发者ID:evanphx,项目名称:harq,代码行数:101,代码来源:fsck.cpp


注:本文中的DB::Get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。