Yuriy Guts
Software Architect @ ELEKS
Redis is an open-source (BSD), networked, in-memory key-value cache
and store with optional durability.
Commonly called a data structure server.
• Insanely fast
• Available for distributed environment by design
• Allows atomic operations specific to data structures
• String
• Hash
• List
• Set
• Sorted Set
• Bitmap
• HyperLogLog
LPUSH people Alice
[“Alice”]
LPUSH people Bob
[“Bob”, “Alice”]
RPUSH people Charlie
[“Bob”, “Alice”, “Charlie”]
EXPIRE people 120
COMMAND <arg0> <arg1> ... <argN>
using (IRedisNativeClient redisNativeClient = new RedisNativeClient())
{
redisNativeClient.LPush("lastVisitorIds", BitConverter.GetBytes(113));
redisNativeClient.LPush("lastVisitorIds", BitConverter.GetBytes(61));
redisNativeClient.LPush("lastVisitorIds", BitConverter.GetBytes(2481));
}
using (IRedisClient redisClient = new RedisClient())
{
var book = new Book()
{
Id = 5,
Author = new Author
{
Name = "Jeffrey Richter",
Biography = "Founder of Wintellect.",
},
Title = "CLR via C#",
PublishingDate = DateTime.Now,
};
var bookClient = redisClient.As<Book>();
bookClient.Store(book);
var book = bookClient.GetById(5);
}
• Session store
• Read cache, write-through cache
• Dynamically computed statistics and aggregates
• Publish/Subscribe channels
• 2x Redis Servers (master + slave)
• 96 GB RAM each
• 60k RPS on average
http://stackexchange.com/performance
using (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"
• No “official” Windows port (only MSOpenTech x64 distro)
• Limited access control/administration features
• Non-ACID transactions (batching only)
yuriy.guts @ eleks.com

Redis for .NET Developers

  • 1.
  • 2.
    Redis is anopen-source (BSD), networked, in-memory key-value cache and store with optional durability. Commonly called a data structure server.
  • 3.
    • Insanely fast •Available for distributed environment by design • Allows atomic operations specific to data structures
  • 4.
    • String • Hash •List • Set • Sorted Set • Bitmap • HyperLogLog
  • 5.
    LPUSH people Alice [“Alice”] LPUSHpeople Bob [“Bob”, “Alice”] RPUSH people Charlie [“Bob”, “Alice”, “Charlie”] EXPIRE people 120 COMMAND <arg0> <arg1> ... <argN>
  • 6.
    using (IRedisNativeClient redisNativeClient= new RedisNativeClient()) { redisNativeClient.LPush("lastVisitorIds", BitConverter.GetBytes(113)); redisNativeClient.LPush("lastVisitorIds", BitConverter.GetBytes(61)); redisNativeClient.LPush("lastVisitorIds", BitConverter.GetBytes(2481)); }
  • 7.
    using (IRedisClient redisClient= new RedisClient()) { var book = new Book() { Id = 5, Author = new Author { Name = "Jeffrey Richter", Biography = "Founder of Wintellect.", }, Title = "CLR via C#", PublishingDate = DateTime.Now, }; var bookClient = redisClient.As<Book>(); bookClient.Store(book); var book = bookClient.GetById(5); }
  • 8.
    • Session store •Read cache, write-through cache • Dynamically computed statistics and aggregates • Publish/Subscribe channels
  • 10.
    • 2x RedisServers (master + slave) • 96 GB RAM each • 60k RPS on average http://stackexchange.com/performance
  • 11.
    using (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"
  • 12.
    • No “official”Windows port (only MSOpenTech x64 distro) • Limited access control/administration features • Non-ACID transactions (batching only)
  • 13.