shadowspore / t38c

Tile38 Client package
MIT License
83 stars 33 forks source link

FSet is setting incorrect values in fields with very large values #51

Closed buddy-sandidge closed 1 year ago

buddy-sandidge commented 1 year ago

Hello,

I ran into an with setting a field with a very large value using FSet resulting in an incorrect value set in Tile38. The issue appears to be caused by the rounding configured in the floatString function. I suspect a fix might be as simple as updating the formatFloat function to be something like this instead.

func formatFloat(v float64) string {
    return strconv.FormatFloat(v, 'f', 0, 64)
}

An example of a failure case:

_ = client.Keys.JSet("test", "example", "key", "value").Do()
_ = client.Keys.FSet("test", "example").Field("id", 123456789012345680).Do()

The code will result in example having a field id set to 123456789000000000 instead of the expected value 123456789012345680. However, manually setting the field in the cli does give the expected results. This can be sen in the Tile38 cli:

127.0.0.1:9851> GET test example WITHFIELDS
{"ok":true,"object":"{\"key\":\"value\"}","fields":{"id":123456789000000000},"elapsed":"19.377µs"}
127.0.0.1:9851> FSET test example id 123456789012345680
{"ok":true,"elapsed":"9.808µs"}
127.0.0.1:9851> GET test example WITHFIELDS
{"ok":true,"object":"{\"key\":\"value\"}","fields":{"id":123456789012345680},"elapsed":"20.699µs"}

I can create a PR if needed; let me know if I should do anything besides adding a test case to TestKeys.

shadowspore commented 1 year ago

Fixed by https://github.com/shadowspore/t38c/pull/52 Thank you for sending a PR