nalgeon / redka

Redis re-implemented with SQLite
BSD 3-Clause "New" or "Revised" License
3.24k stars 87 forks source link

LUA scripting #21

Closed alturkovic closed 2 months ago

alturkovic commented 2 months ago

This seems like a huge feature to drop.

LUA scripting is the preferred way (and the only one as far as I know) to implement conditional atomic execution. A lot of libraries built on top of Redis rely on custom LUA scripts so Redka is not a suitable replacement for most of these. Not having LUA scripting means that there is no way to implement any conditional atomic operations on top of the existing ones.

For an example: set key foo if bar does not exist. This could be implemented with LUA very easily, but I do not see how to implement such feature with Redka.

Not having an option to extend Redis with LUA scripts is very limiting and is one of the main features (IMHO) that makes Redis what it is.

Is there any way you could re-evaluate your position on supporting LUA scripts?

nalgeon commented 2 months ago

but I do not see how to implement such feature with Redka.

With transactions — as long as you use the Go module:

db.Update(func(tx *redka.Tx) error {
    barExists, err := tx.Key().Exists("bar")
    if err != nil {
        return err
    }
    if barExists {
        return nil
    }
    // Set foo if bar does not exist.
    return tx.Str().Set("foo", "foo")
})

Is there any way you could re-evaluate your position on supporting LUA scripts?

There is: if/when there are a reasonable number of people already using Redka in production, and real-world use cases they can't implement without Lua scripting. Which is currently not the case.

alturkovic commented 2 months ago

With transactions — as long as you use the Go module

I was hoping to use this from non-Go projects (as a standalone server) where it would not be supported.

There is: if/when there is a reasonable amount of people who already using Redka in production, and real-world use cases they can't implement without Lua scripting. Which is currently not the case.

Fair enough, thank you for the quick reply :)