Upcoming SlideShare
Loading in...5




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.



Total Views
Views on SlideShare
Embed Views



0 Embeds 0

No embeds



Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

Redis Redis Presentation Transcript

  • 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.
  • 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).
  • 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 $
  • 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> $
  • 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
  • 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
  • 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
  • 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)
  • 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"
  • Redis FIM.