set
写单行数据
///
/// \brief set
/// store the k-v to the cluster.
/// key is composed of hashkey and sortkey.
/// \param hashkey
/// used to decide which partition to put this k-v
/// \param sortkey
/// all the k-v under hashkey will be sorted by sortkey.
/// \param value
/// the value we want to store.
/// \param timeout_milliseconds
/// if wait longer than this value, will return time out error
/// \param ttl_seconds
/// time to live of this value, if expired, will return not found; 0 means no ttl
/// \return
/// int, the error indicates whether or not the operation is succeeded.
/// this error can be converted to a string using get_error_string()
///
virtual int set(const std::string &hashkey,
const std::string &sortkey,
const std::string &value,
int timeout_milliseconds = 5000,
int ttl_seconds = 0,
internal_info *info = NULL) = 0;
注:
- internal_info 结构如下,主要是记录在写入成功之后,该条数据的一些信息,在使用之前需要判断info是否为空
struct internal_info
{
int32_t app_id;
int32_t partition_index;
int64_t decree;
std::string server;
internal_info() : app_id(-1), partition_index(-1), decree(-1) {}
}
- 返回值:int值来表示是否成功,通过get_error_string() 函数来判断返回值的意义(下面的所有同步接口的返回值,都可以通过该函数判断返回值意义)
///
/// \brief get_error_string
/// get error string
/// all the function above return an int value that indicates an error can be converted into a
/// string for human reading.
/// \param error_code
/// all the error code are defined in "error_def.h"
/// \return
///
virtual const char *get_error_string(int error_code) const = 0;