Scripting API

Purely functional interface for the Scripting API.

Script Commands usage

Once you have acquired a connection you can start using it:

import cats.effect.IO

def putStrLn(str: String): IO[Unit] = IO(println(str))

commandsApi.use { cmd => // ScriptCommands[IO, String, String]
  for {
    // returns a String according the value codec (the last type parameter of ScriptCommands)
    greeting: String <- cmd.eval("return 'Hello World'", ScriptOutputType.Value)
    _ <- putStrLn(s"Greetings from Lua: $greeting")
  } yield ()

The return type depends on the ScriptOutputType you pass and needs to suite the result of the Lua script itself. Possible values are Integer, Value (for decoding the result using the value codec), Multi (for many values) and Status (maps to Unit in Scala). Scripts can be cached for better performance using scriptLoad and then executed via evalSha, see the redis docs for details.