Your SlideShare is downloading. ×
  • Like
Upcoming SlideShare
Loading in...5

Thanks for flagging this SlideShare!

Oops! An error has occurred.


Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply



This is a short introduction to NoSQL REDIS (key, value store) database I wrote a couple of months ago. …

This is a short introduction to NoSQL REDIS (key, value store) database I wrote a couple of months ago.
Includes the main commands REDIS offers plus how to set up a storage for Products in a similar way as data table.

Published in Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads


Total Views
On SlideShare
From Embeds
Number of Embeds



Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

    No notes for slide


  • 1. Redis An open source, advanced key-value store. It isoften referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets.
  • 2. Redis – get it from• Debian based Linux distros – apt-get install… • redis-server • redis-doc• Other Linux ditros – Tar from• Windows – Many sources, though not official support (google-it).
  • 3. Redis• Redis is running $ ps -ef |grep redis redis 1081 1 0 May11 ? 00:01:01 /usr/bin/redis-server /etc/redis/redis.conf• Redis client / console $ redis-cli redis> redis> ? redis-cli 2.2.11 Type: "help @<group>" to get a list of commands in <group> "help <command>" for help on <command> "help <tab>" to get a list of possible help topics "quit" to exit redis> quit $
  • 4. Redis• Redis commands $ redis-cli redis> redis> SET server:name “test” OK redis> GET server:name “test” redis> DEL server:name (integer) 1 redis> GET server:name (nil) redis> $
  • 5. Redis• Redis more interesting commands – INCR – EXPIRE – TTL• Redis support for Lists: – RPUSH, LPUSH, LLEN, LRANGE, LPOP, and RPOP• Redis support for Sets (and Sorted sets): – SADD, SREM, SISMEMBER, SMEMBERS and SUNION.• More at
  • 6. Redis and Python• Need to add the redis-py module $ easy_install redis• On the python console >>> import redis >>> r_server = redis.Redis("localhost") >>> r_server.set(“whatever", “myTest") True >>> r_server.get(“whatever”) myTest
  • 7. Redis and Python• Simple method to add an object to redis: def save_to_redis(self): """Saves a product to the local redis database""" r = redis.Redis("localhost") if r.sadd("products", self.pId): r.set("product:%s:category" % self.pId, r.set("product:%s:brand" % self.pId, self.brand) r.set("product:%s:description" % self.pId, self.desc) r.set("product:%s:price" % self.pId, self.price) r.set("product:%s:url" % self.pId, self.url) return True else return False
  • 8. Redis and Python• Simple method to read an object to redis: @staticmethod def get_product(param_id): r = redis.Redis("localhost") if r.sismember("products",param_id): cat = r.get("product:%s:category" % param_id) brand = r.get("product:%s:brand" % param_id).decode(utf-8) desc = r.get("product:%s:description" % param_id).decode(utf-8) price = r.get("product:%s:price" % param_id) url = r.get("product:%s:url" % param_id).decode(utf-8) return Product(param_id,cat,brand,desc,price,url)
  • 9. Redis• Back at the redis-cli : $ redis-cli redis> SCARD products (integer) 3 redis> SMEMBERS products 1) "140274“ 2) "115165“ 3) "114278“ redis> SISMEMBER products 115165 (integer) 1 redis> keys product:140274:* 1) "product:140274:brand" 2) "product:140274:description" 3) "product:140274:url" 4) "product:140274:category" 5) "product:140274:price" redis> GET product:140274:description "212 Glam Men Eau De Toilette Spray 100ml/3.4oz"
  • 10. Redis FIM.