Redis
Upcoming SlideShare
Loading in...5
×
 

Redis

on

  • 1,488 views

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.

Statistics

Views

Total Views
1,488
Views on SlideShare
1,488
Embed Views
0

Actions

Likes
0
Downloads
15
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

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.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
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. http://redis.io
  • Redis – get it from• Debian based Linux distros – apt-get install… • redis-server • redis-doc• Other Linux ditros – Tar from http://redis.io• 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 127.0.0.1:6379> redis 127.0.0.1:6379> ? 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 127.0.0.1:6379> quit $
  • Redis• Redis commands $ redis-cli redis 127.0.0.1:6379> redis 127.0.0.1:6379> SET server:name “test” OK redis 127.0.0.1:6379> GET server:name “test” redis 127.0.0.1:6379> DEL server:name (integer) 1 redis 127.0.0.1:6379> GET server:name (nil) redis 127.0.0.1:6379> $
  • 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 http://redis.io/documentation
  • 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, self.cat) 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 127.0.0.1:6379> SCARD products (integer) 3 redis 127.0.0.1:6379> SMEMBERS products 1) "140274“ 2) "115165“ 3) "114278“ redis 127.0.0.1:6379> SISMEMBER products 115165 (integer) 1 redis 127.0.0.1:6379> keys product:140274:* 1) "product:140274:brand" 2) "product:140274:description" 3) "product:140274:url" 4) "product:140274:category" 5) "product:140274:price" redis 127.0.0.1:6379> GET product:140274:description "212 Glam Men Eau De Toilette Spray 100ml/3.4oz"
  • Redis FIM.