A Developer Overview of Redis
-
Upload
yuriy-guts -
Category
Software
-
view
64 -
download
3
Transcript of A Developer Overview of Redis
![Page 1: A Developer Overview of Redis](https://reader035.fdocuments.in/reader035/viewer/2022073118/55be7f1abb61eb05488b474c/html5/thumbnails/1.jpg)
A Developer overview of Redis
Yuriy GutsSolutions Architect @ ELEKS
![Page 2: A Developer Overview of Redis](https://reader035.fdocuments.in/reader035/viewer/2022073118/55be7f1abb61eb05488b474c/html5/thumbnails/2.jpg)
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](https://reader035.fdocuments.in/reader035/viewer/2022073118/55be7f1abb61eb05488b474c/html5/thumbnails/3.jpg)
Differentiation
• Insanely fast
• Available for distributed environment by design
• Allows atomic operations specific to data structures
![Page 4: A Developer Overview of Redis](https://reader035.fdocuments.in/reader035/viewer/2022073118/55be7f1abb61eb05488b474c/html5/thumbnails/4.jpg)
Data Structures
• String
• Hash
• List
• Set
• Sorted Set
• Bitmap
• HyperLogLog
![Page 5: A Developer Overview of Redis](https://reader035.fdocuments.in/reader035/viewer/2022073118/55be7f1abb61eb05488b474c/html5/thumbnails/5.jpg)
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](https://reader035.fdocuments.in/reader035/viewer/2022073118/55be7f1abb61eb05488b474c/html5/thumbnails/6.jpg)
Use Cases
• Session store
• Read cache, write-through cache
• Dynamically computed statistics and aggregates
• Publish/Subscribe channels
![Page 7: A Developer Overview of Redis](https://reader035.fdocuments.in/reader035/viewer/2022073118/55be7f1abb61eb05488b474c/html5/thumbnails/7.jpg)
Adoption
![Page 8: A Developer Overview of Redis](https://reader035.fdocuments.in/reader035/viewer/2022073118/55be7f1abb61eb05488b474c/html5/thumbnails/8.jpg)
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](https://reader035.fdocuments.in/reader035/viewer/2022073118/55be7f1abb61eb05488b474c/html5/thumbnails/9.jpg)
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](https://reader035.fdocuments.in/reader035/viewer/2022073118/55be7f1abb61eb05488b474c/html5/thumbnails/10.jpg)
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](https://reader035.fdocuments.in/reader035/viewer/2022073118/55be7f1abb61eb05488b474c/html5/thumbnails/11.jpg)
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](https://reader035.fdocuments.in/reader035/viewer/2022073118/55be7f1abb61eb05488b474c/html5/thumbnails/12.jpg)
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](https://reader035.fdocuments.in/reader035/viewer/2022073118/55be7f1abb61eb05488b474c/html5/thumbnails/13.jpg)
DEMO
• Leaderboard Server
• Leaderboard Command-Line Client
• Near-Realtime Leaderboard Web UI
![Page 14: A Developer Overview of Redis](https://reader035.fdocuments.in/reader035/viewer/2022073118/55be7f1abb61eb05488b474c/html5/thumbnails/14.jpg)
Q & Ayuriy.guts @ eleks.com
https://github.com/YuriyGuts/redis-websocket-leaderboard