Redis logo

An advanced key value store

Talk by Tim Gibbon / @TommyBobbins

Advantages

  • Fast and lightweight - Raspberry Pi will handle 2000 requests per second.
  • Simple - easy set/get calls.
  • Can store all programatical data types ( arrays, hashes, strings, lists, sorted lists).
  • Large range of useful extras.
  • Can be easily clustered.
  • Persistence - data is written to disk.
Unicorn

Disadvantages

  • Security. Cannot be safely run across t'internet.
  • Number of available commands and configuration can be offputting.
  • Code is built by Pivotal, but is BSD licenced.
Freaky Clown

Using Redis?

  • Twitter
  • Github
  • Weibo
  • Pinterest
  • Snapchat
  • Craigslist
  • Digg
  • StackOverflow
  • Flickr
  • Me
Soho. ed_needs_a_bicycle

Installing


                                               pi@raspberrypi: ~/$ sudo apt-get install redis-server python-redis
                                        
Old Tools and Spanners by Ian Britton

Command line usage


pi@raspberrypi ~/$ redis-cli -h localhost set temperature/sensor/cellar 20.0
OK
pi@raspberrypi ~/$ redis-cli -h localhost get temperature/sensor/cellar
"20.0"
pi@raspberrypi ~/$ redis-cli -h localhost expire temperature/sensor/cellar 5
(integer) 1
pi@raspberrypi ~/$ redis-cli -h localhost get temperature/sensor/cellar
"20.0"
pi@raspberrypi ~/$ redis-cli -h localhost get temperature/sensor/cellar
(nil)
                                        

Python and Redis


import redis
redthis = redis.StrictRedis(host='433board',port=6379, db=0, socket_timeout=3)

try:
    #Read in all the previous settings
    weather_temp=float(redthis.get("temperature/weather"))
    boiler_state=redthis.get("boiler/req")
    time_to_live=int(redthis.ttl("boiler/req"))
    redthis.set("temperature/calendar", calendar_temp)
                                        

Benchmarking


          pi@raspberrypi ~/$ redis-benchmark -q -n 1000
          PING_INLINE: 2659.57 requests per second
          PING_BULK: 2403.85 requests per second
          SET: 2242.15 requests per second 
          GET: 2352.94 requests per second
          INCR: 2242.15 requests per second
          LPUSH: 1855.29 requests per second
          LPOP: 2314.81 requests per second
          SADD: 2272.73 requests per second
          SPOP: 2577.32 requests per second
          LPUSH (needed to benchmark LRANGE): 2127.66 requests per second
          LRANGE_100 (first 100 elements): 964.32 requests per second
          LRANGE_300 (first 300 elements): 417.01 requests per second
          LRANGE_500 (first 450 elements): 250.13 requests per second
          LRANGE_600 (first 600 elements): 220.56 requests per second
          MSET (10 keys): 1488.10 requests per second
					

Application - Raspberry Pi powered home automation

THE END

Tim Gibbon / lunarlite.co.uk

github.com/tommybobbins/PiThermostat/

Photo Credits

  • Soho © ed_needs_a_bicycle CC BY-NC-SA 2.0
  • Old Tools and Spanners © Ian Britton CC BY-NC 2.0