Redis Introduction

Preview:

Citation preview

Redis introduction

Alex Su2013/05/06

What is Redis

An open source, BSD licensed, advanced key-value store

Sponsored by

Who's using Redis?

Supported Platforms

Linux Mac OS X FreeBSD Solaris Windows

no official support

Supported Languages ActionScript C C++ C# Clojure Common Lisp Dart Erlang Go Haskell Haxe Java Io server-side JavaScript (Node.js) Lua Objective-C Perl PHP Pure Data Python Ruby Scala Smalltalk Tcl

Data types

Stringswith a maximum of 512MB

Lists Sets Sorted sets

Set with score Hashes

Perfect to represent object

Commands SET GET

INCR DECR

LPUSH LRANGE LLEN

EXPIRE TTL

SADD SMEMBERS SCARD SREM

ZADD ZRANGE ZREVRANGE ZCARD ZREM

HSET HGET HGETALL

Publish–subscribe

Redis supports publish-subscribe mode. You can subscribe some topics, and

when someone publish topic matches your interest, redis send it to you.

Lua scripting

Scripting makes Redis much faster for complex operationsread-compute-write workflow

Pipelining NOT Redis transactions Does not provide atomicity Nothing more complicated than the fact that

Redis server is able to queue up responses in memory

Too many commands in a single pipeline may cause memory issues and potentially socket timeout.

Benchmark

without pipelining 1.185238 seconds

with pipelining 0.250783 seconds

Transactions

All the commands in a transaction are serialized and executed sequentially.

Either all of the commands or none are processed.

Redis does not support roll backsA command fails to be queuedA command fails after EXEC is called(not

supported)

More use cases

Leader election Counting semaphores Queue Pizza topping problem

Persistence

Virtual Memory RDB (Snapshots)

Take snapshot in an intervalFastMay loss several minutes data if kill -9

Append Only File (AOF)Log-based link binlog, redo whole steps since

startupAuto bgrewriteaof (background rewrite AOF)Still fast enoughMay loss 1 second data if kill -9

Replication

Official Master-slave replicationWrite in Master, Read in Slaves

Partitioning

Redis Cluster is currently not production ready.

Redis Cluster is a mix between query routing and client side partitioning.

High Availability

Redis Sentinel is a system designed to help managing Redis instances. It performs the following three tasks: Monitoring Notification Automatic failover Not good for production environments

High Availability(alternative)

Virtual IP keepalived or heartbeat DRBD

High Availability(alternative)

redis_failover project

Twemproxy Maintain persistent server connections Keep connection count on cache servers low Pipeline requests and responses Use multiple server pools simultaneously Proxy the complete memcached ASCII protocol Easily configure server pools using a YAML file Use multiple hashing modes, including

consistent hashing Increase observability using stats exposed on a

monitoring port

Performance Benchmark

Cost of Redis Persistence

Redis web admin console Redis Commander Redmon Redsmin

Redis Commander

Asfd

Compare with Memcached

Compare with Memcached

Memcached Redis

(Multi)Get V V

(Multi)Set V V

Incr/Decr V V

Deletion V V

Expiration V V

Range Queries V

Data Types V

Persistence V

Replication V

Prepend/Append V

勝勝

勝勝

Questions?