pmem / kvdk

Key Value Development Kit

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Will kvdk support other types of Key or value such as int64,selfdefined structure? [NEW]

jinhao2 opened this issue · comments

As a kv system, it may save any type of data except for std::basic_string_view, will kvdk support other types?
Following codes only support c-like string as input data, why not support any data with size ?

/**

  • Constructor initialized with data and its size.
  • @param[in] data pointer to the C-like string to initialize with,
  • it can contain null characters.
  • @param[in] size length of the given data.
    */
    template <typename CharT, typename Traits>
    constexpr inline basic_string_view<CharT, Traits>::basic_string_view(
    const CharT *data, size_type size)
    : data_(data), size_(size)
    {
    }

Thank you for submitting a question.
For now, KVDK doesn't have explicit support for integer values or custom data types. While you can store them with the current APIs, here is an example for your reference:

  std::string key{"key"};
  int int_value = 1024;
  std::string value{(char*)&int_value, sizeof(int)};
  std::string v;

  status = engine->Set(key, value);
  assert(status == kvdk::Status::Ok);
  std::cout << "set value = " << int_value << std::endl;

  status = engine->Get(key, &v);
  assert(status == kvdk::Status::Ok);
  assert(v == value);
  std::cout << "get value: " << *(int*)v.data() << std::endl;

OK, thanks for your reply.