Webinar: Redis Modules - Percona · 2 Who We Are The open source home and commercial provider of...

37
Extend Redis with Modules Itamar Haber

Transcript of Webinar: Redis Modules - Percona · 2 Who We Are The open source home and commercial provider of...

Page 1: Webinar: Redis Modules - Percona · 2 Who We Are The open source home and commercial provider of Redis Open source. The leading in-memory database platform, supporting any high performance

Extend Redis with ModulesItamar Haber

Page 2: Webinar: Redis Modules - Percona · 2 Who We Are The open source home and commercial provider of Redis Open source. The leading in-memory database platform, supporting any high performance

2

Who We Are

The open source home and commercial provider of Redis

Open source. The leading in-memory database platform, supporting any high performance OLTP or OLAP use case.

[email protected]@itamarhaberChief Developer Advocate at Redis Labs

Page 3: Webinar: Redis Modules - Percona · 2 Who We Are The open source home and commercial provider of Redis Open source. The leading in-memory database platform, supporting any high performance

~10 Things About Redis

Page 4: Webinar: Redis Modules - Percona · 2 Who We Are The open source home and commercial provider of Redis Open source. The leading in-memory database platform, supporting any high performance

4

1.Redis: REmote DIctionary Server2./ rɛdɪs/: “red-iss”3.OSS: http://github.com/antirez/redis4.3-clause BSD-license: http://redis.io5. In-memory: read/write from/to RAM6.A database for: 5 data structures7.And: 4 (+1) more specialized ones

Page 5: Webinar: Redis Modules - Percona · 2 Who We Are The open source home and commercial provider of Redis Open source. The leading in-memory database platform, supporting any high performance

5

8.Developed & maintained: (mostly) Salvatore Sanfilippo (a.k.a. @antirez) and his OSS team at @RedisLabs

9.History: v1.0 August 9th, 2009… v3.2.4 Septmeber 26th, 2016

10.“The Leatherman™ of Databases”:mostly used as a DB, cache & broker

Page 6: Webinar: Redis Modules - Percona · 2 Who We Are The open source home and commercial provider of Redis Open source. The leading in-memory database platform, supporting any high performance

6

11.A couple or so of extra features:(a) atomicity; (b) blocking wait;(c) configurable persistence;(d) data expiration and (e) eviction; as well as transactions, PubSub, Luascripts, high availability & clustering

12.Next version (v4.0): MODULES!

Page 7: Webinar: Redis Modules - Percona · 2 Who We Are The open source home and commercial provider of Redis Open source. The leading in-memory database platform, supporting any high performance

7

Redis 1011. Redis is “NoSQL”0. No (explicit) schema, access by key1. Key -> structure -> data

Page 8: Webinar: Redis Modules - Percona · 2 Who We Are The open source home and commercial provider of Redis Open source. The leading in-memory database platform, supporting any high performance

8

Redis data stratav1.0 Strings

ListsSets

v1.2 SortedSets

v2.0 Hashes

v2.2 Bit arraysv2.8.9 HyperLogLogsv3.2 Geo Sets

Bit fieldsv4 MODULES!

and a brain!

Page 9: Webinar: Redis Modules - Percona · 2 Who We Are The open source home and commercial provider of Redis Open source. The leading in-memory database platform, supporting any high performance

9

How to Redis in 3 steps:1. 150 OSS clients in 50 languages, e.g:

Java, Node.js, .NET, Python, Ruby…2. You make a request, i.e.:

PING3. The server replies, i.e.g:

PONG

Page 10: Webinar: Redis Modules - Percona · 2 Who We Are The open source home and commercial provider of Redis Open source. The leading in-memory database platform, supporting any high performance

10

~$ redis-cli127.0.0.1:6379> SET counter 1OK127.0.0.1:6379> GET counter"1"127.0.0.1:6379> INCRBY counter 1(integer) 2127.0.0.1:6379> APPEND counter b||!2b(integer) 7127.0.0.1:6379> GETSET counter "\x00Hello\xffWorld""2b||!2b"127.0.0.1:6379>

Page 11: Webinar: Redis Modules - Percona · 2 Who We Are The open source home and commercial provider of Redis Open source. The leading in-memory database platform, supporting any high performance

The Evolution of Versatility

Page 12: Webinar: Redis Modules - Percona · 2 Who We Are The open source home and commercial provider of Redis Open source. The leading in-memory database platform, supporting any high performance

12

Flexibility: model (almost) anything with basic “building blocks” and simple rules (v0.0.1)Composability: transactions (v1.2) and server-side Lua scripts (v2.6)Extensibility: modules (v4) for adding custom data structures and commands

Page 13: Webinar: Redis Modules - Percona · 2 Who We Are The open source home and commercial provider of Redis Open source. The leading in-memory database platform, supporting any high performance

MODULES! (a.k.a plugins)

Page 14: Webinar: Redis Modules - Percona · 2 Who We Are The open source home and commercial provider of Redis Open source. The leading in-memory database platform, supporting any high performance

14

Redis before modules:1. Redis is ubiquitous for fast data, fits

lots of cases (Swiss™ Army knife)2. Some use cases need special care3. Open source has its own agenda

So what can you do? FR, PR or fork

Page 15: Webinar: Redis Modules - Percona · 2 Who We Are The open source home and commercial provider of Redis Open source. The leading in-memory database platform, supporting any high performance

15

Redis with modules:1. Core still fits lots of cases2. Module extensions for special cases3. A new community-driven ecosystem4. “Give power to users to go faster”5. … and not only to users …What to expect? Nothing’s impossible!

Page 16: Webinar: Redis Modules - Percona · 2 Who We Are The open source home and commercial provider of Redis Open source. The leading in-memory database platform, supporting any high performance

16

Redis modules are:1. Dynamically (server-)loaded libraries2. Future-compatible3. (are mostly) written in C4. (nearly) as fast as the core5. GA Q4 2016

Page 17: Webinar: Redis Modules - Percona · 2 Who We Are The open source home and commercial provider of Redis Open source. The leading in-memory database platform, supporting any high performance

17

Modules let you:1. Process: where the data is at2. Compose: call core & other modules3. Extend: add new data structures

and commands

Page 18: Webinar: Redis Modules - Percona · 2 Who We Are The open source home and commercial provider of Redis Open source. The leading in-memory database platform, supporting any high performance

18

redis> ECHO "Alpha""Alpha"redis> MODULE LOAD example.soOKredis> EXAMPLE.ECHO "Bravo""Bravo"redis> ^C

~$ wc example.c13 46 520 example.c~$ gcc -fPIC -std=gnu99 -c -o example.o example.c~$ ld -o example.so example.o -shared -Bsymbolic -lc

core command

module library

“new” command

Page 19: Webinar: Redis Modules - Percona · 2 Who We Are The open source home and commercial provider of Redis Open source. The leading in-memory database platform, supporting any high performance

Redis Modules API

Page 20: Webinar: Redis Modules - Percona · 2 Who We Are The open source home and commercial provider of Redis Open source. The leading in-memory database platform, supporting any high performance

20

The API1. Where most of the effort was made2. Abstracts & isolates Redis’ internals3. The server’s (C-) binding contract4. Will not be broken once released5. Exposes three conceptual layers

Page 21: Webinar: Redis Modules - Percona · 2 Who We Are The open source home and commercial provider of Redis Open source. The leading in-memory database platform, supporting any high performance

21

Modules API layers1.Operational: admin, memory, disk,

replication, arguments, replies…2.High-level: client-like access to core

and modules’ commands3.Low-level: (almost) native access to

core data structures memory

Page 22: Webinar: Redis Modules - Percona · 2 Who We Are The open source home and commercial provider of Redis Open source. The leading in-memory database platform, supporting any high performance

22

user app

Redis client

Redis

core

data

GET foo

"bar"

101010

010101

101010

Page 23: Webinar: Redis Modules - Percona · 2 Who We Are The open source home and commercial provider of Redis Open source. The leading in-memory database platform, supporting any high performance

23

user

101010

010101

101010

High

level

API

appmodule

Page 24: Webinar: Redis Modules - Percona · 2 Who We Are The open source home and commercial provider of Redis Open source. The leading in-memory database platform, supporting any high performance

24

user

101010

010101

101010

app

Low

level

API

Page 25: Webinar: Redis Modules - Percona · 2 Who We Are The open source home and commercial provider of Redis Open source. The leading in-memory database platform, supporting any high performance

The Benchmark (Why Bother with Modules?)

Page 26: Webinar: Redis Modules - Percona · 2 Who We Are The open source home and commercial provider of Redis Open source. The leading in-memory database platform, supporting any high performance

26

1.2 1.251.05

0.1

seconds

Time needed

for summing

1,000,000

Sorted Set

scores Python

(local)

Lua API

high low

Page 27: Webinar: Redis Modules - Percona · 2 Who We Are The open source home and commercial provider of Redis Open source. The leading in-memory database platform, supporting any high performance

27

Some exemplary modules:• RediSearch – full text search• countminsketch – streaming counter• redablooms – Bloom filters

• redis-tdigest – rank estimator

Page 28: Webinar: Redis Modules - Percona · 2 Who We Are The open source home and commercial provider of Redis Open source. The leading in-memory database platform, supporting any high performance

28

redismodules.com: Redis Module Hub

Page 29: Webinar: Redis Modules - Percona · 2 Who We Are The open source home and commercial provider of Redis Open source. The leading in-memory database platform, supporting any high performance

29

What Is The Hub

1.Modules developed by: anyone2.Certified by: Redis Labs3.Licenses: Open Source & Commercial4. (will be) Distributed via: Redis Cloud

and Redis Labs Enterprise Cluster5.Where: redismodules.com

Page 30: Webinar: Redis Modules - Percona · 2 Who We Are The open source home and commercial provider of Redis Open source. The leading in-memory database platform, supporting any high performance

30

Neural Redis moduleAlpha

• A brain neural network• Simple to use, will be part of Redis• Online (threaded) training• https://github.com/antirez/neural-

redis

Page 31: Webinar: Redis Modules - Percona · 2 Who We Are The open source home and commercial provider of Redis Open source. The leading in-memory database platform, supporting any high performance

31

redis> NN.CREATE net REGRESSOR 2 3 -> 1 …(integer) 13redis> NN.OBSERVE net 1 2 -> 3redis> NN.OBSERVE net 4 5 -> 9redis> NN.OBSERVE net 3 4 -> 7redis> NN.OBSERVE net 1 1 -> 2… repeat ~6 more times

redis> NN.TRAIN net AUTOSTOPredis> NN.RUN net 1 11) "2.0776522297040843"redis> NN.RUN net 3 21) "5.1765427204933099"

Teaching it

how to add

numbers

Page 32: Webinar: Redis Modules - Percona · 2 Who We Are The open source home and commercial provider of Redis Open source. The leading in-memory database platform, supporting any high performance

32

Build your own (module)• Get Redis (unstable branch)• Read the docs under src/modules• An SDK to jumpstart:

https://github.com/RedisLabs/RedisModulesSDK

• Start coding

Page 33: Webinar: Redis Modules - Percona · 2 Who We Are The open source home and commercial provider of Redis Open source. The leading in-memory database platform, supporting any high performance

33

Hack for Fun and Profit• Online: Oct 17th

San Francisco & Tel-Aviv: Nov 11th

• World fame & cash prizes!• Register at:

https://www.hackerearth.com/sprints/redislabs-hackathon-global/

Page 34: Webinar: Redis Modules - Percona · 2 Who We Are The open source home and commercial provider of Redis Open source. The leading in-memory database platform, supporting any high performance

Thank you

Page 35: Webinar: Redis Modules - Percona · 2 Who We Are The open source home and commercial provider of Redis Open source. The leading in-memory database platform, supporting any high performance

Further Reading

Page 36: Webinar: Redis Modules - Percona · 2 Who We Are The open source home and commercial provider of Redis Open source. The leading in-memory database platform, supporting any high performance

36

1. The Redis Open Source Project Website – http://redis.io2. Redis source code on GitHub – http://github.com/antirez/redis3. Getting started:

1. An introduction to Redis data types and abstractions –http://redis.io/topics/data-types-intro

2. Try Redis (in your browser) – http://try.redis.io3. Karl Seguin’s The Little Redis Book –

http://openmymind.net/2012/1/23/The-Little-Redis-Book/4. Josiah Carlson’s Redis In Action – https://redislabs.com/ebook/redis-in-

action

4. Redis documentation – http://redis.io/documentation5. Redis commands – http://redis.io/commands6. Redis community – http://redis.io/community7. Redis Watch newsletter – https://redislabs.com/redis-watch-archive

Page 37: Webinar: Redis Modules - Percona · 2 Who We Are The open source home and commercial provider of Redis Open source. The leading in-memory database platform, supporting any high performance

37

8. Redis Loadable Modules System – http://antirez.com/news/1069. Introduction to Redis Modules API –

https://github.com/antirez/redis/blob/unstable/src/modules/INTRO.md

10. Redis Modules API reference –https://github.com/antirez/redis/blob/unstable/src/modules/API.md

11. Creating a redis Module in 15 lines of code! –https://gist.github.com/dvirsky/83fc32366d5ad82fc3dca47ed2704377