A Developer Overview of Redis

14
A Developer overview of Redis Yuriy Guts Solutions Architect @ ELEKS

Transcript of A Developer Overview of Redis

Page 1: A Developer Overview of Redis

A Developer overview of Redis

Yuriy GutsSolutions Architect @ ELEKS

Page 2: A Developer Overview of Redis

First Things FirstRedis is an open-source (BSD), networked, in-memory key-value cache and store with optional durability.

Commonly called a data structure server.

Page 3: A Developer Overview of Redis

Differentiation

• Insanely fast

• Available for distributed environment by design

• Allows atomic operations specific to data structures

Page 4: A Developer Overview of Redis

Data Structures

• String

• Hash

• List

• Set

• Sorted Set

• Bitmap

• HyperLogLog

Page 5: A Developer Overview of Redis

COMMANDS

LPUSH  people  Alice

[“Alice”]

LPUSH  people  Bob

[“Bob”,  “Alice”]

RPUSH  people  Charlie

[“Bob”,  “Alice”,  “Charlie”]

EXPIRE  people  120  

COMMAND  <arg0>  <arg1>  ...  <argN>

Page 6: A Developer Overview of Redis

Use Cases

• Session store

• Read cache, write-through cache

• Dynamically computed statistics and aggregates

• Publish/Subscribe channels

Page 7: A Developer Overview of Redis

Adoption

Page 8: A Developer Overview of Redis

Stack Exchange

• 2x Redis Servers (master + slave)

• 96 GB RAM each

• 60k RPS on average

http://stackexchange.com/performance

Page 9: A Developer Overview of Redis

ServiceStack Native Client

using (IRedisNativeClient redisNativeClient = new RedisNativeClient()){

redisNativeClient.LPush("lastVisitorIds",  BitConverter.GetBytes(113));redisNativeClient.LPush("lastVisitorIds",  BitConverter.GetBytes(61));redisNativeClient.LPush("lastVisitorIds",  BitConverter.GetBytes(2481));

}

Page 10: A Developer Overview of Redis

ServiceStack Typed Clientusing (IRedisClient redisClient = new RedisClient()){

var book  = new Book(){

Id  = 5,Author  = new Author{

Name  = "Itzik Ben-­‐Gan",Biography  = "Microsoft  MVP:  SQL  Server",

},Title  = "T-­‐SQL  2012  Fundamentals",PublishingDate = DateTime.Now,

};

var bookClient = redisClient.As<Book>();bookClient.Store(book);var book  = bookClient.GetById(5);

}

Page 11: A Developer Overview of Redis

StackExchange.Redis APIusing (var redisConnection = ConnectionMultiplexer.Connect("localhost")){

var redisDb = redisConnection.GetDatabase();redisDb.ListLeftPush("people",  "Alice");redisDb.ListLeftPush("people",  "Bob");redisDb.ListRightPush("people",  "Charlie");var results  = redisDb.ListRange("people",  0,  redisDb.ListLength("people"));

foreach (var resultItem  in results){

Console.WriteLine(resultItem);}

}

1422544070.303526  [0  127.0.0.1:37586]  "LPUSH"  "people"  "Alice"1422544070.305371  [0  127.0.0.1:37586]  "LPUSH"  "people"  "Bob"1422544070.305891  [0  127.0.0.1:37586]  "RPUSH"  "people"  "Charlie"1422544070.306290  [0  127.0.0.1:37586]  "LLEN"  "people"1422544070.309355  [0  127.0.0.1:37586]  "LRANGE"  "people"  "0"  "3"

Page 12: A Developer Overview of Redis

Tradeoffs

• No “official” Windows port (only MSOpenTech x64 distro)

• Limited access control/administration features

• Non-ACID transactions (batching only)

Page 13: A Developer Overview of Redis

DEMO

• Leaderboard Server

• Leaderboard Command-Line Client

• Near-Realtime Leaderboard Web UI

Page 14: A Developer Overview of Redis

Q & Ayuriy.guts @ eleks.com

https://github.com/YuriyGuts/redis-websocket-leaderboard