Redis 101. A whirlwind tour of the next big thing in NoSQL data storage PETER COOPER. http://twitter.com/peterc http://coder.io/

Similar documents
CS 145: NoSQL Activity Stanford University, Fall 2015 A Quick Introdution to Redis

Classifying malware using network traffic analysis. Or how to learn Redis, git, tshark and Python in 4 hours.

Understanding the Top 5 Redis Performance Metrics

Etcetera! CMSC 491 Hadoop-Based Distributed Computing Spring 2015 Adam Shook

How To Write A Key Value Database (Kvs) In Ruby On Rails (Ruby)

@tobiastrelle. codecentric AG 1

API Analytics with Redis and Google Bigquery. javier

NoSQL replacement for SQLite (for Beatstream) Antti-Jussi Kovalainen Seminar OHJ-1860: NoSQL databases

Big Data with Component Based Software

JAVA IN THE CLOUD PAAS PLATFORM IN COMPARISON

HDB++: HIGH AVAILABILITY WITH. l TANGO Meeting l 20 May 2015 l Reynald Bourtembourg

Social Networks and the Richness of Data

Here is a quick diagram of the ULV SSO/Sync Application. Number 3 is what we deal with in this document.

Open Source Technologies on Microsoft Azure

Kafka & Redis for Big Data Solutions

The Little Redis Book is licensed under the Attribution-NonCommercial 3.0 Unported license. You should not have paid for this book.

NoSQL: Going Beyond Structured Data and RDBMS

NOSQL INTRODUCTION WITH MONGODB AND RUBY GEOFF

YouTube Vitess. Cloud-Native MySQL. Oracle OpenWorld Conference October 26, Anthony Yeh, Software Engineer, YouTube.

How to choose the right PaaS Platform?

Using the Push Notifications Extension Part 1: Certificates and Setup

Building Your First MongoDB Application

Sentimental Analysis using Hadoop Phase 2: Week 2

Last time. Today. IaaS Providers. Amazon Web Services, overview

Lab Exercise Part II: Git: A distributed version control system

Cloud Scale Distributed Data Storage. Jürmo Mehine

Python Loops and String Manipulation

New Relic & JMeter - Perfect Performance Testing

Salesforce Mobile Push Notifications Implementation Guide

.NET User Group Bern

Java, PHP & Ruby - Cloud Hosting

Accelerating Enterprise Applications and Reducing TCO with SanDisk ZetaScale Software

Going Native With Apache Cassandra. QCon London, 2014

Git - Working with Remote Repositories

Assignment # 1 (Cloud Computing Security)

How graph databases started the multi-model revolution

High Frequency Trading and NoSQL. Peter Lawrey CEO, Principal Consultant Higher Frequency Trading

Spark ΕΡΓΑΣΤΗΡΙΟ 10. Prepared by George Nikolaides 4/19/2015 1

The Cloud to the rescue!

Data storing and data access

Logistics. Database Management Systems. Chapter 1. Project. Goals for This Course. Any Questions So Far? What This Course Cannot Do.

Lecture Data Warehouse Systems

Database Management System Choices. Introduction To Database Systems CSE 373 Spring 2013

Using New Relic to Monitor Your Servers

Enterprise PaaS Evaluation Guide

Using Object Database db4o as Storage Provider in Voldemort

Scaling up = getting a better machine. Scaling out = use another server and add it to your cluster.

Apache Thrift and Ruby

Distributed File System. MCSN N. Tonellotto Complements of Distributed Enabling Platforms

NoSQL Data Base Basics

What is a stack? Do I need to know?

WHAT'S NEW WITH SALESFORCE FOR OUTLOOK

The Cordova Development Lifecycle

Datacenter Operating Systems

X4-2 Exadata announced (well actually around Jan 1) OEM/Grid control 12c R4 just released

An Open Source NoSQL solution for Internet Access Logs Analysis

Comparing SQL and NOSQL databases

The Quest for Extreme Scalability

Can the Elephants Handle the NoSQL Onslaught?

Sep 23, OSBCONF 2014 Cloud backup with Bareos

APP DEVELOPMENT ON THE CLOUD MADE EASY WITH PAAS

Monitoring and Managing a JVM

6 CURRENT JOB OPENINGS:

Tivoli Endpoint Manager BigFix Dashboard

Frictionless Persistence in.net with MongoDB. Mogens Heller Grabe Trifork

MADOCA II Data Logging System Using NoSQL Database for SPring-8

The Decaffeinated Robot

Exploi'ng NoSQL Like Never Before HITB AMS 2014

Open source, high performance database

Installing an open source version of MateCat

DISTRIBUTED SYSTEMS [COMP9243] Lecture 9a: Cloud Computing WHAT IS CLOUD COMPUTING? 2

Couchbase Server Under the Hood

Using Network Attached Storage with Linux. by Andy Pepperdine

Advanced Data Management Technologies

Cloud Computing Is In Your Future

nosql and Non Relational Databases

Drupal in the Cloud. Scaling with Drupal and Amazon Web Services. Northern Virginia Drupal Meetup

Cucumber: Finishing the Example. CSCI 5828: Foundations of Software Engineering Lecture 23 04/09/2012

Dr. Chuck Cartledge. 15 Oct. 2015

Open Source DBMS CUBRID 2008 & Community Activities. Byung Joo Chung bjchung@cubrid.com

Evaluation of NoSQL databases for large-scale decentralized microblogging

Microsoft Azure: Opção de Nuvem para Todo o Desenvolvedor. Danilo Bordini & Osvaldo Daibert

BlackBerry Enterprise Service 10. Secure Work Space for ios and Android Version: Security Note

Python Lists and Loops

Running a Workflow on a PowerCenter Grid

Zimbra to Gmail Migration

Gentran Integration Suite. Archiving and Purging. Version 4.2

Monitoring Drupal with Sensu. John VanDyk Iowa State University DrupalCorn Iowa City August 10, 2013

Taming the Cloud Database with Apache jclouds

Practical Cassandra. Vitalii

FAWN - a Fast Array of Wimpy Nodes

INASP: Effective Network Management Workshops

Salesforce Mobile Push Notifications Implementation Guide

Transcription:

Redis 101 A whirlwind tour of the next big thing in NoSQL data storage PETER COOPER http://twitter.com/peterc http://coder.io/

Whirlwind tour? No overbearing detail. A quick whizz-through. Enough to get you excited (if Redis is for you.) Official docs, etc, are an awesome way to continue.

Redis is... NoSQL an advanced key-value store by SALVATORE SANFILIPPO ( @antirez)

NoSQL? An informal, loosely-defined term for non-relational, structured data storage systems Like MongoDB, memcached, CouchDB, and Redis See http://en.wikipedia.org/wiki/structured_storage for comparisons

memcached The canonically simple example a networked hash in the sky behind a simple protocol Keys page:index.html user:123:session login_count user:100:last_login_time Values <html><head>[...] xdrsdewd4dslzkekj+ 7464 102736485756 Everything s a string (or a blob ) Commands just set or get data (mostly)

Take memcached s simplicity, Add more data types, Add persistence, Add more commands,.. and more Redis

Redis Data Types Strings Lists Sets Sorted/Scored Sets Hashes all accessed by a string key

Redis Data Examples Keys page:index.html login_count users_logged_in_today Values <html><head>[...] 7464 { 1, 2, 3, 4, 5 } String Set latest_post_ids [201, 204, 209,..] List user:123:session time => 10927353 username => joe Hash users_and_scores joe ~ 1.3483 bert ~ 93.4 fred ~ 283.22 chris ~ 23774.17 Sorted (scored) Set

Strings Redis command line client app Key Value./redis-cli SET mystring hello world./redis-cli GET mystring returns hello world

Strings GETSET MGET SETNX SETEX MSET MSETNX INCR INCRBY DECR DECRBY APPEND SUBSTR Works on strings that appear to be integers. Magic! http://code.google.com/p/redis/wiki/commandreference

Expiration When caching, you don t want things to live forever. Any item in Redis can be made to expire after or at a certain time. seconds EXPIRE your_key 1234 TTL your_key == 1234

Deleting Keys You can also delete data at will. DEL your_key EXISTS your_key == 0 (false)

Lists LPUSH RPUSH a b c d e f LPOP RPOP e.g. RPUSH my_q f

Lists LLEN == 6 a Xb c d e f } LRANGE 2 3 LREM 1 b LINDEX 5

Queues NOT A NATIVE TYPE RPUSH Still just a list! a b c d e f LPOP Or BLPOP to block (wait) until something can be popped RPUSH my_q abc RPUSH my_q def LPOP my_q LPOP my_q LPOP my_q == abc == def == (nil)

Sets SREM contains:aba hello contains:aba abacus cabal baba hello teabag base cabaret database SMOVE contains:aba contains:ase base contains:ase vase vaseline baseline uncase unbased phase database tease SADD contains:ase suitcase

Sets contains:aba abacus cabal baba teabag cabaret database SCARD contains:aba == 6 SISMEMBER contains:aba chips == 0 (meaning false) SRANDMEMBER contains:aba == teabag contains:ase vase vaseline baseline unbased phase database suitcase SMEMBERS contains:ase == vase, vaseline, baseline, unbased, phase, database, suitcase

Sets contains:aba abacus cabal baba teabag cabaret database vase vaseline baseline unbased phase suitcase contains:ase SINTER contains:aba contains:ase == database This is only a simple example. SINTER can take any number of arguments! SUNION is another command that will join sets together.

contains:aba Sets abacus cabal baba teabag cabaret database resultset vase vaseline baseline unbased phase suitcase contains:ase database SINTERSTORE resultset contains:aba contains:ase SUNIONSTORE does the same for set unions.

Sorted Sets? Sorry - no time! Basically, like normal sets but each element can have a rank or score and be returned or sorted by it.

Hashes product:1 created_at 102374657 product_id 1 name Twinkies available 10 HSET product:1 created_at 102374657 HSET product:1 product_id 1 HSET product:1 name Twinkies HSET product:1 available 10 HGET product:1 name == Twinkies HLEN product:1 == 4 HKEYS product:1 == created_at, product_id, name, available HGETALL product:1 == created_at => 102374657 product_id => 1 [.. etc..] Also... HVALS HEXISTS HINCRBY HMGET HMSET

Session Storage Session 8d3e4 created_at: 102374657 user_id: 1 It s basically a hash HSET session:8d3e4 created_at 102374657 HSET session:8d3e4 user_id 1 OR HMSET session:8d3e4 created_at 102374657 user_id 1 Then let Redis automatically expire it in 24 hours! EXPIRE session:8d3e4 86400

Redis Social Network Users have names, can follow others, and be followed s are things like messages, photos, etc.

User id: 1 name: joe has many.. User id: 2 name: fred has many..

User id: 1 name: joe User id: 2 name: fred user:1:name username:joe 1 joe So we can do a two way reference post:1:content hello world post:1:user 1 Ditto

Building unique key names with colons like user:1:name is just a convention Any string will dooooo...

User id: 1 name: joe User id: 2 name: fred set user:1:name joe set username:joe 1 set post:1:content hello world set post:1:user 1 Remember, SET and GET are used for string values

User id: 1 name: joe User id: 2 name: fred user:1:posts [3, 2, 1] List

User id: 1 name: joe User id: 2 name: fred user:1:posts [3, 2, 1] lpush user:1:posts 1 lpush user:1:posts 2 lpush user:1:posts 3 LPUSH and RPUSH add items to the start or end of a list

User id: 1 name: joe User id: 3 name: bill User id: 2 name: fred User id: 4 name: jane user:1:follows {2, 3, 4} sadd user:1:follows 2 sadd user:1:follows 3 sadd user:1:follows 4 Set Order not important SADD and SREM add or remove elements to/from a set

User id: 1 name: joe User id: 3 name: bill User id: 2 name: fred User id: 4 name: jane You might want to track the relationship in the opposite direction too. Just create another set! user:1:followed_by {3} sadd user:1:followed_by 3

A Simple Social Network Keys user:1:name user:2:name username:joe username:fred user:1:follows user:2:follows user:1:followed_by user:2:followed_by post:1:content post:1:user post:2:content post:2:user user:1:posts user:2:posts Values joe fred 1 2 {2,3,4} Set {1} {2} {1} Hello world 2 Blah blah 1 [2,3,4] List [1,5,6] Simplified from the earlier graphs due to lack of space :-)

Unique IDs INCR next_post_id If next_post_id doesn t exist or doesn t contain a number, it ll be set at 0, incremented, and 1 will be returned. returns 1 post:1:etc INCR next_post_id INCR increments the element by 1 and returns the new value. Great for unique IDs! returns 2 or next_user_id!

Creating a new user INCR next_user_id returns SET user:[uid]:name [username] SET username:[username] [id] [uid] Creating a new post INCR next_post_id returns SET post:[pid]:content [content] SET post:[pid]:user [pid] LPUSH user:[uid]:posts [pid] LPUSH posts:global [pid] [pid]

SORT ZCARD MONITOR SLAVEOF SUBSCRIBE PUBLISH RENAME SELECT SAVE Enough commands! I haven t covered them all though.. On to softer issues.

Atomicity Redis is single threaded No locking necessary In other words, commands like INCR won t tread on each other s toes coming from multiple clients simultaneously!

Redis Factoids BSD licensed (free, open) Sponsored by VMware Written in ANSI C Good community (list, IRC & wiki) Works on all POSIX-compliant UNIXes An unofficial Windows/Cygwin build is available

Installation Download a tarball or clone the git repo Run make redis-server and redis-cli are ready to roll (You can make a config file later, if you want.) http://code.google.com/p/redis/

Performance Depends a lot on configuration and operation complexity. Common range from 5000 to 120,000 rps for basic ops GET/SET/LPUSH/LPOP, etc. (ultra low end to high end hardware)

Performance redis-benchmark tool on a CentOS virtual machine on a 2009 imac GET: 28011 rps SET: 36101 rps INCR: 36496 rps LPUSH: 38759 rps LPOP: 38610 rps }average ~36000 And that s with 1024 byte payloads!

Persistence Dump data to disk after certain conditions are met. Or manually. SAVE and BGSAVE commands AND/OR An append only log file (which can be optimized/rebuilt automatically) but you need to set this up in a config file

Language Support Ruby, Python, PHP, Erlang, Tcl, Perl, Lua, Java, Scala, Clojure, C#, C/C++, JavaScript/Node.js, Haskell, IO, Go i.e. anything actually worth using

Missed a lot, so where next!? Google Redis the official site is great http://coder.io/tag/redis for news and articles P.S. I m writing a Redis book a little like this presentation. E-mail peter@peterc.org to be put on an announce list!