Redis - Fast and Furious
N✮SQL Berlin




Mathias Meyer, 22.10.2009
Peritor GmbH
Self
I work at
   
   Peritor in Berlin
I tweet
 
   
   @roidrage
I code at
   
   http://github.com/mattmatt
I blog at
 ...
Peritor
              Working on




          http://scalarium.com


                                 3
Redis - Key-Value Store
Simple, yet awesome
Fast, yet nonvolatile




code.google.com/p/redis
                          4
Redis




REmote DIctionary Server




                           5
Redis




Went public in March 2009
Just reached 1.0




                            6
Redis




< 6000 lines of code




                       7
Redis




And the code is simple




                         8
Redis




No threading, just one process




                                 9
Redis




Like Memcached, only awesome




                               10
Redis




Simple and efficient text-based protocol
(just like grandma and Memcached used to make)




                    ...
Redis Protocol




                 12
Redis Protocol




redis[“key”] = “value”




                         13
Redis Protocol




Duh!




                 14
Redis Protocol




Values can be strings, lists or sets




                                       15
Redis Protocol - Special Ops
Push and pop elements
(atomic)
Fetch arbitrary set and
array elements
Sorting




           ...
Redis Protocol

set foo 4
1000
+OK




                 17
Redis Protocol

set foo 4
                 Request
1000
+OK              Response




                            17
Redis Protocol

get foo
$4
1000


get bar
$-1




                 18
Redis Protocol

get foo          Request
$4
                 Response
1000


get bar          Reques
$-1              Resp...
Redis Protocol

incr foo
:1001


type foo
+string




                 19
Redis Protocol - Lists

lpush pizza 4
fury
+OK


rpush pizza 8
ortolana
+OK


                         20
Redis Protocol - Lists

lrange pizza 0 1
*2
$4
fury
$8
ortolana




                         21
Redis Protocol - Lists

lrange pizza 0 1         Request
*2
$4
fury                     Response
$8
ortolana




         ...
Redis Protocol - Sets

sadd mq 8
rabbitmq
:1


sadd mq 6
zeromq
:1


                        22
Redis Protocol - Sets

smembers mq
*2
$6
zeromq
$8
rabbitmq




                        23
Redis Protocol - Sets

sort mq alpha
*2
$8
rabbitmq
$6
zeromq




                        24
Redis Protocol - The Rest
Random list/set access
Intersections, Unions
Monitoring
Controlling the Server
Multi-Set Command...
Redis




Data is held in memory, but can be persisted




                                               26
Redis Key-Value Database

Persistent
Asynchronous
Just like Super Pursuit
Mode




                           27
Redis Database




Data is written to disk asynchronously




                                         28
Redis Database


                              Redis Server

                                Dump
                        ...
Redis Database




save 900 1
save 300 10
save 60 100000



                 30
Replication

1 Master - N Slaves
Asynchronous on Master
Synchronous on Slave




                         31
Redis Replication
Like dumping the database, only to a different file descriptor.




                                     ...
Redis Replication


                   Redis Master




           Redis Slave         Redis Slave




                   ...
Redis - Scaling




Horizontal
 • Run multiple Redis processes
 • Use HashRing (e.g. in redis-rb)




                    ...
Redis - Scaling




Vertical
 • Master-Slave setup
 • Fetch data from any slave (e.g. random)




                        ...
To Redis, or not to Redis?




                             36
As always, it depends




                        37
To Redis




Caching
Statistical data
Recoverable state
Worker queue

                    38
Not to Redis




100% consistent dataset required
Data is larger than memory



                                   39
Redis Use Cases




Nanite - A self-assembling cluster of Ruby
daemons




                                             40
The most important




                     41
Is it faster than




                    42
No, but fast enough for you
(if you need the extra features)




                                   43
Redis
Simple, fast, awesome.




                         44
Questions




            45
Peritor GmbH
Blücherstr. 22, Hof III Aufgang 6
10961 Berlin
Tel.: +49 (0)30 69 20 09 84 0
Fax: +49 (0)30 69 20 09 84 9
Int...
Upcoming SlideShare
Loading in...5
×

Redis - N✮SQL Berlin

7,276

Published on

Redis, the fast and furious key-value store.

Published in: Technology
0 Comments
15 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
7,276
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
152
Comments
0
Likes
15
Embeds 0
No embeds

No notes for slide
  • (that&amp;#x2019;s not a lot, even for C code)
  • (even for C code)
  • (old school)
  • Strings can&amp;#x2019;t be longer than 1GB
    Lists are implemented as doubly linked lists
    Sets are stored as hashesh
  • Different datatypes require using different command sets. Not doing so will raise errors.
  • Get is wicked fast.
  • incr requires parsing of the value
  • lset is destructive, replaces the existing element
  • List access only through ranges, getting a whole list requires you to fetch the length first.
  • Data in Redis isn&amp;#x2019;t volatile, at least most of the time
  • ..and only if necessary.
    Data is put into a single dump file.
  • Database is dumped into a tempfile, then renamed.
    It&amp;#x2019;s possible to loose data in the dumping period.
  • Writes out data after x seconds if at least y number of keys have changed.
    On startup the dump is reread into memory.
  • Fast, more complex, datatypes
  • Redis stores the daemon state and is used for service lookup.
  • Redis - N✮SQL Berlin

    1. 1. Redis - Fast and Furious N✮SQL Berlin Mathias Meyer, 22.10.2009 Peritor GmbH
    2. 2. Self I work at Peritor in Berlin I tweet @roidrage I code at http://github.com/mattmatt I blog at http://paperplanes.de 2
    3. 3. Peritor Working on http://scalarium.com 3
    4. 4. Redis - Key-Value Store Simple, yet awesome Fast, yet nonvolatile code.google.com/p/redis 4
    5. 5. Redis REmote DIctionary Server 5
    6. 6. Redis Went public in March 2009 Just reached 1.0 6
    7. 7. Redis < 6000 lines of code 7
    8. 8. Redis And the code is simple 8
    9. 9. Redis No threading, just one process 9
    10. 10. Redis Like Memcached, only awesome 10
    11. 11. Redis Simple and efficient text-based protocol (just like grandma and Memcached used to make) 11
    12. 12. Redis Protocol 12
    13. 13. Redis Protocol redis[“key”] = “value” 13
    14. 14. Redis Protocol Duh! 14
    15. 15. Redis Protocol Values can be strings, lists or sets 15
    16. 16. Redis Protocol - Special Ops Push and pop elements (atomic) Fetch arbitrary set and array elements Sorting 16
    17. 17. Redis Protocol set foo 4 1000 +OK 17
    18. 18. Redis Protocol set foo 4 Request 1000 +OK Response 17
    19. 19. Redis Protocol get foo $4 1000 get bar $-1 18
    20. 20. Redis Protocol get foo Request $4 Response 1000 get bar Reques $-1 Respons 18
    21. 21. Redis Protocol incr foo :1001 type foo +string 19
    22. 22. Redis Protocol - Lists lpush pizza 4 fury +OK rpush pizza 8 ortolana +OK 20
    23. 23. Redis Protocol - Lists lrange pizza 0 1 *2 $4 fury $8 ortolana 21
    24. 24. Redis Protocol - Lists lrange pizza 0 1 Request *2 $4 fury Response $8 ortolana 21
    25. 25. Redis Protocol - Sets sadd mq 8 rabbitmq :1 sadd mq 6 zeromq :1 22
    26. 26. Redis Protocol - Sets smembers mq *2 $6 zeromq $8 rabbitmq 23
    27. 27. Redis Protocol - Sets sort mq alpha *2 $8 rabbitmq $6 zeromq 24
    28. 28. Redis Protocol - The Rest Random list/set access Intersections, Unions Monitoring Controlling the Server Multi-Set Commands 25
    29. 29. Redis Data is held in memory, but can be persisted 26
    30. 30. Redis Key-Value Database Persistent Asynchronous Just like Super Pursuit Mode 27
    31. 31. Redis Database Data is written to disk asynchronously 28
    32. 32. Redis Database Redis Server Dump Database fork() Redis Server rename() exit() 29
    33. 33. Redis Database save 900 1 save 300 10 save 60 100000 30
    34. 34. Replication 1 Master - N Slaves Asynchronous on Master Synchronous on Slave 31
    35. 35. Redis Replication Like dumping the database, only to a different file descriptor. 32
    36. 36. Redis Replication Redis Master Redis Slave Redis Slave Redis Slave Redis Slave 33
    37. 37. Redis - Scaling Horizontal • Run multiple Redis processes • Use HashRing (e.g. in redis-rb) 34
    38. 38. Redis - Scaling Vertical • Master-Slave setup • Fetch data from any slave (e.g. random) 35
    39. 39. To Redis, or not to Redis? 36
    40. 40. As always, it depends 37
    41. 41. To Redis Caching Statistical data Recoverable state Worker queue 38
    42. 42. Not to Redis 100% consistent dataset required Data is larger than memory 39
    43. 43. Redis Use Cases Nanite - A self-assembling cluster of Ruby daemons 40
    44. 44. The most important 41
    45. 45. Is it faster than 42
    46. 46. No, but fast enough for you (if you need the extra features) 43
    47. 47. Redis Simple, fast, awesome. 44
    48. 48. Questions 45
    49. 49. Peritor GmbH Blücherstr. 22, Hof III Aufgang 6 10961 Berlin Tel.: +49 (0)30 69 20 09 84 0 Fax: +49 (0)30 69 20 09 84 9 Internet: www.peritor.com E-Mail: info@peritor.com © Peritor GmbH - Alle Rechte Vorbehalten
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×