diff --git a/src/storage/rdb.cc b/src/storage/rdb.cc index 544e679ff64..95a9a757cc1 100644 --- a/src/storage/rdb.cc +++ b/src/storage/rdb.cc @@ -157,7 +157,7 @@ StatusOr RDB::loadEncodedString() { unsigned char buf[4] = {0}; if (len == RDBEncInt8) { auto next = GET_OR_RET(stream_->ReadByte()); - return std::to_string(static_cast(next)); + return std::to_string(static_cast(next)); } else if (len == RDBEncInt16) { GET_OR_RET(stream_->Read(reinterpret_cast(buf), 2)); auto value = static_cast(buf[0]) | (static_cast(buf[1]) << 8); diff --git a/tests/gocase/unit/dump/dump_test.go b/tests/gocase/unit/dump/dump_test.go index 154891c3f07..ea2625f06e9 100644 --- a/tests/gocase/unit/dump/dump_test.go +++ b/tests/gocase/unit/dump/dump_test.go @@ -167,3 +167,29 @@ func TestDump_Bitset(t *testing.T) { require.NoError(t, rdb.RestoreReplace(ctx, restoredKey, 0, serialized).Err()) require.Equal(t, rdb.Get(ctx, key).Val(), rdb.Get(ctx, restoredKey).Val()) } + +func TestDump_IntegerEncoding(t *testing.T) { + srv := util.StartServer(t, map[string]string{}) + defer srv.Close() + + ctx := context.Background() + rdb := srv.NewClient() + defer func() { require.NoError(t, rdb.Close()) }() + + values := []int64{ + 0, 1, -1, 127, -128, 128, -129, 129, + 32767, -32768, 32768, -32769, + 2147483647, -2147483648, 2147483648, -2147483649, + } + for i, v := range values { + key := fmt.Sprintf("key_%d", i) + require.NoError(t, rdb.Set(ctx, key, v, 0).Err()) + serialized, err := rdb.Dump(ctx, key).Result() + require.NoError(t, err) + restoreKey := fmt.Sprintf("restore_%s", key) + require.NoError(t, rdb.Restore(ctx, restoreKey, 0, serialized).Err()) + got, err := rdb.Get(ctx, restoreKey).Int64() + require.NoError(t, err) + require.Equal(t, v, got) + } +}