Top Banner
Getting Started with Redis Sam Davarnia @samdvr
21

Getting Started with Redis

Aug 19, 2014

Download

Engineering

Sam Davarnia

Getting Started with Redis by Sam Davarnia
for SocalCodeCamp
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Getting Started with Redis

Getting Started with Redis Sam Davarnia @samdvr

Page 2: Getting Started with Redis

What is Redis? ¡ Key/Value Store

¡ Not just strings

¡  Persistence

¡  FAST

¡  Scalable

Page 3: Getting Started with Redis

Redis is fast

Page 4: Getting Started with Redis

5 Data Types ¡  Strings

¡ Hashes

¡  Lists

¡  Sets

¡  Sorted Sets

Page 5: Getting Started with Redis

Strings ¡  The most simple data type

¡  Common Commands ¡  SET/GET (MSET/MGET) ¡  INCR/DECR ¡  INCRBY /INCRBYFLOAT ¡  DECRBY / DECRBYFLOAT ¡  STRLEN

Page 6: Getting Started with Redis

Use Cases ¡  Simple caching with expiration

¡  Counts & Sums using INCRBY/DECRBY

SET        blog_count    10    INCR  blog_count  GET      blog_count          “11”    

Page 7: Getting Started with Redis

Hashes ¡  Similar to Ruby & Python hashes

they are maps with keys & values

¡  Common Commands ¡  HSET / HGET ¡  HGETALL ¡  HINCRBY / HINCRBYFLOAT

Page 8: Getting Started with Redis

Use Cases ¡ Good for representing objects and storing data types

other than strings and integers

HSET  myhash  field1  "Hello”  field2  “Everyone”  HGET  myhash  field1          “HELLO”    

Page 9: Getting Started with Redis

Lists ¡  Basically linked lists from left to right.

¡  You can push and pop elements Accessing data in the middle isn’t as fast

¡  Common Commands ¡  LSET/LINDEX ¡  LPUSH/LPOP ¡  RPUSH/RPOP ¡  LINSERT ¡  LRANGE

Page 10: Getting Started with Redis

Use Cases ¡ Great for queues

¡  Activity feeds

Page 11: Getting Started with Redis

Sets ¡ Unordered collections of unique elements

¡  Find differences between two sets, union of two sets …

¡  Common Commands ¡  SADD/SREM ¡  SMEMBERS ¡  SISMEMBER ¡  SUNION ¡  SPOP

Page 12: Getting Started with Redis

Use Cases ¡  Tagging systems

¡  Tracking unique visitors

¡ Getting random elements from a collection

Page 13: Getting Started with Redis

Sorted Sets ¡  Similar to Sets but each key should have a score to get

sorted

¡  Common Commands ¡  ZADD/ZREM ¡  ZCOUNT ¡  ZINCRBY ¡  ZRANK ¡  ZRANGE ¡  ZSCORE

Page 14: Getting Started with Redis

Use cases ¡  Leaderboards

¡ Notification systems

¡  Autocomplete searches

¡  Activity feeds based on a score or time and more..

Page 15: Getting Started with Redis

Pub/Sub ¡ Redis supports real time data propagation.

¡ Users can subscribe to a “channel” and any message sent to the channel will be published to all subscribers at the same time.

Page 16: Getting Started with Redis

Use Cases ¡  Chat System

¡ Real-time reporting and analytics

Page 17: Getting Started with Redis

Persistence ¡ RDB ¡  Point in time snapshot

¡  Append Only File (AOF) ¡  More durable than RDB but slower

Page 18: Getting Started with Redis

Scaling ¡ Redis has a master/slave replication feature similar to

MySQL

Slave(Read-only)

Slave(Read-only)

Master(Write-only)

Page 19: Getting Started with Redis

Redis as a Service ¡ Managed Redis services

Page 20: Getting Started with Redis

Resources ¡ Redis.io list of all the commands and documentation

¡  Books: ¡  Redis In Action ¡  Redis: The Definitive Guide

Page 21: Getting Started with Redis

Questions/Demo