const std::string& ToString(std::string& str) const { switch (type) { case EMPTY: { str = ""; return str; } case INTEGER: { Buffer tmp(64); tmp.Printf("%lld", v.int_v); str.assign(tmp.GetRawReadBuffer(), tmp.ReadableBytes()); return str; } case DOUBLE: { fast_dtoa(v.double_v, 10, str); return str; } default: { str.assign(v.raw->GetRawReadBuffer(), v.raw->ReadableBytes()); return str; } } }
int Ardb::HIncrbyFloat(Context& ctx, RedisCommandFrame& cmd) { double increment, val = 0; if (!GetDoubleValue(ctx, cmd.GetArguments()[2], increment)) { return 0; } ValueObject meta; int err = GetMetaValue(ctx, cmd.GetArguments()[0], HASH_META, meta); CHECK_ARDB_RETURN_VALUE(ctx.reply, err); Data value; Data field(cmd.GetArguments()[1]); if (0 == err) { HashGet(ctx, meta, field, value); if (!value.GetDouble(val)) { fill_error_reply(ctx.reply, "value is not a float or out of range"); return 0; } } val += increment; std::string tmp; fast_dtoa(val, 10, tmp); value.SetString(tmp, false); HashSet(ctx, meta, field, value); fill_str_reply(ctx.reply, tmp); return 0; }