SlideShare a Scribd company logo
Day 1
Itamar Haber @itamarhaber #Redis #RedisConf
hello I am
●
●
How I Implemented the #1 Requested Feature In Redis In Less than 1 Hour with Modules
●
●
●
●
●
●
●
●
No
Gave serious
thought about
what you need
to solve?
Is there a core
Redis capability
that does it?
Do that!
Can you do it in
the app?
Is Lua good
enough?
Is there an
existing GA
module that
already does it?
Yes
No
No No
Honestly
factored cost of
taking on a new
software
project?
Yes Yes Yes
No
Is it a valid
feature request
to the core?
Yes
Yes
No
mebi
Roll
out
your
own
Try that first.
Hackers love
helping each
other 3:-)
Found a really
good name for
it, something
catchy and
cool?
Go back one
diagram. Start
at the beginning
mebi
ctx
argv argc
#include "redismodule.h"
int MyCommand(RedisModuleCtx *ctx,
RedisModuleString **argv, int argc) {
// My code here
// ...
return REDISMODULE_OK;
}
int ZPop(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
if (argc != 2) {
RedisModule_WrongArity(ctx);
return REDISMODULE_OK;
}
RedisModule_AutoMemory(ctx);
RedisModuleCallReply *rep = RedisModule_Call(
ctx, "ZRANGE", "!sllc", argv[1], 0, 0, "WITHSCORES");
if (RedisModule_CallReplyType(rep) == REDISMODULE_REPLY_ERROR) {
RedisModule_ReplyWithCallReply(ctx, rep);
return REDISMODULE_OK;
}
RedisModuleString *ele =
RedisModule_CreateStringFromCallReply(
RedisModule_CallReplyArrayElement(arr, 0));
RedisModule_Call(ctx, "ZREM", "ss", key, ele);
RedisModule_ReplyWithCallReply(ctx, rep);
return REDISMODULE_OK;
}
// Registering the module and its commands
int RedisModule_OnLoad(RedisModuleCtx *ctx,
RedisModuleString **argv, int argc) {
if (RedisModule_Init(ctx, "zpop", 1,
REDISMODULE_APIVER_1) == REDISMODULE_ERR) {
return REDISMODULE_ERR;
}
if (RedisModule_CreateCommand(ctx,
"z.pop", ZPop, "Write", 1, 1, 1) ==
REDISMODULE_ERR) {
return REDISMODULE_ERR;
}
return REDISMODULE_OK;
}
# Compile it on Linux:
$ gcc -fPIC -std=gnu99 -c -o zpop.o zpop.c
$ ld -o zpop.so zpop.o -shared -Bsymbolic -lc
# Compile it on OSX:
$ gcc -dynamic -fno-common -std=gnu99 -c -o zpop.o zpop.c
$ ld -o zpop.so zpop.o -bundle -undefined dynamic_lookup
-lc
# Run it:
$ redis-server --loadmodule ./zpop.so
# Use it:
$ redis-cli
redis> ZADD z 0 a 1 b 3 c
(integer) 3
redis> Z.POP z
"a"
RedisModule_CallReply
RedisModule_WrongArity()
RedisModule_Call()
●
●
●
●
How I Implemented the #1 Requested Feature In Redis In Less than 1 Hour with Modules
How I Implemented the #1 Requested Feature In Redis In Less than 1 Hour with Modules
How I Implemented the #1 Requested Feature In Redis In Less than 1 Hour with Modules
•
•
•
•
How I Implemented the #1 Requested Feature In Redis In Less than 1 Hour with Modules
How I Implemented the #1 Requested Feature In Redis In Less than 1 Hour with Modules
:

More Related Content

PDF
Lesson 2 introduction to grasshopper3D
PDF
Null object pattern
PPTX
Prototype4Production Presented at FOSSASIA2015 at Singapore
PDF
API Strategy: The Next Generation
PDF
My 10 favorite Haxe language features - Francis Bourre - Codemotion Rome 2017
PDF
Drupal Patch Reviews: Get good reviews, give good reviews. Faster.
PPTX
Untangling4
PDF
Not Your Fathers C - C Application Development In 2016
Lesson 2 introduction to grasshopper3D
Null object pattern
Prototype4Production Presented at FOSSASIA2015 at Singapore
API Strategy: The Next Generation
My 10 favorite Haxe language features - Francis Bourre - Codemotion Rome 2017
Drupal Patch Reviews: Get good reviews, give good reviews. Faster.
Untangling4
Not Your Fathers C - C Application Development In 2016

Similar to How I Implemented the #1 Requested Feature In Redis In Less than 1 Hour with Modules (20)

PDF
Design Patterns in React
PDF
An Introduction to Git (even for non-developers)
PDF
Open Day July 2019
PDF
Django best practices
PDF
Study Jam: Android for Beginners, Summary
PDF
Usable Software Design
PDF
Why Go Lang?
PDF
Introduction to Git (even for non-developers)
PDF
Критика "библиотечного" подхода в разработке под Android. UA Mobile 2016.
PDF
Supporting SDKs in Seven Different Programming Languages While Maintaining Sa...
PDF
Introduction of Tools for providing rich user experience in debugger
PDF
Transitioning to Native
PDF
Introduction to Git (even for non-developers!)
PDF
Open data for good
PDF
React native: building native iOS apps with javascript
PDF
Professional JavaScript: AntiPatterns
PDF
Reactive datastore demo (2020 03-21)
PPTX
Alt Dot Net Usergroup: Does the world end if you stop using Visual Studio?
PDF
Docker and Go: why did we decide to write Docker in Go?
Design Patterns in React
An Introduction to Git (even for non-developers)
Open Day July 2019
Django best practices
Study Jam: Android for Beginners, Summary
Usable Software Design
Why Go Lang?
Introduction to Git (even for non-developers)
Критика "библиотечного" подхода в разработке под Android. UA Mobile 2016.
Supporting SDKs in Seven Different Programming Languages While Maintaining Sa...
Introduction of Tools for providing rich user experience in debugger
Transitioning to Native
Introduction to Git (even for non-developers!)
Open data for good
React native: building native iOS apps with javascript
Professional JavaScript: AntiPatterns
Reactive datastore demo (2020 03-21)
Alt Dot Net Usergroup: Does the world end if you stop using Visual Studio?
Docker and Go: why did we decide to write Docker in Go?
Ad

More from Itamar Haber (17)

PDF
Redis v5 & Streams
PDF
Redis Modules API - an introduction
PDF
Redis Lua Scripts
PDF
Introduction to Redis
PDF
Redis Streams - Fiverr Tech5 meetup
PPTX
Developing a Redis Module - Hackathon Kickoff
PDF
Extend Redis with Modules
PDF
Leveraging Probabilistic Data Structures for Real Time Analytics with Redis M...
PDF
Power to the People: Redis Lua Scripts
PDF
What's new in Redis v3.2
PPTX
Redis Developers Day 2015 - Secondary Indexes and State of Lua
PDF
Use Redis in Odd and Unusual Ways
PPTX
Why Your MongoDB Needs Redis
PPTX
Redis & MongoDB: Stop Big Data Indigestion Before It Starts
PPTX
Benchmarking Redis by itself and versus other NoSQL databases
PPTX
Redis Indices (#RedisTLV)
PPTX
Redis Use Patterns (DevconTLV June 2014)
Redis v5 & Streams
Redis Modules API - an introduction
Redis Lua Scripts
Introduction to Redis
Redis Streams - Fiverr Tech5 meetup
Developing a Redis Module - Hackathon Kickoff
Extend Redis with Modules
Leveraging Probabilistic Data Structures for Real Time Analytics with Redis M...
Power to the People: Redis Lua Scripts
What's new in Redis v3.2
Redis Developers Day 2015 - Secondary Indexes and State of Lua
Use Redis in Odd and Unusual Ways
Why Your MongoDB Needs Redis
Redis & MongoDB: Stop Big Data Indigestion Before It Starts
Benchmarking Redis by itself and versus other NoSQL databases
Redis Indices (#RedisTLV)
Redis Use Patterns (DevconTLV June 2014)
Ad

Recently uploaded (20)

PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
cuic standard and advanced reporting.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Big Data Technologies - Introduction.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Electronic commerce courselecture one. Pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
NewMind AI Weekly Chronicles - August'25 Week I
The Rise and Fall of 3GPP – Time for a Sabbatical?
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
sap open course for s4hana steps from ECC to s4
MYSQL Presentation for SQL database connectivity
Advanced methodologies resolving dimensionality complications for autism neur...
Encapsulation_ Review paper, used for researhc scholars
cuic standard and advanced reporting.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Big Data Technologies - Introduction.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Electronic commerce courselecture one. Pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Understanding_Digital_Forensics_Presentation.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
Digital-Transformation-Roadmap-for-Companies.pptx

How I Implemented the #1 Requested Feature In Redis In Less than 1 Hour with Modules

  • 1. Day 1 Itamar Haber @itamarhaber #Redis #RedisConf
  • 6. No Gave serious thought about what you need to solve? Is there a core Redis capability that does it? Do that! Can you do it in the app? Is Lua good enough? Is there an existing GA module that already does it? Yes No No No Honestly factored cost of taking on a new software project? Yes Yes Yes No Is it a valid feature request to the core? Yes Yes No mebi Roll out your own Try that first. Hackers love helping each other 3:-)
  • 7. Found a really good name for it, something catchy and cool? Go back one diagram. Start at the beginning mebi
  • 8. ctx argv argc #include "redismodule.h" int MyCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) { // My code here // ... return REDISMODULE_OK; }
  • 9. int ZPop(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) { if (argc != 2) { RedisModule_WrongArity(ctx); return REDISMODULE_OK; } RedisModule_AutoMemory(ctx); RedisModuleCallReply *rep = RedisModule_Call( ctx, "ZRANGE", "!sllc", argv[1], 0, 0, "WITHSCORES"); if (RedisModule_CallReplyType(rep) == REDISMODULE_REPLY_ERROR) { RedisModule_ReplyWithCallReply(ctx, rep); return REDISMODULE_OK; } RedisModuleString *ele = RedisModule_CreateStringFromCallReply( RedisModule_CallReplyArrayElement(arr, 0)); RedisModule_Call(ctx, "ZREM", "ss", key, ele); RedisModule_ReplyWithCallReply(ctx, rep); return REDISMODULE_OK; }
  • 10. // Registering the module and its commands int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) { if (RedisModule_Init(ctx, "zpop", 1, REDISMODULE_APIVER_1) == REDISMODULE_ERR) { return REDISMODULE_ERR; } if (RedisModule_CreateCommand(ctx, "z.pop", ZPop, "Write", 1, 1, 1) == REDISMODULE_ERR) { return REDISMODULE_ERR; } return REDISMODULE_OK; }
  • 11. # Compile it on Linux: $ gcc -fPIC -std=gnu99 -c -o zpop.o zpop.c $ ld -o zpop.so zpop.o -shared -Bsymbolic -lc # Compile it on OSX: $ gcc -dynamic -fno-common -std=gnu99 -c -o zpop.o zpop.c $ ld -o zpop.so zpop.o -bundle -undefined dynamic_lookup -lc # Run it: $ redis-server --loadmodule ./zpop.so # Use it: $ redis-cli redis> ZADD z 0 a 1 b 3 c (integer) 3 redis> Z.POP z "a"
  • 21. :