27
Redis introduction Alex Su 2013/05/06

Redis Introduction

  • Upload
    alex-su

  • View
    991

  • Download
    10

Embed Size (px)

Citation preview

Page 1: Redis Introduction

Redis introduction

Alex Su2013/05/06

Page 2: Redis Introduction

What is Redis

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

Sponsored by

Page 3: Redis Introduction

Who's using Redis?

Page 4: Redis Introduction

Supported Platforms

Linux Mac OS X FreeBSD Solaris Windows

no official support

Page 5: Redis Introduction

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

Page 6: Redis Introduction

Data types

Stringswith a maximum of 512MB

Lists Sets Sorted sets

Set with score Hashes

Perfect to represent object

Page 7: Redis Introduction

Commands SET GET

INCR DECR

LPUSH LRANGE LLEN

EXPIRE TTL

SADD SMEMBERS SCARD SREM

ZADD ZRANGE ZREVRANGE ZCARD ZREM

HSET HGET HGETALL

Page 8: Redis Introduction

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.

Page 9: Redis Introduction

Lua scripting

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

Page 10: Redis Introduction

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

Page 11: Redis Introduction

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)

Page 12: Redis Introduction

More use cases

Leader election Counting semaphores Queue Pizza topping problem

Page 13: Redis Introduction

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

Page 14: Redis Introduction

Replication

Official Master-slave replicationWrite in Master, Read in Slaves

Page 15: Redis Introduction

Partitioning

Redis Cluster is currently not production ready.

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

Page 16: Redis Introduction

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

Page 17: Redis Introduction

High Availability(alternative)

Virtual IP keepalived or heartbeat DRBD

Page 18: Redis Introduction

High Availability(alternative)

redis_failover project

Page 19: Redis Introduction

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

Page 20: Redis Introduction

Performance Benchmark

Page 21: Redis Introduction

Cost of Redis Persistence

Page 22: Redis Introduction

Redis web admin console Redis Commander Redmon Redsmin

Page 23: Redis Introduction

Redis Commander

Asfd

Page 24: Redis Introduction

Compare with Memcached

Page 25: Redis Introduction

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

勝勝

勝勝

Page 27: Redis Introduction

Questions?