+ All Categories
Home > Documents > Preparing for World Domination - Redis Labs · 2/5/2017  · A Year of Redis Modules Dvir Volk...

Preparing for World Domination - Redis Labs · 2/5/2017  · A Year of Redis Modules Dvir Volk...

Date post: 11-Oct-2020
Category:
Upload: others
View: 2 times
Download: 0 times
Share this document with a friend
38
Preparing for World Domination A Year of Redis Modules Dvir Volk @dvirsky
Transcript
Page 1: Preparing for World Domination - Redis Labs · 2/5/2017  · A Year of Redis Modules Dvir Volk @dvirsky. A Quick Recap of Redis Key ... Full-Text Search. RediSearch V1 From-Scratch

Preparing for World Domination

A Year of Redis Modules

Dvir Volk@dvirsky

Page 2: Preparing for World Domination - Redis Labs · 2/5/2017  · A Year of Redis Modules Dvir Volk @dvirsky. A Quick Recap of Redis Key ... Full-Text Search. RediSearch V1 From-Scratch

A Quick Recap of Redis

Key

"I'm a Plain Text String!"

{ A: “foo”, B: “bar”, C: “baz” }

Strings / Bitmaps / BitFields

Hash Tables (objects!)

Linked Lists

Sets

Sorted Sets

Geo Sets

HyperLogLog

{ A , B , C , D , E }

[ A → B → C → D → E ]

{ A: 0.1, B: 0.3, C: 100, D: 1337 }

{ A: (51.5, 0.12), B: (32.1, 34.7) }

00110101 11001110 10101010

Page 3: Preparing for World Domination - Redis Labs · 2/5/2017  · A Year of Redis Modules Dvir Volk @dvirsky. A Quick Recap of Redis Key ... Full-Text Search. RediSearch V1 From-Scratch

But Can Redis Do X?

Page 4: Preparing for World Domination - Redis Labs · 2/5/2017  · A Year of Redis Modules Dvir Volk @dvirsky. A Quick Recap of Redis Key ... Full-Text Search. RediSearch V1 From-Scratch

So You Want a New Feature?

● Convince @antirez● Fork Redis● Build Your Own Database!

Page 5: Preparing for World Domination - Redis Labs · 2/5/2017  · A Year of Redis Modules Dvir Volk @dvirsky. A Quick Recap of Redis Key ... Full-Text Search. RediSearch V1 From-Scratch

First Mention of Modules: Redis 1.0

Page 6: Preparing for World Domination - Redis Labs · 2/5/2017  · A Year of Redis Modules Dvir Volk @dvirsky. A Quick Recap of Redis Key ... Full-Text Search. RediSearch V1 From-Scratch

Fast Forward 7 Years...

● Discussion began last Redis Day TLV● Modules were the main feature for 4.0● The key differences this time:

▪ Isolated API ▪ ABI Backwards Compatibility

Page 7: Preparing for World Domination - Redis Labs · 2/5/2017  · A Year of Redis Modules Dvir Volk @dvirsky. A Quick Recap of Redis Key ... Full-Text Search. RediSearch V1 From-Scratch

And So The Journey Began...

● Salvatore started work on the flight back● We had a working module 2 weeks later● And it was already usable!

● It could add commands

● It could call Redis like a Lua script

Page 8: Preparing for World Domination - Redis Labs · 2/5/2017  · A Year of Redis Modules Dvir Volk @dvirsky. A Quick Recap of Redis Key ... Full-Text Search. RediSearch V1 From-Scratch

It Was Awesome!

Page 9: Preparing for World Domination - Redis Labs · 2/5/2017  · A Year of Redis Modules Dvir Volk @dvirsky. A Quick Recap of Redis Key ... Full-Text Search. RediSearch V1 From-Scratch

First iteration of the API

● Secret-ish for 2 months ● Redis command handling● High level, simple, Lua like API● Direct access to string keys● Replication control● Low level, faster API

Page 10: Preparing for World Domination - Redis Labs · 2/5/2017  · A Year of Redis Modules Dvir Volk @dvirsky. A Quick Recap of Redis Key ... Full-Text Search. RediSearch V1 From-Scratch

Initial Experiments

● Some “missing commands”:● HGETSET

● PREPEND

● PDEL

● Etc

● Image Manipulation● PAM Auth● And...

Page 11: Preparing for World Domination - Redis Labs · 2/5/2017  · A Year of Redis Modules Dvir Volk @dvirsky. A Quick Recap of Redis Key ... Full-Text Search. RediSearch V1 From-Scratch

The Obligatory

Page 12: Preparing for World Domination - Redis Labs · 2/5/2017  · A Year of Redis Modules Dvir Volk @dvirsky. A Quick Recap of Redis Key ... Full-Text Search. RediSearch V1 From-Scratch

Starting to Get Serious

● That was very cool, but we wanted more:● Probabilistic Data Structures

● Bloom Filter

● Streaming Top-k

● etc.

● Full-Text Search

Page 13: Preparing for World Domination - Redis Labs · 2/5/2017  · A Year of Redis Modules Dvir Volk @dvirsky. A Quick Recap of Redis Key ... Full-Text Search. RediSearch V1 From-Scratch

RediSearch V1

▪ From-Scratch search index over redis▪ Uses String DMA for holding compressed index data▪ This allows efficient compression of data▪ Includes stemming, exact phrase match, etc.▪ Up to X5 faster than Elastic / Solr

Page 14: Preparing for World Domination - Redis Labs · 2/5/2017  · A Year of Redis Modules Dvir Volk @dvirsky. A Quick Recap of Redis Key ... Full-Text Search. RediSearch V1 From-Scratch

Search in Action> FT.CREATE products SCHEMA title TEXT price NUMERICOK> FT.ADD products id1 1.0 FIELDS title "LG 42'' LCD TV" price 500OK> FT.ADD products id2 1.0 FIELDS title "Toshiba 40'' LCD TV" price 400OK> FT.SEARCH products "lcd tv" FILTER price 450 +inf1) (integer) 12) "id1"3) 1) "title" 2) "LG 42'' LCD TV" 3) "price" 4) "500"

Page 15: Preparing for World Domination - Redis Labs · 2/5/2017  · A Year of Redis Modules Dvir Volk @dvirsky. A Quick Recap of Redis Key ... Full-Text Search. RediSearch V1 From-Scratch

Modules API v2 - Custom Types, Blocking

● Bye Bye Strings, hello data types!● Add any data type to redis at native speeds

● Much greater degree of freedom

● Much more testable

● Block the client, work in the background● Run heavy computation or network in the background

● Let redis handle other calls

● Return when ready!

Page 16: Preparing for World Domination - Redis Labs · 2/5/2017  · A Year of Redis Modules Dvir Volk @dvirsky. A Quick Recap of Redis Key ... Full-Text Search. RediSearch V1 From-Scratch

Working Asynchronously

● In normal operation, each handler blocks Redis● Blocking keeps client waiting but not Redis

Handle Request #1

Background Work

Send ReplyRedis Main Thread

Module Thread

Handle Request #2

Page 17: Preparing for World Domination - Redis Labs · 2/5/2017  · A Year of Redis Modules Dvir Volk @dvirsky. A Quick Recap of Redis Key ... Full-Text Search. RediSearch V1 From-Scratch

This allowed some interesting stuff

● AutoComplete for search● Machine Learning models● Neural-Redis training in the background● Secondary Indexing using efficient structures

Page 18: Preparing for World Domination - Redis Labs · 2/5/2017  · A Year of Redis Modules Dvir Volk @dvirsky. A Quick Recap of Redis Key ... Full-Text Search. RediSearch V1 From-Scratch

Redis-ML

● Database for ML models● Train wherever you want● Store the result in redis● Query models in real time● Scale your models beyond a single machine

Page 19: Preparing for World Domination - Redis Labs · 2/5/2017  · A Year of Redis Modules Dvir Volk @dvirsky. A Quick Recap of Redis Key ... Full-Text Search. RediSearch V1 From-Scratch

Redis Module

Tree Ensembles

Linear Regression

Logistic Regression

Matrix + Vector Operations

More to come...

The Redis-ML Module

Page 20: Preparing for World Domination - Redis Labs · 2/5/2017  · A Year of Redis Modules Dvir Volk @dvirsky. A Quick Recap of Redis Key ... Full-Text Search. RediSearch V1 From-Scratch

Neural Redis

● Developed by Salvatore● Training is done inside Redis● Online continuous training process● Builds Fully Connected NNs

Page 21: Preparing for World Domination - Redis Labs · 2/5/2017  · A Year of Redis Modules Dvir Volk @dvirsky. A Quick Recap of Redis Key ... Full-Text Search. RediSearch V1 From-Scratch

The Trouble With JSON

● Right now people save JSON objects as strings● Changing a property means read, modify, write● Accessing a single property means loading the entire object● This S.U.C.K.S!

● Slow

● Un-atomic

● CPU Wasteful

● Karmically wrong

● Sucks Ass

Page 22: Preparing for World Domination - Redis Labs · 2/5/2017  · A Year of Redis Modules Dvir Volk @dvirsky. A Quick Recap of Redis Key ... Full-Text Search. RediSearch V1 From-Scratch

ReJSON to the rescue

● Store objects as actual object trees● Update elements atomically● Retrieve part of an object

> JSON.SET doc . '{ "foo": "bar", "baz": [1,2] }'> JSON.SET doc .goo true> JSON.NUMINCRBY doc .baz[0] 9> JSON.GET doc .baz"[10,2]"> JSON.GET doc ."{\"foo\":\"bar\",\"baz\":[10,2],\"goo\":true}"

Page 23: Preparing for World Domination - Redis Labs · 2/5/2017  · A Year of Redis Modules Dvir Volk @dvirsky. A Quick Recap of Redis Key ... Full-Text Search. RediSearch V1 From-Scratch

Redis-Secondary

● Schema aware secondary indexes● Integers, floats, booleans, strings, etc

● Either a raw data type or automatic index● Treat HASH keys as objects or table rows● SQL-like WHERE clauses as proxies to redis commands

Page 24: Preparing for World Domination - Redis Labs · 2/5/2017  · A Year of Redis Modules Dvir Volk @dvirsky. A Quick Recap of Redis Key ... Full-Text Search. RediSearch V1 From-Scratch

Secondary Indexing In Action> IDX.CREATE users_name_age TYPE HASH SCHEMA name STRING age INT32

> IDX.INTO users_name_age HMSET user1 name "alice" age 30

> IDX.INTO users_name_age HMSET user2 name "bob" age 25

> IDX.FROM users_name_age WHERE "name LIKE 'b%'" HGET $ name

1) user1

2) "bob"

> IDX.FROM users_name_age WHERE "name >= 'alice' AND age < 31" HGETALL $

1) user1

...

Page 25: Preparing for World Domination - Redis Labs · 2/5/2017  · A Year of Redis Modules Dvir Volk @dvirsky. A Quick Recap of Redis Key ... Full-Text Search. RediSearch V1 From-Scratch

The Start of a Module Ecosystem

● Modules were launched May 2016 at RedisConf● Initial modules started to appear, mostly toy projects● We launched Modules-Hub

Page 26: Preparing for World Domination - Redis Labs · 2/5/2017  · A Year of Redis Modules Dvir Volk @dvirsky. A Quick Recap of Redis Key ... Full-Text Search. RediSearch V1 From-Scratch

Redis Modules Hack 2016

● A global, distributed hackathon● With on-site events in TLV and SF● Some very interesting projects● We gave them cash!

Page 27: Preparing for World Domination - Redis Labs · 2/5/2017  · A Year of Redis Modules Dvir Volk @dvirsky. A Quick Recap of Redis Key ... Full-Text Search. RediSearch V1 From-Scratch

First Place - Redis-Cell

● Author: Brandur Leach● Advanced rate limiting algorithm● Actually written in Rust, not C

CL.THROTTLE user123 15 30 60 1

▲ ▲ ▲ ▲ ▲

| | | | └───── apply 1 token (default if omitted)

| | └──┴─────── 30 tokens / 60 seconds

| └───────────── 15 max_burst

└─────────────────── key "user123"

Page 28: Preparing for World Domination - Redis Labs · 2/5/2017  · A Year of Redis Modules Dvir Volk @dvirsky. A Quick Recap of Redis Key ... Full-Text Search. RediSearch V1 From-Scratch

Notable Mention: Redis-Graph

● Author: Roi Lipman● A fast graph database implemented in Redis● Subset of Cipher (Neo4J QL) implementation● Uses Redis HASH keys as nodes

GRAPH.QUERY presidents

"MATCH (president)-[born]->(state:Hawaii)

RETURN president.name, president.age"

Page 29: Preparing for World Domination - Redis Labs · 2/5/2017  · A Year of Redis Modules Dvir Volk @dvirsky. A Quick Recap of Redis Key ... Full-Text Search. RediSearch V1 From-Scratch

Other Cool Modules

● Time-series aggregation engine● Pyrecks - Python function execution● Statsd reporting of Redis metrics● Zstd value compression● Time decaying popularity ranking● Shared memory support● And many more!

Page 30: Preparing for World Domination - Redis Labs · 2/5/2017  · A Year of Redis Modules Dvir Volk @dvirsky. A Quick Recap of Redis Key ... Full-Text Search. RediSearch V1 From-Scratch

So What’s Next?

Page 31: Preparing for World Domination - Redis Labs · 2/5/2017  · A Year of Redis Modules Dvir Volk @dvirsky. A Quick Recap of Redis Key ... Full-Text Search. RediSearch V1 From-Scratch

Coming In Redise

● To be released soon in Redis Labs’ enterprise cluster● Pre-bundled modules:

● RediSearch

● ReJSON

● Secondary

● Redis-ML

● Use your own modules at their own risk

Page 32: Preparing for World Domination - Redis Labs · 2/5/2017  · A Year of Redis Modules Dvir Volk @dvirsky. A Quick Recap of Redis Key ... Full-Text Search. RediSearch V1 From-Scratch

Stable But Not Done...

● Redis does not yet officially support modules!● 4.0 is due in the coming weeks● The API can be considered 99% stable● But it’s far from complete

Page 33: Preparing for World Domination - Redis Labs · 2/5/2017  · A Year of Redis Modules Dvir Volk @dvirsky. A Quick Recap of Redis Key ... Full-Text Search. RediSearch V1 From-Scratch

TODO: Improved low-level API

● The current API is missing some basic Redis stuff:● Keyspace iteration

● HGETALL

● Geo commands

● etc

Page 34: Preparing for World Domination - Redis Labs · 2/5/2017  · A Year of Redis Modules Dvir Volk @dvirsky. A Quick Recap of Redis Key ... Full-Text Search. RediSearch V1 From-Scratch

TODO: Thread Safe Operations

● Beyond the blocking API● Allow modules to operate on Redis from a bg-thread● Allow modules to schedule periodic timers● Per-key read/write locks - allow real multi threading!

Page 35: Preparing for World Domination - Redis Labs · 2/5/2017  · A Year of Redis Modules Dvir Volk @dvirsky. A Quick Recap of Redis Key ... Full-Text Search. RediSearch V1 From-Scratch

TODO: Hooks

● Get notified when a command is executed● Get notified when keys you are interested change● Allow overriding commands● This opens the door to:

● New data structures for existing commands

● REALLY automatic indexing

● Robust encryption and security models

● etc

Page 36: Preparing for World Domination - Redis Labs · 2/5/2017  · A Year of Redis Modules Dvir Volk @dvirsky. A Quick Recap of Redis Key ... Full-Text Search. RediSearch V1 From-Scratch

TODO: Clustered Modules API

● Allow cluster shards to pass messages automatically● Allow map-reduce operations for multi-shards● Abstract cluster topology away● Allow things like search to REALLY SCALE

● The goal: Disque will become a module!

Page 37: Preparing for World Domination - Redis Labs · 2/5/2017  · A Year of Redis Modules Dvir Volk @dvirsky. A Quick Recap of Redis Key ... Full-Text Search. RediSearch V1 From-Scratch

So You Want to Write a Module?

● It’s really easy, we promise● No special linking required, just one header file● The documentation is excellent● Redis includes a lot of simple examples● Use RedisModulesSDK

Page 38: Preparing for World Domination - Redis Labs · 2/5/2017  · A Year of Redis Modules Dvir Volk @dvirsky. A Quick Recap of Redis Key ... Full-Text Search. RediSearch V1 From-Scratch

Thank You!


Recommended