dragonflydb / dragonfly

A modern replacement for Redis and Memcached
https://www.dragonflydb.io/
Other
24.52k stars 885 forks source link

Got "script tried accessing undeclared key" when key actually exists #3066

Closed howz97 closed 1 month ago

howz97 commented 1 month ago

Describe the bug Got "script tried accessing undeclared key" when key actually exists

To Reproduce install drongonfly

docker run --network=host --ulimit memlock=-1 docker.dragonflydb.io/dragonflydb/dragonfly

execute

127.0.0.1:6379> set foo bar
OK
127.0.0.1:6379> get foo
"bar"
127.0.0.1:6379> eval "redis.call('GET', 'foo')" 0
(error) ERR Error running script (call to 77563f88f961d5772ea29fbc4a18558997365e67): @user_script:2: script tried accessing undeclared key

Expected behavior eval should succeed

Environment (please complete the following information):

Reproducible Code Snippet

# Minimal code snippet to reproduce this bug

Additional context Add any other context about the problem here.

dranikpg commented 1 month ago

It doesn't matter if the key exists or not, it needs to be added to the EVAL command or specific script options should be used #272

howz97 commented 1 month ago

I tried append the key to EVAL, while it return (nil) . Is this a bug? @dranikpg

127.0.0.1:6379> set foo bar
OK
127.0.0.1:6379> get foo
"bar"
127.0.0.1:6379> eval "redis.call('GET', KEYS[1])" 1 foo
(nil)
127.0.0.1:6379> 
romange commented 1 month ago

@howz97 you should write : eval "return redis.call('GET', KEYS[1])" 1 foo note the "return"