-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Closed
Description
Expected behaviour
eval should be faster than running multiple commands separately and processing in PHP in between.
Actual behaviour
in CLI:
redis-cli SET mykey "HELLO;WORLD"
redis-cli SET HELLO "FOO"
redis-cli SET WORLD "BAR"
time for i in {1..1000}; do redis-cli MGET $(redis-cli GET mykey | sed -E 's/^([^;]+);(.+)$/\1 \2/') > /dev/null; done
time for i in {1..1000}; do redis-cli EVAL 'local value = redis.call( "GET", KEYS[1] ); local a, b = value:match( "^([^;]+);(.+)$" ); return redis.call( "MGET", a, b )' 1 mykey > /dev/null; done
EVAL is about 100% faster than running multiple commands (I used the inefficient "sed" on purpose to ensure it's not the regex causing it, using a more efficient sed 's/;/ /'
delivers the same results though)
In PHP the opposite is true though and eval is about 150% slower:
(same issue for evalSha/evalSha_ro and eval_ro, even though those are slightly faster than eval, still much slower)
$x = 0;
$start = microtime( true );
while ( $x < 1000 ) {
$redis->eval( 'local value = redis.call( "GET", KEYS[1] ); local a, b = value:match( "^([^;]+);(.+)$" ); return redis.call( "MGET", a, b )', [ 'mykey' ], 1 );
$x++;
}
var_dump( microtime( true ) - $start );
$x = 0;
$start = microtime( true );
while ( $x < 1000 ) {
$r = $redis->get( 'mykey' );
$redis->mGet( explode( ';', $r, 2 ) );
$x++;
}
var_dump( microtime( true ) - $start );
I'm seeing this behaviour on
- OS: unix
- Redis: 7.2.5
- PHP: 8.3.x
- phpredis: 6.0.2
I've checked
- There is no similar issue from other users
- Issue isn't fixed in
develop
branch
Metadata
Metadata
Assignees
Labels
No labels