Getting Started with Redis

Preview:

DESCRIPTION

Getting Started with Redis by Sam Davarnia for SocalCodeCamp

Citation preview

Getting Started with Redis Sam Davarnia @samdvr

What is Redis? ¡ Key/Value Store

¡ Not just strings

¡  Persistence

¡  FAST

¡  Scalable

Redis is fast

5 Data Types ¡  Strings

¡ Hashes

¡  Lists

¡  Sets

¡  Sorted Sets

Strings ¡  The most simple data type

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

Use Cases ¡  Simple caching with expiration

¡  Counts & Sums using INCRBY/DECRBY

SET        blog_count    10    INCR  blog_count  GET      blog_count          “11”    

Hashes ¡  Similar to Ruby & Python hashes

they are maps with keys & values

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

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”    

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

Use Cases ¡ Great for queues

¡  Activity feeds

Sets ¡ Unordered collections of unique elements

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

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

Use Cases ¡  Tagging systems

¡  Tracking unique visitors

¡ Getting random elements from a collection

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

sorted

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

Use cases ¡  Leaderboards

¡ Notification systems

¡  Autocomplete searches

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

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.

Use Cases ¡  Chat System

¡ Real-time reporting and analytics

Persistence ¡ RDB ¡  Point in time snapshot

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

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

MySQL

Slave(Read-only)

Slave(Read-only)

Master(Write-only)

Redis as a Service ¡ Managed Redis services

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

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

Questions/Demo

Recommended