SlideShare ist ein Scribd-Unternehmen logo
1 von 20
Downloaden Sie, um offline zu lesen
@itamarhaber
A Redis Geek, Disque Freak... and Lunatic!
Chief Developer Advocatique at
Have you signed for newsletter?
http://bit.ly/RedisWatch
...is a powerful, fast, lightweight,
embeddable scripting language.
...(pronounced LOO-ah) means
"Moon" in Portuguese.
Please do not write it as "LUA", which
is both ugly and confusing...
http://www.lua.org
Lunatic
Noun: a mentally ill person (not in technical use),
extremely foolish, eccentric, or absurd.
Origin: Middle English, from Old French lunatique, from
late Latin lunaticus, from Latin luna ‘moon’ (from the
belief that change of the moon caused intermittent
insanity).
Luaphobia is pure lunacy
Redis does Lua since v2.6 (Oct 23, 2012)
Scripts are atomic, have (practically) local data access
Lua is pretty and/or ugly isn't perfect, but …
… having the option to use it beats not.
(mea culpa: when all you have is a hammer)
Lua Redis language, primer (1/2)
--[[
this is a multi-line comment
]]
local t = { 1, 2, foo = "bar", nil, false }
for i, v in ipairs(KEYS)
if i % 2 ~= 0 then
redis.call('SET', ARGV[1],)
end
end
Lua Redis libraries, primer (2/2)
Core Lua: base, table, string, math & debug
Also included: bitop, struct, cmsgpack & cjson
redis library: call, pcall, log, status_reply,
Error_reply & sha1hex
[v3.2 spoiler]: debug, breakpoint, set_repl &
replicate_commands
Lua crash course...
ceci n'est pas Le Voyage Dans Le Lune
For your future reference:
RTFM - http://www.lua.org/pil
Redis - http://redis.io/commands/eval
15min - https://gist.github.com/tylerneylon/5853042
A poor & not to scale analogy
Redis is the Sun.
Earth is your application.
Imagine that the Moon is stuck in the middle of
the Sun.
You send non-melting rockets (scripts) with robots
(commands) and cargo (data) back and forth…
A helluava use case #1
Save the bandwidth, save the LATENCY
● Cached compiled multi-operations scripts
● Variadic keys & variable arity arguments (i.e. lots)
● Server-side processing for: exploding input, data
transformation & manipulation, JSON/MessagePack
(de)serialization, imploding (aggregating) output...
UC#1 example: GEOPATHLEN
Meet https://github.com/RedisLabs/geo.lua (WIP)
A (metric only) helper library for Redis geospatial indices
Redis API: GEODIST key elem1 elem2
+ GEODIST key elem2 elem3
+ ...
Lua library: GEOPATHLEN key elem1 elem2 elem3...
Winning use case #2
Transact with intelligence
● Scripts are atomic & blocking
● Comments, variables, data types, operators, control
structures & (some) libraries
● Do you really want to WATCH/MULTI/DISCARD/EXEC?
Lua.tx "recipe": 1) assert 2) process 3) check 4) commit
Liberating use case #3
Patent APIs & data structures
Remember geo.lua?
● GEODEL
● xyzsets (geosets w/ attitude)
● GeoJSON - encode/decode
● ...and ME TRY FILTER!
GEORADIUS -> GEOMETRYFILTER
3. Radius search from pbb's center
2. Compute p's bounding box
4. Filter anything out of pbb
5. Use a semi-infinite ray (PNPOLY)
Find the geoset members in polygon p
1. Read p's definition from geomash
Lua ain't only green cheese
● Massive number crunching? Nah: redimension's
benchmark
● Lua's operators (no ternary?), strings (no split?),
patterns (no regex?), tables (no zip?)...
● Only 32-bit bit operations
● Redis' sandboxing means no external packages
● Access to data not totally inexpensive
● Beware of returning doubles, associative arrays, …
SCRIPT DEBUG, YES PLEASE!
Integral Redis Lua
scripts debugger
ZeroBrane Studio
Plugin for Redis
Script source is sent to slaves, reduces wire traffic:
for i = 1, 100 do
redis.call('INCR', KEYS[1])
end
Disadvantages: wasteful (1 + n slaves), long recovery
from AOF, no non-determinism, no "transient" keys
Lua replication < v3.2
Effects & target replication 3.2
-- succeeds if called before any write
redis.replicate_commands()
-- optionally, change replication target
redis.set_repl(redis.REPL_NONE)
-- or redis.REPL_AOF, redis.REPL_SLAVE
-- or redis.REPL_ALL (the default)
redis.call('TIME') -- random prize!
Lua versions
● Redis: 5.1.5 2012-02-17
● Current: 5.3.2 2015-11-30
● No major changes to language,
upgrade TBD soon™
Scripts graveyard:
infospect.lua, hitman.lua and redis-
lua-debugger… but I can still add
port 6379 to /etc/services with
Lua though ;)

Weitere ähnliche Inhalte

Was ist angesagt?

Linux Binary Exploitation - Return-oritend Programing
Linux Binary Exploitation - Return-oritend ProgramingLinux Binary Exploitation - Return-oritend Programing
Linux Binary Exploitation - Return-oritend ProgramingAngel Boy
 
Windows 10 Nt Heap Exploitation (English version)
Windows 10 Nt Heap Exploitation (English version)Windows 10 Nt Heap Exploitation (English version)
Windows 10 Nt Heap Exploitation (English version)Angel Boy
 
台科逆向簡報
台科逆向簡報台科逆向簡報
台科逆向簡報耀德 蔡
 
Redis — The AK-47 of Post-relational Databases
Redis — The AK-47 of Post-relational DatabasesRedis — The AK-47 of Post-relational Databases
Redis — The AK-47 of Post-relational DatabasesKarel Minarik
 
Redis - for duplicate detection on real time stream
Redis - for duplicate detection on real time streamRedis - for duplicate detection on real time stream
Redis - for duplicate detection on real time streamCodemotion
 
Redis SoCraTes 2014
Redis SoCraTes 2014Redis SoCraTes 2014
Redis SoCraTes 2014steffenbauer
 
[2012 CodeEngn Conference 06] pwn3r - Secuinside 2012 CTF 예선 문제풀이
[2012 CodeEngn Conference 06] pwn3r - Secuinside 2012 CTF 예선 문제풀이[2012 CodeEngn Conference 06] pwn3r - Secuinside 2012 CTF 예선 문제풀이
[2012 CodeEngn Conference 06] pwn3r - Secuinside 2012 CTF 예선 문제풀이GangSeok Lee
 
Finding Xori: Malware Analysis Triage with Automated Disassembly
Finding Xori: Malware Analysis Triage with Automated DisassemblyFinding Xori: Malware Analysis Triage with Automated Disassembly
Finding Xori: Malware Analysis Triage with Automated DisassemblyPriyanka Aash
 
JavaOne 2012 - JVM JIT for Dummies
JavaOne 2012 - JVM JIT for DummiesJavaOne 2012 - JVM JIT for Dummies
JavaOne 2012 - JVM JIT for DummiesCharles Nutter
 
Asynchronous single page applications without a line of HTML or Javascript, o...
Asynchronous single page applications without a line of HTML or Javascript, o...Asynchronous single page applications without a line of HTML or Javascript, o...
Asynchronous single page applications without a line of HTML or Javascript, o...Robert Schadek
 
Apache Hadoop Shell Rewrite
Apache Hadoop Shell RewriteApache Hadoop Shell Rewrite
Apache Hadoop Shell RewriteAllen Wittenauer
 
DConf 2016: Keynote by Walter Bright
DConf 2016: Keynote by Walter Bright DConf 2016: Keynote by Walter Bright
DConf 2016: Keynote by Walter Bright Andrei Alexandrescu
 
NOSQL and Cassandra
NOSQL and CassandraNOSQL and Cassandra
NOSQL and Cassandrarantav
 
Configuration management II - Terraform
Configuration management II - TerraformConfiguration management II - Terraform
Configuration management II - TerraformXavier Serrat Bordas
 
Introduction to PostgreSQL
Introduction to PostgreSQLIntroduction to PostgreSQL
Introduction to PostgreSQLMark Wong
 
Upgrading to MongoDB 4.0 from older versions
Upgrading to MongoDB 4.0 from older versionsUpgrading to MongoDB 4.0 from older versions
Upgrading to MongoDB 4.0 from older versionsAntonios Giannopoulos
 

Was ist angesagt? (20)

Linux Binary Exploitation - Return-oritend Programing
Linux Binary Exploitation - Return-oritend ProgramingLinux Binary Exploitation - Return-oritend Programing
Linux Binary Exploitation - Return-oritend Programing
 
Elephants and Raft
Elephants and RaftElephants and Raft
Elephants and Raft
 
Windows 10 Nt Heap Exploitation (English version)
Windows 10 Nt Heap Exploitation (English version)Windows 10 Nt Heap Exploitation (English version)
Windows 10 Nt Heap Exploitation (English version)
 
Csp scala wixmeetup2016
Csp scala wixmeetup2016Csp scala wixmeetup2016
Csp scala wixmeetup2016
 
Nginx-lua
Nginx-luaNginx-lua
Nginx-lua
 
台科逆向簡報
台科逆向簡報台科逆向簡報
台科逆向簡報
 
Redis — The AK-47 of Post-relational Databases
Redis — The AK-47 of Post-relational DatabasesRedis — The AK-47 of Post-relational Databases
Redis — The AK-47 of Post-relational Databases
 
Redis - for duplicate detection on real time stream
Redis - for duplicate detection on real time streamRedis - for duplicate detection on real time stream
Redis - for duplicate detection on real time stream
 
Redis SoCraTes 2014
Redis SoCraTes 2014Redis SoCraTes 2014
Redis SoCraTes 2014
 
[2012 CodeEngn Conference 06] pwn3r - Secuinside 2012 CTF 예선 문제풀이
[2012 CodeEngn Conference 06] pwn3r - Secuinside 2012 CTF 예선 문제풀이[2012 CodeEngn Conference 06] pwn3r - Secuinside 2012 CTF 예선 문제풀이
[2012 CodeEngn Conference 06] pwn3r - Secuinside 2012 CTF 예선 문제풀이
 
Finding Xori: Malware Analysis Triage with Automated Disassembly
Finding Xori: Malware Analysis Triage with Automated DisassemblyFinding Xori: Malware Analysis Triage with Automated Disassembly
Finding Xori: Malware Analysis Triage with Automated Disassembly
 
JavaOne 2012 - JVM JIT for Dummies
JavaOne 2012 - JVM JIT for DummiesJavaOne 2012 - JVM JIT for Dummies
JavaOne 2012 - JVM JIT for Dummies
 
Asynchronous single page applications without a line of HTML or Javascript, o...
Asynchronous single page applications without a line of HTML or Javascript, o...Asynchronous single page applications without a line of HTML or Javascript, o...
Asynchronous single page applications without a line of HTML or Javascript, o...
 
Apache Hadoop Shell Rewrite
Apache Hadoop Shell RewriteApache Hadoop Shell Rewrite
Apache Hadoop Shell Rewrite
 
DConf 2016: Keynote by Walter Bright
DConf 2016: Keynote by Walter Bright DConf 2016: Keynote by Walter Bright
DConf 2016: Keynote by Walter Bright
 
NOSQL and Cassandra
NOSQL and CassandraNOSQL and Cassandra
NOSQL and Cassandra
 
Everything as Code with Terraform
Everything as Code with TerraformEverything as Code with Terraform
Everything as Code with Terraform
 
Configuration management II - Terraform
Configuration management II - TerraformConfiguration management II - Terraform
Configuration management II - Terraform
 
Introduction to PostgreSQL
Introduction to PostgreSQLIntroduction to PostgreSQL
Introduction to PostgreSQL
 
Upgrading to MongoDB 4.0 from older versions
Upgrading to MongoDB 4.0 from older versionsUpgrading to MongoDB 4.0 from older versions
Upgrading to MongoDB 4.0 from older versions
 

Andere mochten auch

Benchmarking Redis by itself and versus other NoSQL databases
Benchmarking Redis by itself and versus other NoSQL databasesBenchmarking Redis by itself and versus other NoSQL databases
Benchmarking Redis by itself and versus other NoSQL databasesItamar Haber
 
A Weight Off Your Shoulders: MongoDB Atlas
A Weight Off Your Shoulders: MongoDB AtlasA Weight Off Your Shoulders: MongoDB Atlas
A Weight Off Your Shoulders: MongoDB AtlasMongoDB
 
Scalable Streaming Data Pipelines with Redis
Scalable Streaming Data Pipelines with RedisScalable Streaming Data Pipelines with Redis
Scalable Streaming Data Pipelines with RedisAvram Lyon
 
Highly scalable caching service on cloud - Redis
Highly scalable caching service on cloud - RedisHighly scalable caching service on cloud - Redis
Highly scalable caching service on cloud - RedisKrishna-Kumar
 
Redis Indices (#RedisTLV)
Redis Indices (#RedisTLV)Redis Indices (#RedisTLV)
Redis Indices (#RedisTLV)Itamar Haber
 
A New “Sparkitecture” for Modernizing your Data Warehouse: Spark Summit East ...
A New “Sparkitecture” for Modernizing your Data Warehouse: Spark Summit East ...A New “Sparkitecture” for Modernizing your Data Warehouse: Spark Summit East ...
A New “Sparkitecture” for Modernizing your Data Warehouse: Spark Summit East ...Spark Summit
 
Redis Use Patterns (DevconTLV June 2014)
Redis Use Patterns (DevconTLV June 2014)Redis Use Patterns (DevconTLV June 2014)
Redis Use Patterns (DevconTLV June 2014)Itamar Haber
 

Andere mochten auch (7)

Benchmarking Redis by itself and versus other NoSQL databases
Benchmarking Redis by itself and versus other NoSQL databasesBenchmarking Redis by itself and versus other NoSQL databases
Benchmarking Redis by itself and versus other NoSQL databases
 
A Weight Off Your Shoulders: MongoDB Atlas
A Weight Off Your Shoulders: MongoDB AtlasA Weight Off Your Shoulders: MongoDB Atlas
A Weight Off Your Shoulders: MongoDB Atlas
 
Scalable Streaming Data Pipelines with Redis
Scalable Streaming Data Pipelines with RedisScalable Streaming Data Pipelines with Redis
Scalable Streaming Data Pipelines with Redis
 
Highly scalable caching service on cloud - Redis
Highly scalable caching service on cloud - RedisHighly scalable caching service on cloud - Redis
Highly scalable caching service on cloud - Redis
 
Redis Indices (#RedisTLV)
Redis Indices (#RedisTLV)Redis Indices (#RedisTLV)
Redis Indices (#RedisTLV)
 
A New “Sparkitecture” for Modernizing your Data Warehouse: Spark Summit East ...
A New “Sparkitecture” for Modernizing your Data Warehouse: Spark Summit East ...A New “Sparkitecture” for Modernizing your Data Warehouse: Spark Summit East ...
A New “Sparkitecture” for Modernizing your Data Warehouse: Spark Summit East ...
 
Redis Use Patterns (DevconTLV June 2014)
Redis Use Patterns (DevconTLV June 2014)Redis Use Patterns (DevconTLV June 2014)
Redis Use Patterns (DevconTLV June 2014)
 

Ähnlich wie Power to the People: Redis Lua Scripts

Use of Lua in Lab Devices
Use of Lua in Lab DevicesUse of Lua in Lab Devices
Use of Lua in Lab DevicesClaus Kühnel
 
Lua+tdd
Lua+tddLua+tdd
Lua+tddotikik
 
Rclex: A Library for Robotics meet Elixir
Rclex: A Library for Robotics meet ElixirRclex: A Library for Robotics meet Elixir
Rclex: A Library for Robotics meet ElixirHideki Takase
 
Ruby is dying. What languages are cool now?
Ruby is dying. What languages are cool now?Ruby is dying. What languages are cool now?
Ruby is dying. What languages are cool now?Michał Konarski
 
Roberto De Ioris - Scriptiamo Unreal Engine con Lua - Codemotion Rome 2019
Roberto De Ioris - Scriptiamo Unreal Engine con Lua - Codemotion Rome 2019Roberto De Ioris - Scriptiamo Unreal Engine con Lua - Codemotion Rome 2019
Roberto De Ioris - Scriptiamo Unreal Engine con Lua - Codemotion Rome 2019Codemotion
 
Docker and Go: why did we decide to write Docker in Go?
Docker and Go: why did we decide to write Docker in Go?Docker and Go: why did we decide to write Docker in Go?
Docker and Go: why did we decide to write Docker in Go?Jérôme Petazzoni
 
Open Source Storage at Scale: Ceph @ GRNET
Open Source Storage at Scale: Ceph @ GRNETOpen Source Storage at Scale: Ceph @ GRNET
Open Source Storage at Scale: Ceph @ GRNETNikos Kormpakis
 
A brief history of Lua - Roberto Ierusalimschy (PUC Rio)
A brief history of Lua - Roberto  Ierusalimschy (PUC Rio)A brief history of Lua - Roberto  Ierusalimschy (PUC Rio)
A brief history of Lua - Roberto Ierusalimschy (PUC Rio)Kore VM
 
Java(ee) mongo db applications in the cloud
Java(ee) mongo db applications in the cloud Java(ee) mongo db applications in the cloud
Java(ee) mongo db applications in the cloud Shekhar Gulati
 
Tarantool 1.6 talk at SECR 2014 conference
Tarantool 1.6 talk at SECR 2014 conferenceTarantool 1.6 talk at SECR 2014 conference
Tarantool 1.6 talk at SECR 2014 conferenceKostja Osipov
 
BUD17-104: Scripting Languages in IoT: Challenges and Approaches
BUD17-104: Scripting Languages in IoT: Challenges and ApproachesBUD17-104: Scripting Languages in IoT: Challenges and Approaches
BUD17-104: Scripting Languages in IoT: Challenges and ApproachesLinaro
 
Getting Started with Hadoop
Getting Started with HadoopGetting Started with Hadoop
Getting Started with HadoopJosh Devins
 
Lua and fable jonathan shaw (lionhead)
Lua and fable   jonathan shaw (lionhead)Lua and fable   jonathan shaw (lionhead)
Lua and fable jonathan shaw (lionhead)Kore VM
 
Introduction to Docker, December 2014 "Tour de France" Bordeaux Special Edition
Introduction to Docker, December 2014 "Tour de France" Bordeaux Special EditionIntroduction to Docker, December 2014 "Tour de France" Bordeaux Special Edition
Introduction to Docker, December 2014 "Tour de France" Bordeaux Special EditionJérôme Petazzoni
 
MozillaPH Rust Hack & Learn Session 1
MozillaPH Rust Hack & Learn Session 1MozillaPH Rust Hack & Learn Session 1
MozillaPH Rust Hack & Learn Session 1Robert 'Bob' Reyes
 
Introduction to Lua Luajit Openresty Luvit
Introduction to Lua Luajit Openresty LuvitIntroduction to Lua Luajit Openresty Luvit
Introduction to Lua Luajit Openresty LuvitLionel Duboeuf
 
PyTorch for Delphi - Python Data Sciences Libraries.pdf
PyTorch for Delphi - Python Data Sciences Libraries.pdfPyTorch for Delphi - Python Data Sciences Libraries.pdf
PyTorch for Delphi - Python Data Sciences Libraries.pdfEmbarcadero Technologies
 

Ähnlich wie Power to the People: Redis Lua Scripts (20)

Use of Lua in Lab Devices
Use of Lua in Lab DevicesUse of Lua in Lab Devices
Use of Lua in Lab Devices
 
Lua+tdd
Lua+tddLua+tdd
Lua+tdd
 
Rclex: A Library for Robotics meet Elixir
Rclex: A Library for Robotics meet ElixirRclex: A Library for Robotics meet Elixir
Rclex: A Library for Robotics meet Elixir
 
Ruby is dying. What languages are cool now?
Ruby is dying. What languages are cool now?Ruby is dying. What languages are cool now?
Ruby is dying. What languages are cool now?
 
Roberto De Ioris - Scriptiamo Unreal Engine con Lua - Codemotion Rome 2019
Roberto De Ioris - Scriptiamo Unreal Engine con Lua - Codemotion Rome 2019Roberto De Ioris - Scriptiamo Unreal Engine con Lua - Codemotion Rome 2019
Roberto De Ioris - Scriptiamo Unreal Engine con Lua - Codemotion Rome 2019
 
Docker and Go: why did we decide to write Docker in Go?
Docker and Go: why did we decide to write Docker in Go?Docker and Go: why did we decide to write Docker in Go?
Docker and Go: why did we decide to write Docker in Go?
 
Lua and its Ecosystem
Lua and its EcosystemLua and its Ecosystem
Lua and its Ecosystem
 
Open Source Storage at Scale: Ceph @ GRNET
Open Source Storage at Scale: Ceph @ GRNETOpen Source Storage at Scale: Ceph @ GRNET
Open Source Storage at Scale: Ceph @ GRNET
 
A brief history of Lua - Roberto Ierusalimschy (PUC Rio)
A brief history of Lua - Roberto  Ierusalimschy (PUC Rio)A brief history of Lua - Roberto  Ierusalimschy (PUC Rio)
A brief history of Lua - Roberto Ierusalimschy (PUC Rio)
 
Java(ee) mongo db applications in the cloud
Java(ee) mongo db applications in the cloud Java(ee) mongo db applications in the cloud
Java(ee) mongo db applications in the cloud
 
Tarantool 1.6 talk at SECR 2014 conference
Tarantool 1.6 talk at SECR 2014 conferenceTarantool 1.6 talk at SECR 2014 conference
Tarantool 1.6 talk at SECR 2014 conference
 
BUD17-104: Scripting Languages in IoT: Challenges and Approaches
BUD17-104: Scripting Languages in IoT: Challenges and ApproachesBUD17-104: Scripting Languages in IoT: Challenges and Approaches
BUD17-104: Scripting Languages in IoT: Challenges and Approaches
 
Getting Started with Hadoop
Getting Started with HadoopGetting Started with Hadoop
Getting Started with Hadoop
 
Lua and fable jonathan shaw (lionhead)
Lua and fable   jonathan shaw (lionhead)Lua and fable   jonathan shaw (lionhead)
Lua and fable jonathan shaw (lionhead)
 
Darktable -- raw converter for linux
Darktable -- raw converter for linuxDarktable -- raw converter for linux
Darktable -- raw converter for linux
 
Introduction to Docker, December 2014 "Tour de France" Bordeaux Special Edition
Introduction to Docker, December 2014 "Tour de France" Bordeaux Special EditionIntroduction to Docker, December 2014 "Tour de France" Bordeaux Special Edition
Introduction to Docker, December 2014 "Tour de France" Bordeaux Special Edition
 
MozillaPH Rust Hack & Learn Session 1
MozillaPH Rust Hack & Learn Session 1MozillaPH Rust Hack & Learn Session 1
MozillaPH Rust Hack & Learn Session 1
 
Introduction to Lua Luajit Openresty Luvit
Introduction to Lua Luajit Openresty LuvitIntroduction to Lua Luajit Openresty Luvit
Introduction to Lua Luajit Openresty Luvit
 
Lua
LuaLua
Lua
 
PyTorch for Delphi - Python Data Sciences Libraries.pdf
PyTorch for Delphi - Python Data Sciences Libraries.pdfPyTorch for Delphi - Python Data Sciences Libraries.pdf
PyTorch for Delphi - Python Data Sciences Libraries.pdf
 

Mehr von Itamar Haber

Redis v5 & Streams
Redis v5 & StreamsRedis v5 & Streams
Redis v5 & StreamsItamar Haber
 
Redis Modules API - an introduction
Redis Modules API - an introductionRedis Modules API - an introduction
Redis Modules API - an introductionItamar Haber
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to RedisItamar Haber
 
How I Implemented the #1 Requested Feature In Redis In Less than 1 Hour with ...
How I Implemented the #1 Requested Feature In Redis In Less than 1 Hour with ...How I Implemented the #1 Requested Feature In Redis In Less than 1 Hour with ...
How I Implemented the #1 Requested Feature In Redis In Less than 1 Hour with ...Itamar Haber
 
Redis Streams - Fiverr Tech5 meetup
Redis Streams - Fiverr Tech5 meetupRedis Streams - Fiverr Tech5 meetup
Redis Streams - Fiverr Tech5 meetupItamar Haber
 
Leveraging Probabilistic Data Structures for Real Time Analytics with Redis M...
Leveraging Probabilistic Data Structures for Real Time Analytics with Redis M...Leveraging Probabilistic Data Structures for Real Time Analytics with Redis M...
Leveraging Probabilistic Data Structures for Real Time Analytics with Redis M...Itamar Haber
 
Redis Developers Day 2015 - Secondary Indexes and State of Lua
Redis Developers Day 2015 - Secondary Indexes and State of LuaRedis Developers Day 2015 - Secondary Indexes and State of Lua
Redis Developers Day 2015 - Secondary Indexes and State of LuaItamar Haber
 
Use Redis in Odd and Unusual Ways
Use Redis in Odd and Unusual WaysUse Redis in Odd and Unusual Ways
Use Redis in Odd and Unusual WaysItamar Haber
 
Why Your MongoDB Needs Redis
Why Your MongoDB Needs RedisWhy Your MongoDB Needs Redis
Why Your MongoDB Needs RedisItamar Haber
 
Redis & MongoDB: Stop Big Data Indigestion Before It Starts
Redis & MongoDB: Stop Big Data Indigestion Before It StartsRedis & MongoDB: Stop Big Data Indigestion Before It Starts
Redis & MongoDB: Stop Big Data Indigestion Before It StartsItamar Haber
 

Mehr von Itamar Haber (11)

Redis v5 & Streams
Redis v5 & StreamsRedis v5 & Streams
Redis v5 & Streams
 
Redis Modules API - an introduction
Redis Modules API - an introductionRedis Modules API - an introduction
Redis Modules API - an introduction
 
Redis Lua Scripts
Redis Lua ScriptsRedis Lua Scripts
Redis Lua Scripts
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
How I Implemented the #1 Requested Feature In Redis In Less than 1 Hour with ...
How I Implemented the #1 Requested Feature In Redis In Less than 1 Hour with ...How I Implemented the #1 Requested Feature In Redis In Less than 1 Hour with ...
How I Implemented the #1 Requested Feature In Redis In Less than 1 Hour with ...
 
Redis Streams - Fiverr Tech5 meetup
Redis Streams - Fiverr Tech5 meetupRedis Streams - Fiverr Tech5 meetup
Redis Streams - Fiverr Tech5 meetup
 
Leveraging Probabilistic Data Structures for Real Time Analytics with Redis M...
Leveraging Probabilistic Data Structures for Real Time Analytics with Redis M...Leveraging Probabilistic Data Structures for Real Time Analytics with Redis M...
Leveraging Probabilistic Data Structures for Real Time Analytics with Redis M...
 
Redis Developers Day 2015 - Secondary Indexes and State of Lua
Redis Developers Day 2015 - Secondary Indexes and State of LuaRedis Developers Day 2015 - Secondary Indexes and State of Lua
Redis Developers Day 2015 - Secondary Indexes and State of Lua
 
Use Redis in Odd and Unusual Ways
Use Redis in Odd and Unusual WaysUse Redis in Odd and Unusual Ways
Use Redis in Odd and Unusual Ways
 
Why Your MongoDB Needs Redis
Why Your MongoDB Needs RedisWhy Your MongoDB Needs Redis
Why Your MongoDB Needs Redis
 
Redis & MongoDB: Stop Big Data Indigestion Before It Starts
Redis & MongoDB: Stop Big Data Indigestion Before It StartsRedis & MongoDB: Stop Big Data Indigestion Before It Starts
Redis & MongoDB: Stop Big Data Indigestion Before It Starts
 

Kürzlich hochgeladen

unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 

Kürzlich hochgeladen (20)

unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 

Power to the People: Redis Lua Scripts

  • 1.
  • 2. @itamarhaber A Redis Geek, Disque Freak... and Lunatic! Chief Developer Advocatique at Have you signed for newsletter? http://bit.ly/RedisWatch
  • 3. ...is a powerful, fast, lightweight, embeddable scripting language. ...(pronounced LOO-ah) means "Moon" in Portuguese. Please do not write it as "LUA", which is both ugly and confusing... http://www.lua.org
  • 4. Lunatic Noun: a mentally ill person (not in technical use), extremely foolish, eccentric, or absurd. Origin: Middle English, from Old French lunatique, from late Latin lunaticus, from Latin luna ‘moon’ (from the belief that change of the moon caused intermittent insanity).
  • 5. Luaphobia is pure lunacy Redis does Lua since v2.6 (Oct 23, 2012) Scripts are atomic, have (practically) local data access Lua is pretty and/or ugly isn't perfect, but … … having the option to use it beats not. (mea culpa: when all you have is a hammer)
  • 6. Lua Redis language, primer (1/2) --[[ this is a multi-line comment ]] local t = { 1, 2, foo = "bar", nil, false } for i, v in ipairs(KEYS) if i % 2 ~= 0 then redis.call('SET', ARGV[1],) end end
  • 7. Lua Redis libraries, primer (2/2) Core Lua: base, table, string, math & debug Also included: bitop, struct, cmsgpack & cjson redis library: call, pcall, log, status_reply, Error_reply & sha1hex [v3.2 spoiler]: debug, breakpoint, set_repl & replicate_commands
  • 8. Lua crash course... ceci n'est pas Le Voyage Dans Le Lune For your future reference: RTFM - http://www.lua.org/pil Redis - http://redis.io/commands/eval 15min - https://gist.github.com/tylerneylon/5853042
  • 9. A poor & not to scale analogy Redis is the Sun. Earth is your application. Imagine that the Moon is stuck in the middle of the Sun. You send non-melting rockets (scripts) with robots (commands) and cargo (data) back and forth…
  • 10. A helluava use case #1 Save the bandwidth, save the LATENCY ● Cached compiled multi-operations scripts ● Variadic keys & variable arity arguments (i.e. lots) ● Server-side processing for: exploding input, data transformation & manipulation, JSON/MessagePack (de)serialization, imploding (aggregating) output...
  • 11. UC#1 example: GEOPATHLEN Meet https://github.com/RedisLabs/geo.lua (WIP) A (metric only) helper library for Redis geospatial indices Redis API: GEODIST key elem1 elem2 + GEODIST key elem2 elem3 + ... Lua library: GEOPATHLEN key elem1 elem2 elem3...
  • 12. Winning use case #2 Transact with intelligence ● Scripts are atomic & blocking ● Comments, variables, data types, operators, control structures & (some) libraries ● Do you really want to WATCH/MULTI/DISCARD/EXEC? Lua.tx "recipe": 1) assert 2) process 3) check 4) commit
  • 13. Liberating use case #3 Patent APIs & data structures Remember geo.lua? ● GEODEL ● xyzsets (geosets w/ attitude) ● GeoJSON - encode/decode ● ...and ME TRY FILTER!
  • 14. GEORADIUS -> GEOMETRYFILTER 3. Radius search from pbb's center 2. Compute p's bounding box 4. Filter anything out of pbb 5. Use a semi-infinite ray (PNPOLY) Find the geoset members in polygon p 1. Read p's definition from geomash
  • 15. Lua ain't only green cheese ● Massive number crunching? Nah: redimension's benchmark ● Lua's operators (no ternary?), strings (no split?), patterns (no regex?), tables (no zip?)... ● Only 32-bit bit operations ● Redis' sandboxing means no external packages ● Access to data not totally inexpensive ● Beware of returning doubles, associative arrays, …
  • 16.
  • 17. SCRIPT DEBUG, YES PLEASE! Integral Redis Lua scripts debugger ZeroBrane Studio Plugin for Redis
  • 18. Script source is sent to slaves, reduces wire traffic: for i = 1, 100 do redis.call('INCR', KEYS[1]) end Disadvantages: wasteful (1 + n slaves), long recovery from AOF, no non-determinism, no "transient" keys Lua replication < v3.2
  • 19. Effects & target replication 3.2 -- succeeds if called before any write redis.replicate_commands() -- optionally, change replication target redis.set_repl(redis.REPL_NONE) -- or redis.REPL_AOF, redis.REPL_SLAVE -- or redis.REPL_ALL (the default) redis.call('TIME') -- random prize!
  • 20. Lua versions ● Redis: 5.1.5 2012-02-17 ● Current: 5.3.2 2015-11-30 ● No major changes to language, upgrade TBD soon™ Scripts graveyard: infospect.lua, hitman.lua and redis- lua-debugger… but I can still add port 6379 to /etc/services with Lua though ;)