Skip to content

ZSet 浮点数精度丢失问题 #939

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
trynocoding opened this issue Mar 21, 2025 · 2 comments
Open

ZSet 浮点数精度丢失问题 #939

trynocoding opened this issue Mar 21, 2025 · 2 comments
Labels
type: question Further information is requested

Comments

@trynocoding
Copy link
Contributor

问题描述(Issue Description)

在使用 RedisShake 迁移 Redis 数据时,发现 ZSet 类型的 score 值出现精度丢失问题。

环境信息(Environment)

  • RedisShake 版本(v4.3.2):
  • Redis 源端版本(v7.2.4):
  • Redis 目的端版本(v7.2.4):
  • Redis 部署方式(standalone):

RedisShake 日志信息

{"level":"debug","time":"2025-03-21T11:00:52+08:00","message":"function before: zadd test_key_17605 0.097932 QAkRRSnlno0nkJQt0k7O3euWdV95lCZYHqaZ"}
{"level":"debug","time":"2025-03-21T11:00:52+08:00","message":"function after: [zadd test_key_17605 0.097932 QAkRRSnlno0nkJQt0k7O3euWdV95lCZYHqaZ]"}
{"level":"debug","time":"2025-03-21T11:00:52+08:00","message":"[writer_127.0.0.1_6380] send cmd. cmd=[zadd test_key_17605 0.097932 QAkRRSnlno0nkJQt0k7O3euWdV95lCZYHqaZ]"}

其他信息(Additional Information)

源实例:
127.0.0.1:6380> zrange test_key_17605 0 -1 WITHSCORES
 1) "QAkRRSnlno0nkJQt0k7O3euWdV95lCZYHqaZ"
 2) "0.09793150749791057"

o.cmdC <- RedisCmd{"zadd", o.key, fmt.Sprintf("%f", score), member}

在处理 ZSet 数据时使用了 fmt.Sprintf("%f", score) 格式化浮点数,这种格式化方式默认只保留 6 位小数,导致精度丢失。

@trynocoding trynocoding added the type: question Further information is requested label Mar 21, 2025
@suxb201
Copy link
Member

suxb201 commented Mar 21, 2025

是这样的👍 有兴趣帮修一下吗

@trynocoding
Copy link
Contributor Author

是这样的👍 有兴趣帮修一下吗

好的,我修下

trynocoding added a commit to trynocoding/RedisShake that referenced this issue Mar 21, 2025
…e#939)

This commit resolves the ZSET score truncation issue caused by using `%f` format specifier, which led to loss of precision for double values.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants