28
Redis Damon Cortesi (@dacort) Untitled Startup (RowFeeder)

Redis

Embed Size (px)

DESCRIPTION

A brief introduction to Redis I gave at Seattle Tech Startups meetup on November 11, 2010. Provides some example use cases.

Citation preview

Page 1: Redis

RedisDamon Cortesi (@dacort)

Untitled Startup (RowFeeder)

Page 2: Redis

Movember

• Help support prostate cancer research

• http://bit.ly/mo_dacort

Page 3: Redis

Up and Running

• wget http://redis.googlecode.com/files/redis-2.0.4.tar.gz

• tar xzvf redis-2.0.4.tar.gz

• cd redis-2.0.4

• make

• ./redis-server

Page 5: Redis

http://try.redis-db.com

Page 6: Redis

101

• Key/Value Store on Steroids

• memcache?

• Persistent

• Push/Pop

• Data types

• Fast - 110000 SETs/sec, 81000 GETs/sec

Page 7: Redis

Redis Data Types

• Strings

• Lists

• Sets

• Sorted/Scored Sets

• Hashes

Page 8: Redis

But wait, there’s more!

• Clustering

• Replication

• Master/Slave

• Publish/Subscribe

Page 9: Redis

Use Cases

• Queue Processing

• Set Intersection

• Stats Tracking/Leaderboards

Page 10: Redis

Keyword Filter

Geo Filter

Other Custom Filters

Resque Queue (redis)

Resque Workers

MongoDB Status Storage

External Data Tagging- bit.ly, geo, klout

rowfeeder.com

MySQL User & Track Data

Slave MySQLGeo Lookups

Memcache

Web Status Processing

GoogleSpreadsheet

Page 11: Redis

Queues

• Resque - Killer Ruby library for background jobs

• RowFeeder - 428,811,359 items processed

a b c d

LPOP

RPUSH

Page 12: Redis
Page 13: Redis
Page 14: Redis

Set Intersections

• Goal: Contact Ashton Kutcher on Twitter

• Approach: Is there anybody I can DM that can DM Ashton, or a friend of his?

Page 15: Redis

Step 1

• Are any of my followers his friends?

• SADD - Add specified member to the set

• SINTER - Intersection of N sets

Page 16: Redis
Page 17: Redis

Step 2

• Can I DM somebody that can DM a friend of his?

• ?t

?

Page 18: Redis
Page 19: Redis

Sweet!

Page 20: Redis

Scoreboards

• Sorted ZSets

• ZINCRBY - Increment Operator

• ZRANGE - Sort + Subset

Page 21: Redis

• Tracks Twitter/Facebook Posts

• ~4,000 keywords monitored in real-time

• ~2MM posts/day

• Sometimes...

Page 22: Redis

What’s Blowing Up?

Page 23: Redis

Step 1

• Maintain counters of all matched terms

• Increment the “stream::kw::time” key by 1

Page 24: Redis

Step 2

• 5 minute running average of the top 10 terms

Page 25: Redis
Page 26: Redis
Page 27: Redis

Limitations

• Greedy with memory

• If it grows to XGB...it will stay there

• (Not optimal if a queue backs up)

• All in RAM / Atomicity

• 2.0 solves both of these!

• NoSQL

Page 28: Redis

Questions

• @dacort

• damon [at] untitledstartup.com