Working with Redis Functions

1. Creating Functions

CommandDescription
FUNCTION LOAD [REPLACE] codePersistent library, replicated via RDB/AOF 7.0+
#!lua name=mylib
redis.register_function('myadd', function(keys, args)
  return redis.call('INCRBY', keys[1], args[1])
end)

2. Calling Functions

CommandDescription
FCALL fname numkeys key ... arg ...Execute (read+write)
FCALL_RO fname numkeys ...Replica-safe read-only call

3. Listing Functions

CommandReturns
FUNCTION LIST [LIBRARYNAME pat] [WITHCODE]All libraries

4. Deleting Functions

CommandDescription
FUNCTION DELETE libnameRemove library

5. Dumping Functions

CommandReturns
FUNCTION DUMPBinary payload of all libraries

6. Restoring Functions

CommandOptions
FUNCTION RESTORE payload [FLUSH|APPEND|REPLACE]Reload from DUMP

7. Flushing Functions

CommandDescription
FUNCTION FLUSH [ASYNC|SYNC]Wipe all libraries

8. Getting Function Stats

CommandReturns
FUNCTION STATSCurrently running function + engine stats

9. Killing Running Functions

CommandLimitations
FUNCTION KILLOnly if no writes performed

10. Understanding Functions vs Lua Scripts

AspectFunctionsEVAL Scripts
PersistenceRDB/AOF replicatedNot persisted; re-load after restart
NamingNamed librariesSHA1 hash
Use caseApp-level extensionsAd-hoc atomic ops