-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
zAdd does not set the correct score for values 1000 & above #113
Comments
Thank, I'll have a look today. |
Hello, I have just tested this without any issue. Do think the problem might be with the return value of microtime()? “By default, microtime() returns a string in the form "msec sec", where sec is the current time measured in the number of seconds since the Unix epoch (0:00:00 January 1, 1970 GMT), and msec is the number of microseconds that have elapsed since sec expressed in seconds.” If you want a floating point value, use $ cat test.php <?php $redis = new Redis; $redis->connect('127.0.0.1', 6379); $redis->del('test'); $t = microtime(true); $redis->zadd('test', $t, 'x'); var_dump($t, $redis->zrange('test', 0, -1, true)); ?> $ php test.php float(1324923009.7921) array(1) { ["x"]=> string(17) "1324923009.792141" } (redis-cli) 1324923009.792088 "DEL" "test" 1324923009.792215 "ZADD" "test" "1324923009.79214096" "x" 1324923009.792290 "ZRANGE" "test" "0" "-1" "WITHSCORES" Would you have some example code that fails to send the right command? I also tried 1000, and it was sent as expected. |
Here's the code that I used to attempt this. I was trying to port the login times from MySQL to Redis, so I was testing at each step. Still getting the same issue. I'm using Redis Server 2.4.5 & version 2.1.3 of phpredis on a 64 bit machine. By the looks of it, for some reason it's the API that's sending the wrong value since the Monitor picks up only the first digit. Let me know if you want me to do any further testing.
Output on web:
Redis-Cli Monitor:
|
Could you please try the latest version of phpredis? This is the output from your code: array(3) { [0]=> int(1) [1]=> int(1) [2]=> array(2) { ["Niro"]=> string(18) "1324925309.8650861" ["Another"]=> string(18) "1324925309.8652489" } } redis-cli monitor: 1324925366.509590 "monitor" 1324925367.841260 "ZADD" "login_time" "1324925367.84114599" "Niro" 1324925367.841368 "ZADD" "login_time" "1324925367.84132099" "Another" 1324925367.841457 "ZRANGE" "login_time" "0" "-1" "WITHSCORES" |
I just ran your code, and I'm getting the same wrong score.
|
I have found the problem and it's weird. I was using the 3rd Release Candidate of PHP 5.4. Downgrading to version 5.3.3 fixed the problem. Not quite sure why that would cause a problem. |
Thanks for looking into it. I'll try PHP 5.4 to figure out what the issue is. |
Thank you, Nicolas. Please don't hesitate to ask if you want me to verify anything. |
Hi, @derniro phpredis use http://jp2.php.net/manual/en/function.number-format.php
you can reproduce above code. let me try latest php5.4. i'll report php bug tracker if that still has issue. |
it reproduced latest 5.4. so I reported that. thx. |
Thanks Chobie, looks like I'll be sticking with php 5.3 for a while. |
Is there any progress on this issue? Currently it makes Redis::zAdd() nearly useless in php-5.4. |
I would like to know also, any progress on this issue with php 5.4? |
Sorry guys, I completely forget about this. Short time solution: you can fix this issue with this patch. _php_math_number_format API has broken on PHP5.4. So we have to use another function to convert double to char*. |
Thanks @chobie - closing this ticket now that a workaround has been provided for this PHP bug. |
Hi,
I've been using your API for Redis for a few days now and it's the best by far. It leaves a tiny footprint and has all the functions I need. Keep up the great work.
Now to the bug I came across. When creating a Sorted Set, the score is not properly set when using zAdd. If the score is 1000 or above, the score changes to the first digit only.
PHP Script:
$redis->zAdd('anothertest',1000,'work');
Redis-Cli Monitor:
1324885452.287708 "ZADD" "anothertest" "1" "work"
I've tested it with smaller values (including decimal values) and it's working just fine. Casting the value as a string has the same effect. The score range I was trying to set was the microtime. Redis seems to be able to work with values that high, so I'm pretty sure there's a minor bug somewhere in the API.
If you need more info, let me know.
Testing Machine:
64bit Centos 6.0
The text was updated successfully, but these errors were encountered: