set

写单行数据

  1. ///
  2. /// \brief set
  3. /// store the k-v to the cluster.
  4. /// key is composed of hashkey and sortkey.
  5. /// \param hashkey
  6. /// used to decide which partition to put this k-v
  7. /// \param sortkey
  8. /// all the k-v under hashkey will be sorted by sortkey.
  9. /// \param value
  10. /// the value we want to store.
  11. /// \param timeout_milliseconds
  12. /// if wait longer than this value, will return time out error
  13. /// \param ttl_seconds
  14. /// time to live of this value, if expired, will return not found; 0 means no ttl
  15. /// \return
  16. /// int, the error indicates whether or not the operation is succeeded.
  17. /// this error can be converted to a string using get_error_string()
  18. ///
  19. virtual int set(const std::string &hashkey,
  20. const std::string &sortkey,
  21. const std::string &value,
  22. int timeout_milliseconds = 5000,
  23. int ttl_seconds = 0,
  24. internal_info *info = NULL) = 0;

注:

  • internal_info 结构如下,主要是记录在写入成功之后,该条数据的一些信息,在使用之前需要判断info是否为空
  1. struct internal_info
  2. {
  3. int32_t app_id;
  4. int32_t partition_index;
  5. int64_t decree;
  6. std::string server;
  7. internal_info() : app_id(-1), partition_index(-1), decree(-1) {}
  8. }
  • 返回值:int值来表示是否成功,通过get_error_string() 函数来判断返回值的意义(下面的所有同步接口的返回值,都可以通过该函数判断返回值意义)
  1. ///
  2. /// \brief get_error_string
  3. /// get error string
  4. /// all the function above return an int value that indicates an error can be converted into a
  5. /// string for human reading.
  6. /// \param error_code
  7. /// all the error code are defined in "error_def.h"
  8. /// \return
  9. ///
  10. virtual const char *get_error_string(int error_code) const = 0;