SlideShare uma empresa Scribd logo
1 de 10
Baixar para ler offline
Redis
  An open source, advanced key-value store. It is
often 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.

Mais conteúdo relacionado

Mais procurados

Solr & Lucene @ Etsy by Gregg Donovan
Solr & Lucene @ Etsy by Gregg DonovanSolr & Lucene @ Etsy by Gregg Donovan
Solr & Lucene @ Etsy by Gregg DonovanGregg Donovan
 
Manifests of Future Past
Manifests of Future PastManifests of Future Past
Manifests of Future PastPuppet
 
New SPL Features in PHP 5.3
New SPL Features in PHP 5.3New SPL Features in PHP 5.3
New SPL Features in PHP 5.3Matthew Turland
 
PHP Arrays - indexed and associative array.
PHP Arrays - indexed and associative array. PHP Arrays - indexed and associative array.
PHP Arrays - indexed and associative array. wahidullah mudaser
 
Redis and its many use cases
Redis and its many use casesRedis and its many use cases
Redis and its many use casesChristian Joudrey
 
Redis for the Everyday Developer
Redis for the Everyday DeveloperRedis for the Everyday Developer
Redis for the Everyday DeveloperRoss Tuck
 
ApacheCon: Abdera A Java Atom Pub Implementation
ApacheCon: Abdera A Java Atom Pub ImplementationApacheCon: Abdera A Java Atom Pub Implementation
ApacheCon: Abdera A Java Atom Pub ImplementationDavid Calavera
 
ElasticSearch 5.x - New Tricks - 2017-02-08 - Elasticsearch Meetup
ElasticSearch 5.x -  New Tricks - 2017-02-08 - Elasticsearch Meetup ElasticSearch 5.x -  New Tricks - 2017-02-08 - Elasticsearch Meetup
ElasticSearch 5.x - New Tricks - 2017-02-08 - Elasticsearch Meetup Alberto Paro
 
Introduction to Apache Pig
Introduction to Apache PigIntroduction to Apache Pig
Introduction to Apache PigAnshul Bhatnagar
 

Mais procurados (20)

Simple uses of ADRCI
Simple uses of ADRCISimple uses of ADRCI
Simple uses of ADRCI
 
Solr & Lucene @ Etsy by Gregg Donovan
Solr & Lucene @ Etsy by Gregg DonovanSolr & Lucene @ Etsy by Gregg Donovan
Solr & Lucene @ Etsy by Gregg Donovan
 
Manifests of Future Past
Manifests of Future PastManifests of Future Past
Manifests of Future Past
 
Spl Not A Bridge Too Far phpNW09
Spl Not A Bridge Too Far phpNW09Spl Not A Bridge Too Far phpNW09
Spl Not A Bridge Too Far phpNW09
 
New SPL Features in PHP 5.3
New SPL Features in PHP 5.3New SPL Features in PHP 5.3
New SPL Features in PHP 5.3
 
Solr @ Etsy - Apache Lucene Eurocon
Solr @ Etsy - Apache Lucene EuroconSolr @ Etsy - Apache Lucene Eurocon
Solr @ Etsy - Apache Lucene Eurocon
 
Routing @ Scuk.cz
Routing @ Scuk.czRouting @ Scuk.cz
Routing @ Scuk.cz
 
PHP Arrays - indexed and associative array.
PHP Arrays - indexed and associative array. PHP Arrays - indexed and associative array.
PHP Arrays - indexed and associative array.
 
Sql cheat sheet
Sql cheat sheetSql cheat sheet
Sql cheat sheet
 
Redis and its many use cases
Redis and its many use casesRedis and its many use cases
Redis and its many use cases
 
C99[2]
C99[2]C99[2]
C99[2]
 
Redis for the Everyday Developer
Redis for the Everyday DeveloperRedis for the Everyday Developer
Redis for the Everyday Developer
 
Perl Web Client
Perl Web ClientPerl Web Client
Perl Web Client
 
dotCloud and go
dotCloud and godotCloud and go
dotCloud and go
 
Nubilus Perl
Nubilus PerlNubilus Perl
Nubilus Perl
 
ApacheCon: Abdera A Java Atom Pub Implementation
ApacheCon: Abdera A Java Atom Pub ImplementationApacheCon: Abdera A Java Atom Pub Implementation
ApacheCon: Abdera A Java Atom Pub Implementation
 
ElasticSearch 5.x - New Tricks - 2017-02-08 - Elasticsearch Meetup
ElasticSearch 5.x -  New Tricks - 2017-02-08 - Elasticsearch Meetup ElasticSearch 5.x -  New Tricks - 2017-02-08 - Elasticsearch Meetup
ElasticSearch 5.x - New Tricks - 2017-02-08 - Elasticsearch Meetup
 
Introduction to Apache Pig
Introduction to Apache PigIntroduction to Apache Pig
Introduction to Apache Pig
 
Living with garbage
Living with garbageLiving with garbage
Living with garbage
 
Process of Hive in HDFS
Process of Hive in HDFSProcess of Hive in HDFS
Process of Hive in HDFS
 

Semelhante a Redis

Redispresentation apac2012
Redispresentation apac2012Redispresentation apac2012
Redispresentation apac2012Ankur Gupta
 
Postgres & Redis Sitting in a Tree- Rimas Silkaitis, Heroku
Postgres & Redis Sitting in a Tree- Rimas Silkaitis, HerokuPostgres & Redis Sitting in a Tree- Rimas Silkaitis, Heroku
Postgres & Redis Sitting in a Tree- Rimas Silkaitis, HerokuRedis Labs
 
Developing a Redis Module - Hackathon Kickoff
 Developing a Redis Module - Hackathon Kickoff Developing a Redis Module - Hackathon Kickoff
Developing a Redis Module - Hackathon KickoffItamar Haber
 
Scaling php applications with redis
Scaling php applications with redisScaling php applications with redis
Scaling php applications with redisjimbojsb
 
Amir Salihefendic: Redis - the hacker's database
Amir Salihefendic: Redis - the hacker's databaseAmir Salihefendic: Redis - the hacker's database
Amir Salihefendic: Redis - the hacker's databaseit-people
 
Redis Use Patterns (DevconTLV June 2014)
Redis Use Patterns (DevconTLV June 2014)Redis Use Patterns (DevconTLV June 2014)
Redis Use Patterns (DevconTLV June 2014)Itamar Haber
 
Introduction to redis
Introduction to redisIntroduction to redis
Introduction to redisTanu Siwag
 
Reproducibility with R
Reproducibility with RReproducibility with R
Reproducibility with RMartin Jung
 
Rails 3 (beta) Roundup
Rails 3 (beta) RoundupRails 3 (beta) Roundup
Rails 3 (beta) RoundupWayne Carter
 
Living the Nomadic life - Nic Jackson
Living the Nomadic life - Nic JacksonLiving the Nomadic life - Nic Jackson
Living the Nomadic life - Nic JacksonParis Container Day
 
Redis for Security Data : SecurityScorecard JVM Redis Usage
Redis for Security Data : SecurityScorecard JVM Redis UsageRedis for Security Data : SecurityScorecard JVM Redis Usage
Redis for Security Data : SecurityScorecard JVM Redis UsageTimothy Spann
 
Amazon Web Services for PHP Developers
Amazon Web Services for PHP DevelopersAmazon Web Services for PHP Developers
Amazon Web Services for PHP DevelopersJeremy Lindblom
 
Advanced Redis data structures
Advanced Redis data structuresAdvanced Redis data structures
Advanced Redis data structuresamix3k
 
Document Locking with Redis in Symfony2
Document Locking with Redis in Symfony2Document Locking with Redis in Symfony2
Document Locking with Redis in Symfony2Tom Corrigan
 

Semelhante a Redis (20)

Redispresentation apac2012
Redispresentation apac2012Redispresentation apac2012
Redispresentation apac2012
 
Postgres & Redis Sitting in a Tree- Rimas Silkaitis, Heroku
Postgres & Redis Sitting in a Tree- Rimas Silkaitis, HerokuPostgres & Redis Sitting in a Tree- Rimas Silkaitis, Heroku
Postgres & Redis Sitting in a Tree- Rimas Silkaitis, Heroku
 
Developing a Redis Module - Hackathon Kickoff
 Developing a Redis Module - Hackathon Kickoff Developing a Redis Module - Hackathon Kickoff
Developing a Redis Module - Hackathon Kickoff
 
Scaling php applications with redis
Scaling php applications with redisScaling php applications with redis
Scaling php applications with redis
 
Amir Salihefendic: Redis - the hacker's database
Amir Salihefendic: Redis - the hacker's databaseAmir Salihefendic: Redis - the hacker's database
Amir Salihefendic: Redis - the hacker's database
 
Redis Use Patterns (DevconTLV June 2014)
Redis Use Patterns (DevconTLV June 2014)Redis Use Patterns (DevconTLV June 2014)
Redis Use Patterns (DevconTLV June 2014)
 
Redis 101
Redis 101Redis 101
Redis 101
 
Nessus and Reporting Karma
Nessus and Reporting KarmaNessus and Reporting Karma
Nessus and Reporting Karma
 
Introduction to redis
Introduction to redisIntroduction to redis
Introduction to redis
 
Redis
RedisRedis
Redis
 
RediSearch Mumbai Meetup 2020
RediSearch Mumbai Meetup 2020RediSearch Mumbai Meetup 2020
RediSearch Mumbai Meetup 2020
 
Mini-Training: Redis
Mini-Training: RedisMini-Training: Redis
Mini-Training: Redis
 
Reproducibility with R
Reproducibility with RReproducibility with R
Reproducibility with R
 
Rails 3 (beta) Roundup
Rails 3 (beta) RoundupRails 3 (beta) Roundup
Rails 3 (beta) Roundup
 
Living the Nomadic life - Nic Jackson
Living the Nomadic life - Nic JacksonLiving the Nomadic life - Nic Jackson
Living the Nomadic life - Nic Jackson
 
Redis for Security Data : SecurityScorecard JVM Redis Usage
Redis for Security Data : SecurityScorecard JVM Redis UsageRedis for Security Data : SecurityScorecard JVM Redis Usage
Redis for Security Data : SecurityScorecard JVM Redis Usage
 
Redis introduction
Redis introductionRedis introduction
Redis introduction
 
Amazon Web Services for PHP Developers
Amazon Web Services for PHP DevelopersAmazon Web Services for PHP Developers
Amazon Web Services for PHP Developers
 
Advanced Redis data structures
Advanced Redis data structuresAdvanced Redis data structures
Advanced Redis data structures
 
Document Locking with Redis in Symfony2
Document Locking with Redis in Symfony2Document Locking with Redis in Symfony2
Document Locking with Redis in Symfony2
 

Último

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusZilliz
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbuapidays
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...apidays
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 

Último (20)

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 

Redis

  • 1. Redis An open source, advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets. http://redis.io
  • 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. 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. 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. 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. 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, 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. 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 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"