valkey-io / valkey

A flexible distributed key-value datastore that is optimized for caching and other realtime workloads.
https://valkey.io
Other
17.61k stars 664 forks source link

Add Lua global object `server` as alias for `redis` #136

Closed zuiderkwast closed 7 months ago

zuiderkwast commented 8 months ago

We shall also keep redis for backward compatibility.

daniel-house commented 8 months ago

Adding a new alias for the word server seems very risky. I can easily imagine that there are already lua scripts with the word server in them. valkey would seem safer.

zuiderkwast commented 8 months ago

@daniel-house Good point. If script uses a variable named server, they will get an error like I got here:

127.0.0.1:6379> eval 'server = "hello" return server' 0 
(error) ERR user_script:1: Attempt to modify a readonly table script: eaea3495a27b17adb01815dd404912e3f3623d10, on @user_script:1.

@valkey-io/core-team Shall we add a valkey Lua object instead?

I don't think it's a problem actually. Users can only create local variables. It's already possible to create a local variable called redis:

127.0.0.1:6379> eval 'local redis redis = "qux" return redis' 0
"qux"
madolson commented 8 months ago

Yeah, you have to create local variables. Someone might already be creating a local server that would shadow the global variable, but that shouldn't break their script. It is a valid callout that some folks might need some soft refactoring if they were declaring a local server variable, which would shadow the global one. I don't see a concern.

madolson commented 8 months ago

(Assigning it to me, although someone else from AWS is working on it. I'll update assignment when they join the triage group)

zuiderkwast commented 7 months ago

Fixed by #213