Redis  An open source, advanced key-value store. It isoften referred to as a data structure server since                  ...
Redis – get it from• Debian based Linux distros   – apt-get install…    • redis-server    • redis-doc• Other Linux ditros ...
Redis• Redis is running  $ ps -ef |grep redis   redis 1081 1 0 May11 ? 00:01:01 /usr/bin/redis-server /etc/redis/redis.con...
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:...
Redis• Redis more interesting commands  – INCR  – EXPIRE  – TTL• Redis support for Lists:  – RPUSH, LPUSH, LLEN, LRANGE, L...
Redis and Python• Need to add the redis-py module $ easy_install redis• On the python console >>> import redis >>> r_serve...
Redis and Python• Simple method to add an object to redis:  def save_to_redis(self):      """Saves a product to the local ...
Redis and Python• Simple method to read an object to redis:  @staticmethod  def get_product(param_id):      r = redis.Redi...
Redis•   Back at the redis-cli :    $ redis-cli    redis 127.0.0.1:6379> SCARD products    (integer) 3    redis 127.0.0.1:...
Redis FIM.
Upcoming SlideShare
Loading in...5
×

Redis

1,186

Published on

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
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,186
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
19
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Redis

  1. 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. http://redis.io
  2. 2. 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).
  3. 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 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 $
  4. 4. 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> $
  5. 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 http://redis.io/documentation
  6. 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. 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, 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
  8. 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. 9. 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"
  10. 10. Redis FIM.
  1. A particular slide catching your eye?

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

×