SlideShare uma empresa Scribd logo
1 de 20
Baixar para ler offline
@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 ;)

Mais conteúdo relacionado

Mais procurados

これからのPerlプロダクトのかたち(YAPC::Asia 2013)
これからのPerlプロダクトのかたち(YAPC::Asia 2013)これからのPerlプロダクトのかたち(YAPC::Asia 2013)
これからのPerlプロダクトのかたち(YAPC::Asia 2013)
goccy
 
Kotlin Slides from Devoxx 2011
Kotlin Slides from Devoxx 2011Kotlin Slides from Devoxx 2011
Kotlin Slides from Devoxx 2011
Andrey Breslav
 

Mais procurados (20)

A Source-To-Source Approach to HPC Challenges
A Source-To-Source Approach to HPC ChallengesA Source-To-Source Approach to HPC Challenges
A Source-To-Source Approach to HPC Challenges
 
Compilation and Execution
Compilation and ExecutionCompilation and Execution
Compilation and Execution
 
Introduction to IPython & Jupyter Notebooks
Introduction to IPython & Jupyter NotebooksIntroduction to IPython & Jupyter Notebooks
Introduction to IPython & Jupyter Notebooks
 
嵌入式Linux課程-GNU Toolchain
嵌入式Linux課程-GNU Toolchain嵌入式Linux課程-GNU Toolchain
嵌入式Linux課程-GNU Toolchain
 
Something About Dynamic Linking
Something About Dynamic LinkingSomething About Dynamic Linking
Something About Dynamic Linking
 
Survey of Program Transformation Technologies
Survey of Program Transformation TechnologiesSurvey of Program Transformation Technologies
Survey of Program Transformation Technologies
 
Android antipatterns
Android antipatternsAndroid antipatterns
Android antipatterns
 
Java Full Throttle
Java Full ThrottleJava Full Throttle
Java Full Throttle
 
Programming with Python - Basic
Programming with Python - BasicProgramming with Python - Basic
Programming with Python - Basic
 
50 shades of PHP
50 shades of PHP50 shades of PHP
50 shades of PHP
 
これからのPerlプロダクトのかたち(YAPC::Asia 2013)
これからのPerlプロダクトのかたち(YAPC::Asia 2013)これからのPerlプロダクトのかたち(YAPC::Asia 2013)
これからのPerlプロダクトのかたち(YAPC::Asia 2013)
 
ROS Based Programming and Visualization of Quadrotor Helicopters
ROS Based Programming and Visualization of Quadrotor HelicoptersROS Based Programming and Visualization of Quadrotor Helicopters
ROS Based Programming and Visualization of Quadrotor Helicopters
 
Introduction to Python for Bioinformatics
Introduction to Python for BioinformaticsIntroduction to Python for Bioinformatics
Introduction to Python for Bioinformatics
 
Golang
GolangGolang
Golang
 
2015 bioinformatics python_introduction_wim_vancriekinge_vfinal
2015 bioinformatics python_introduction_wim_vancriekinge_vfinal2015 bioinformatics python_introduction_wim_vancriekinge_vfinal
2015 bioinformatics python_introduction_wim_vancriekinge_vfinal
 
WAD : A Module for Converting Fatal Extension Errors into Python Exceptions
WAD : A Module for Converting Fatal Extension Errors into Python ExceptionsWAD : A Module for Converting Fatal Extension Errors into Python Exceptions
WAD : A Module for Converting Fatal Extension Errors into Python Exceptions
 
Kotlin Slides from Devoxx 2011
Kotlin Slides from Devoxx 2011Kotlin Slides from Devoxx 2011
Kotlin Slides from Devoxx 2011
 
Go lang introduction
Go lang introductionGo lang introduction
Go lang introduction
 
Linker and loader upload
Linker and loader   uploadLinker and loader   upload
Linker and loader upload
 
Learn python – for beginners
Learn python – for beginnersLearn python – for beginners
Learn python – for beginners
 

Destaque (6)

ScalaBlitz
ScalaBlitzScalaBlitz
ScalaBlitz
 
Scala Parallel Collections
Scala Parallel CollectionsScala Parallel Collections
Scala Parallel Collections
 
Let's Go (golang)
Let's Go (golang)Let's Go (golang)
Let's Go (golang)
 
Openstack Rally - Benchmark as a Service. Openstack Meetup India. Ananth/Rahul.
Openstack Rally - Benchmark as a Service. Openstack Meetup India. Ananth/Rahul.Openstack Rally - Benchmark as a Service. Openstack Meetup India. Ananth/Rahul.
Openstack Rally - Benchmark as a Service. Openstack Meetup India. Ananth/Rahul.
 
Hancom MDS Conference - KAKAO DEVOPS Practice (카카오 스토리의 Devops 사례)
Hancom MDS Conference - KAKAO DEVOPS Practice (카카오 스토리의 Devops 사례)Hancom MDS Conference - KAKAO DEVOPS Practice (카카오 스토리의 Devops 사례)
Hancom MDS Conference - KAKAO DEVOPS Practice (카카오 스토리의 Devops 사례)
 
LinkedIn Data Infrastructure (QCon London 2012)
LinkedIn Data Infrastructure (QCon London 2012)LinkedIn Data Infrastructure (QCon London 2012)
LinkedIn Data Infrastructure (QCon London 2012)
 

Semelhante a Redis: Lua scripts - a primer and use cases

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
 
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
 

Semelhante a Redis: Lua scripts - a primer and use cases (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?
 
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
 
Jaoo irony
Jaoo ironyJaoo irony
Jaoo irony
 

Mais de Redis Labs

SQL, Redis and Kubernetes by Paul Stanton of Windocks - Redis Day Seattle 2020
SQL, Redis and Kubernetes by Paul Stanton of Windocks - Redis Day Seattle 2020SQL, Redis and Kubernetes by Paul Stanton of Windocks - Redis Day Seattle 2020
SQL, Redis and Kubernetes by Paul Stanton of Windocks - Redis Day Seattle 2020
Redis Labs
 
Anatomy of a Redis Command by Madelyn Olson of Amazon Web Services - Redis Da...
Anatomy of a Redis Command by Madelyn Olson of Amazon Web Services - Redis Da...Anatomy of a Redis Command by Madelyn Olson of Amazon Web Services - Redis Da...
Anatomy of a Redis Command by Madelyn Olson of Amazon Web Services - Redis Da...
Redis Labs
 
RediSearch 1.6 by Pieter Cailliau - Redis Day Bangalore 2020
RediSearch 1.6 by Pieter Cailliau - Redis Day Bangalore 2020RediSearch 1.6 by Pieter Cailliau - Redis Day Bangalore 2020
RediSearch 1.6 by Pieter Cailliau - Redis Day Bangalore 2020
Redis Labs
 
RedisGraph 2.0 by Pieter Cailliau - Redis Day Bangalore 2020
RedisGraph 2.0 by Pieter Cailliau - Redis Day Bangalore 2020RedisGraph 2.0 by Pieter Cailliau - Redis Day Bangalore 2020
RedisGraph 2.0 by Pieter Cailliau - Redis Day Bangalore 2020
Redis Labs
 

Mais de Redis Labs (20)

Redis Day Bangalore 2020 - Session state caching with redis
Redis Day Bangalore 2020 - Session state caching with redisRedis Day Bangalore 2020 - Session state caching with redis
Redis Day Bangalore 2020 - Session state caching with redis
 
Protecting Your API with Redis by Jane Paek - Redis Day Seattle 2020
Protecting Your API with Redis by Jane Paek - Redis Day Seattle 2020Protecting Your API with Redis by Jane Paek - Redis Day Seattle 2020
Protecting Your API with Redis by Jane Paek - Redis Day Seattle 2020
 
The Happy Marriage of Redis and Protobuf by Scott Haines of Twilio - Redis Da...
The Happy Marriage of Redis and Protobuf by Scott Haines of Twilio - Redis Da...The Happy Marriage of Redis and Protobuf by Scott Haines of Twilio - Redis Da...
The Happy Marriage of Redis and Protobuf by Scott Haines of Twilio - Redis Da...
 
SQL, Redis and Kubernetes by Paul Stanton of Windocks - Redis Day Seattle 2020
SQL, Redis and Kubernetes by Paul Stanton of Windocks - Redis Day Seattle 2020SQL, Redis and Kubernetes by Paul Stanton of Windocks - Redis Day Seattle 2020
SQL, Redis and Kubernetes by Paul Stanton of Windocks - Redis Day Seattle 2020
 
Rust and Redis - Solving Problems for Kubernetes by Ravi Jagannathan of VMwar...
Rust and Redis - Solving Problems for Kubernetes by Ravi Jagannathan of VMwar...Rust and Redis - Solving Problems for Kubernetes by Ravi Jagannathan of VMwar...
Rust and Redis - Solving Problems for Kubernetes by Ravi Jagannathan of VMwar...
 
Redis for Data Science and Engineering by Dmitry Polyakovsky of Oracle
Redis for Data Science and Engineering by Dmitry Polyakovsky of OracleRedis for Data Science and Engineering by Dmitry Polyakovsky of Oracle
Redis for Data Science and Engineering by Dmitry Polyakovsky of Oracle
 
Practical Use Cases for ACLs in Redis 6 by Jamie Scott - Redis Day Seattle 2020
Practical Use Cases for ACLs in Redis 6 by Jamie Scott - Redis Day Seattle 2020Practical Use Cases for ACLs in Redis 6 by Jamie Scott - Redis Day Seattle 2020
Practical Use Cases for ACLs in Redis 6 by Jamie Scott - Redis Day Seattle 2020
 
Moving Beyond Cache by Yiftach Shoolman Redis Labs - Redis Day Seattle 2020
Moving Beyond Cache by Yiftach Shoolman Redis Labs - Redis Day Seattle 2020Moving Beyond Cache by Yiftach Shoolman Redis Labs - Redis Day Seattle 2020
Moving Beyond Cache by Yiftach Shoolman Redis Labs - Redis Day Seattle 2020
 
Leveraging Redis for System Monitoring by Adam McCormick of SBG - Redis Day S...
Leveraging Redis for System Monitoring by Adam McCormick of SBG - Redis Day S...Leveraging Redis for System Monitoring by Adam McCormick of SBG - Redis Day S...
Leveraging Redis for System Monitoring by Adam McCormick of SBG - Redis Day S...
 
JSON in Redis - When to use RedisJSON by Jay Won of Coupang - Redis Day Seatt...
JSON in Redis - When to use RedisJSON by Jay Won of Coupang - Redis Day Seatt...JSON in Redis - When to use RedisJSON by Jay Won of Coupang - Redis Day Seatt...
JSON in Redis - When to use RedisJSON by Jay Won of Coupang - Redis Day Seatt...
 
Highly Available Persistent Session Management Service by Mohamed Elmergawi o...
Highly Available Persistent Session Management Service by Mohamed Elmergawi o...Highly Available Persistent Session Management Service by Mohamed Elmergawi o...
Highly Available Persistent Session Management Service by Mohamed Elmergawi o...
 
Anatomy of a Redis Command by Madelyn Olson of Amazon Web Services - Redis Da...
Anatomy of a Redis Command by Madelyn Olson of Amazon Web Services - Redis Da...Anatomy of a Redis Command by Madelyn Olson of Amazon Web Services - Redis Da...
Anatomy of a Redis Command by Madelyn Olson of Amazon Web Services - Redis Da...
 
Building a Multi-dimensional Analytics Engine with RedisGraph by Matthew Goos...
Building a Multi-dimensional Analytics Engine with RedisGraph by Matthew Goos...Building a Multi-dimensional Analytics Engine with RedisGraph by Matthew Goos...
Building a Multi-dimensional Analytics Engine with RedisGraph by Matthew Goos...
 
RediSearch 1.6 by Pieter Cailliau - Redis Day Bangalore 2020
RediSearch 1.6 by Pieter Cailliau - Redis Day Bangalore 2020RediSearch 1.6 by Pieter Cailliau - Redis Day Bangalore 2020
RediSearch 1.6 by Pieter Cailliau - Redis Day Bangalore 2020
 
RedisGraph 2.0 by Pieter Cailliau - Redis Day Bangalore 2020
RedisGraph 2.0 by Pieter Cailliau - Redis Day Bangalore 2020RedisGraph 2.0 by Pieter Cailliau - Redis Day Bangalore 2020
RedisGraph 2.0 by Pieter Cailliau - Redis Day Bangalore 2020
 
RedisTimeSeries 1.2 by Pieter Cailliau - Redis Day Bangalore 2020
RedisTimeSeries 1.2 by Pieter Cailliau - Redis Day Bangalore 2020RedisTimeSeries 1.2 by Pieter Cailliau - Redis Day Bangalore 2020
RedisTimeSeries 1.2 by Pieter Cailliau - Redis Day Bangalore 2020
 
RedisAI 0.9 by Sherin Thomas of Tensorwerk - Redis Day Bangalore 2020
RedisAI 0.9 by Sherin Thomas of Tensorwerk - Redis Day Bangalore 2020RedisAI 0.9 by Sherin Thomas of Tensorwerk - Redis Day Bangalore 2020
RedisAI 0.9 by Sherin Thomas of Tensorwerk - Redis Day Bangalore 2020
 
Rate-Limiting 30 Million requests by Vijay Lakshminarayanan and Girish Koundi...
Rate-Limiting 30 Million requests by Vijay Lakshminarayanan and Girish Koundi...Rate-Limiting 30 Million requests by Vijay Lakshminarayanan and Girish Koundi...
Rate-Limiting 30 Million requests by Vijay Lakshminarayanan and Girish Koundi...
 
Three Pillars of Observability by Rajalakshmi Raji Srinivasan of Site24x7 Zoh...
Three Pillars of Observability by Rajalakshmi Raji Srinivasan of Site24x7 Zoh...Three Pillars of Observability by Rajalakshmi Raji Srinivasan of Site24x7 Zoh...
Three Pillars of Observability by Rajalakshmi Raji Srinivasan of Site24x7 Zoh...
 
Solving Complex Scaling Problems by Prashant Kumar and Abhishek Jain of Myntr...
Solving Complex Scaling Problems by Prashant Kumar and Abhishek Jain of Myntr...Solving Complex Scaling Problems by Prashant Kumar and Abhishek Jain of Myntr...
Solving Complex Scaling Problems by Prashant Kumar and Abhishek Jain of Myntr...
 

Último

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Último (20)

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 

Redis: Lua scripts - a primer and use cases

  • 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 ;)