SlideShare une entreprise Scribd logo
1  sur  30
Télécharger pour lire hors ligne
The Basics 
Dominik Gruber, @the_dom 
ViennaDB – Sep. 22, 2014
Agenda 
• What Is Redis? 
• Operations / Data Types 
• Transactions 
• Scripting 
• Use Cases 
Dominik Redis Gruber • @the_dom
Dominik Gruber 
• Work at KURIER.at online network 
• Many services, among them events.at–which 
makes use of Redis 
• Studied “Software Engineering & Internet 
Computing” at Vienna University of Technology 
Dominik Redis Gruber • @the_dom
Fun Facts 
• Redis = REmote DIctionary Server 
• Initial release in 2009 
• Most recent version: 2.8.17 
• Written in C 
• Libraries for 30+ programming languages 
• Good documentation 
Dominik Redis Gruber • @the_dom
Redis 
“Redis is an open source, BSD licensed, 
advanced key-value cache and store. It is often 
referred to as a data structure server since 
keys can contain strings, hashes, lists, sets, 
sorted sets, bitmaps and hyperloglogs.” 
Dominik Redis Gruber • @the_dom
Redis 
• Redis is an in-memory but persistent on disk database 
• 1 Million small Key -> String value pairs use ~ 100 MB of memory 
• Single threaded – but CPU should not be the bottleneck 
• Average Linux system can deliver even 500k requests per 
second 
• Limit is likely the available memory in your system 
• max. 232 keys 
Dominik Redis Gruber • @the_dom
Differences to Memcached 
• Memcached is a “distributed memory object caching system” 
• Redis persists data to disk eventually 
• Memcached is an LRU cache 
• Redis has different data types and more features 
• Memcached is multithreaded 
• Similar speed 
Dominik Redis Gruber • @the_dom
Prominent Adopters 
• Twitter 
• Pinterest 
• Tumblr 
• GitHub 
• Stack Overflow 
Dominik Redis Gruber • @the_dom
Operations / Data Types 
Dominik Redis Gruber • @the_dom
Basics 
• SET key value [EX seconds] [PX milliseconds] [NX|XX] 
• GET key 
• DEL key 
! 
• Possible Use Case: Caching 
Dominik Redis Gruber • @the_dom
Basics 
• EXISTS key 
• KEYS pattern 
• EXPIRE key seconds 
• MGET key [key …] 
• MSET key value [key value …] 
Dominik Redis Gruber • @the_dom
Strings 
• STRLEN KEY 
• APPEND key value 
Dominik Redis Gruber • @the_dom
Integer 
• INCR key / INCRBY key increment 
• DECR key / DECRBY key increment 
! 
• Possible Use Case: Track Ad- or Page-Impressions 
Dominik Redis Gruber • @the_dom
Hashes 
• HSET key field value 
• HGET key field 
• HGETALL key 
• HDEL key field [field …] 
! 
• Possible Use Case: Session Storage 
Dominik Redis Gruber • @the_dom
Lists 
• LSET key index value 
• LPUSH key value [value …] / RPUSH key value [value …] 
• LPOP key / RPOP key 
• LRANGE key start stopl 
• LREM key count value 
• Possible Use Cases: Task queue, Last modified items (with paging) 
Dominik Redis Gruber • @the_dom
Sets 
• SADD key member [member …] 
• SMEMBERS key / SRANDMEMBER key [count] 
• SSCAN key cursor [MATCH pattern] [COUNT count] 
• SISMEMBER key member 
• SPOP key 
• SREM key member [member …] 
• Possible Use Case: Index items by category 
Dominik Redis Gruber • @the_dom
Sets: Operations 
• SINTER key [key …] / SINTERSTORE destination key [key …] 
• SDIFF key [key …] / SDIFFSTORE destination key [key …] 
• SUNION key [key …] / SUNIONSTORE destination key [key …] 
Dominik Redis Gruber • @the_dom
Sorted Sets 
• ZADD key score member [score member …] 
• ZSCORE key member 
• ZRANGEBYSCORE key min max [WITHSCORES] [LIMIT offset 
count] 
• ZREM key member [member ...] 
• ZREMRANGEBYLEX key min max 
• ZINCRBY key increment member 
• Possible Use Case: Scoreboards, Track time-based events 
Dominik Redis Gruber • @the_dom
HyperLogLog 
“Hyperloglog is an approximate technique for 
computing the number of distinct entries in a set 
(cardinality). It does this while using a small amount of 
memory. For instance, to achieve 99% accuracy, it 
needs only 16 KB. “ 
– Wikipedia 
Dominik Redis Gruber • @the_dom
HyperLogLog 
• PFADD key element [element …] 
• PFCOUNT key [key …] 
• PFMERGE destkey sourcekey [sourcekey ...] 
! 
• Possible Use Case: Track Unique Visitors 
Dominik Redis Gruber • @the_dom
Pub/Sub 
• SUBSCRIBE channel [channel …] 
• UNSUBSCRIBE [channel [channel …]] 
! 
• PUBLISH channel message 
Dominik Redis Gruber • @the_dom
Transactions 
• MULTI 
• EXEC 
• DISCARD 
Dominik Redis Gruber • @the_dom
Transactions 
WATCH mykey 
val = GET mykey 
val = val + 1 
MULTI 
SET mykey $val 
EXEC 
! 
Dominik Redis Gruber • @the_dom
Scripting 
• Execute Lua scripts on the server side 
• EVAL script numkeys key [key ...] arg [arg …] 
! 
• SCRIPT LOAD script 
• EVALSHA sha1 numkeys key [key ...] arg [arg ...] 
Dominik Redis Gruber • @the_dom
Scripting: Example 
RandomPushScript = <<EOF 
local i = tonumber(ARGV[1]) 
local res 
math.randomseed(tonumber(ARGV[2])) 
while (i > 0) do 
res = redis.call('lpush',KEYS[1],math.random()) 
i = i-1 
end 
return res 
EOF 
! 
r.del(:mylist) 
puts r.eval(RandomPushScript,1,:mylist,10,rand(2**32)) 
Dominik Redis Gruber • @the_dom
Use Cases 
Dominik Redis Gruber • @the_dom
Resque 
• “Resque is a Redis-backed Ruby library for creating background 
jobs, placing them on multiple queues, and processing them 
later.” 
• Comes with a web interface 
• Developed by GitHub 
• https://github.com/resque/resque 
• https://github.com/blog/542-introducing-resque 
Dominik Redis Gruber • @the_dom
Typeahead Completion 
• ZRANGEBYLEX key min max [LIMIT offset count] 
• ZRANGEBYLEX uses plain binary comparison 
! 
• ZADD autocomplete 0 apricot 0 apple 0 banana 0 brocolli 0 
brinjal 
• ZRANGEBYLEX autocomplete [br [br(0xff) 
! 
• ZADD 0 mango:{"name":"Mango Smoothie Recipe"} 
0 smoothie:{"name":"Mango Smoothie Recipe"} 
0 recipe:{"name":"Mango Smoothie Recipe"} 
Dominik Redis Gruber • @the_dom
Q & A 
Dominik Redis Gruber • @the_dom
Source 
• http://redis.io 
• http://highscalability.com 
• http://www.cucumbertown.com/craft/ 
autocomplete-using-redis-nginx-lua/ 
Dominik Redis Gruber • @the_dom

Contenu connexe

En vedette

Using Redis as Distributed Cache for ASP.NET apps - Peter Kellner, 73rd Stre...
 Using Redis as Distributed Cache for ASP.NET apps - Peter Kellner, 73rd Stre... Using Redis as Distributed Cache for ASP.NET apps - Peter Kellner, 73rd Stre...
Using Redis as Distributed Cache for ASP.NET apps - Peter Kellner, 73rd Stre...Redis Labs
 
RedisConf 2016 talk - The Redis API: Simple, Composable, Powerful
RedisConf 2016 talk - The Redis API: Simple, Composable, PowerfulRedisConf 2016 talk - The Redis API: Simple, Composable, Powerful
RedisConf 2016 talk - The Redis API: Simple, Composable, PowerfulDynomiteDB
 
Troubleshooting Redis- DaeMyung Kang, Kakao
Troubleshooting Redis- DaeMyung Kang, KakaoTroubleshooting Redis- DaeMyung Kang, Kakao
Troubleshooting Redis- DaeMyung Kang, KakaoRedis Labs
 
Scalable Streaming Data Pipelines with Redis
Scalable Streaming Data Pipelines with RedisScalable Streaming Data Pipelines with Redis
Scalable Streaming Data Pipelines with RedisAvram Lyon
 
Cloud Foundry for Data Science
Cloud Foundry for Data ScienceCloud Foundry for Data Science
Cloud Foundry for Data ScienceIan Huston
 
Back your App with MySQL & Redis, the Cloud Foundry Way- Kenny Bastani, Pivotal
Back your App with MySQL & Redis, the Cloud Foundry Way- Kenny Bastani, PivotalBack your App with MySQL & Redis, the Cloud Foundry Way- Kenny Bastani, Pivotal
Back your App with MySQL & Redis, the Cloud Foundry Way- Kenny Bastani, PivotalRedis Labs
 
Redis & MongoDB: Stop Big Data Indigestion Before It Starts
Redis & MongoDB: Stop Big Data Indigestion Before It StartsRedis & MongoDB: Stop Big Data Indigestion Before It Starts
Redis & MongoDB: Stop Big Data Indigestion Before It StartsItamar Haber
 
Redis High availability and fault tolerance in a multitenant environment
Redis High availability and fault tolerance in a multitenant environmentRedis High availability and fault tolerance in a multitenant environment
Redis High availability and fault tolerance in a multitenant environmentIccha Sethi
 
March 29, 2016 Dr. Josiah Carlson talks about using Redis as a Time Series DB
March 29, 2016 Dr. Josiah Carlson talks about using Redis as a Time Series DBMarch 29, 2016 Dr. Josiah Carlson talks about using Redis as a Time Series DB
March 29, 2016 Dr. Josiah Carlson talks about using Redis as a Time Series DBJosiah Carlson
 
Benchmarking Redis by itself and versus other NoSQL databases
Benchmarking Redis by itself and versus other NoSQL databasesBenchmarking Redis by itself and versus other NoSQL databases
Benchmarking Redis by itself and versus other NoSQL databasesItamar Haber
 
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
 
Leveraging Probabilistic Data Structures for Real Time Analytics with Redis M...
Leveraging Probabilistic Data Structures for Real Time Analytics with Redis M...Leveraging Probabilistic Data Structures for Real Time Analytics with Redis M...
Leveraging Probabilistic Data Structures for Real Time Analytics with Redis M...Itamar Haber
 

En vedette (13)

Using Redis as Distributed Cache for ASP.NET apps - Peter Kellner, 73rd Stre...
 Using Redis as Distributed Cache for ASP.NET apps - Peter Kellner, 73rd Stre... Using Redis as Distributed Cache for ASP.NET apps - Peter Kellner, 73rd Stre...
Using Redis as Distributed Cache for ASP.NET apps - Peter Kellner, 73rd Stre...
 
RedisConf 2016 talk - The Redis API: Simple, Composable, Powerful
RedisConf 2016 talk - The Redis API: Simple, Composable, PowerfulRedisConf 2016 talk - The Redis API: Simple, Composable, Powerful
RedisConf 2016 talk - The Redis API: Simple, Composable, Powerful
 
Troubleshooting Redis- DaeMyung Kang, Kakao
Troubleshooting Redis- DaeMyung Kang, KakaoTroubleshooting Redis- DaeMyung Kang, Kakao
Troubleshooting Redis- DaeMyung Kang, Kakao
 
Scalable Streaming Data Pipelines with Redis
Scalable Streaming Data Pipelines with RedisScalable Streaming Data Pipelines with Redis
Scalable Streaming Data Pipelines with Redis
 
Cloud Foundry for Data Science
Cloud Foundry for Data ScienceCloud Foundry for Data Science
Cloud Foundry for Data Science
 
Back your App with MySQL & Redis, the Cloud Foundry Way- Kenny Bastani, Pivotal
Back your App with MySQL & Redis, the Cloud Foundry Way- Kenny Bastani, PivotalBack your App with MySQL & Redis, the Cloud Foundry Way- Kenny Bastani, Pivotal
Back your App with MySQL & Redis, the Cloud Foundry Way- Kenny Bastani, Pivotal
 
Redis & MongoDB: Stop Big Data Indigestion Before It Starts
Redis & MongoDB: Stop Big Data Indigestion Before It StartsRedis & MongoDB: Stop Big Data Indigestion Before It Starts
Redis & MongoDB: Stop Big Data Indigestion Before It Starts
 
Redis High availability and fault tolerance in a multitenant environment
Redis High availability and fault tolerance in a multitenant environmentRedis High availability and fault tolerance in a multitenant environment
Redis High availability and fault tolerance in a multitenant environment
 
March 29, 2016 Dr. Josiah Carlson talks about using Redis as a Time Series DB
March 29, 2016 Dr. Josiah Carlson talks about using Redis as a Time Series DBMarch 29, 2016 Dr. Josiah Carlson talks about using Redis as a Time Series DB
March 29, 2016 Dr. Josiah Carlson talks about using Redis as a Time Series DB
 
Benchmarking Redis by itself and versus other NoSQL databases
Benchmarking Redis by itself and versus other NoSQL databasesBenchmarking Redis by itself and versus other NoSQL databases
Benchmarking Redis by itself and versus other NoSQL databases
 
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
 
Leveraging Probabilistic Data Structures for Real Time Analytics with Redis M...
Leveraging Probabilistic Data Structures for Real Time Analytics with Redis M...Leveraging Probabilistic Data Structures for Real Time Analytics with Redis M...
Leveraging Probabilistic Data Structures for Real Time Analytics with Redis M...
 
Redis acc 2015_eng
Redis acc 2015_engRedis acc 2015_eng
Redis acc 2015_eng
 

Dernier

"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
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
 
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
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
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
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 

Dernier (20)

"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
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
 
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
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
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...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 

2014-09-22 | Redis - The Basics (ViennaDB)

  • 1. The Basics Dominik Gruber, @the_dom ViennaDB – Sep. 22, 2014
  • 2. Agenda • What Is Redis? • Operations / Data Types • Transactions • Scripting • Use Cases Dominik Redis Gruber • @the_dom
  • 3. Dominik Gruber • Work at KURIER.at online network • Many services, among them events.at–which makes use of Redis • Studied “Software Engineering & Internet Computing” at Vienna University of Technology Dominik Redis Gruber • @the_dom
  • 4. Fun Facts • Redis = REmote DIctionary Server • Initial release in 2009 • Most recent version: 2.8.17 • Written in C • Libraries for 30+ programming languages • Good documentation Dominik Redis Gruber • @the_dom
  • 5. Redis “Redis is an open source, BSD licensed, advanced key-value cache and store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets, sorted sets, bitmaps and hyperloglogs.” Dominik Redis Gruber • @the_dom
  • 6. Redis • Redis is an in-memory but persistent on disk database • 1 Million small Key -> String value pairs use ~ 100 MB of memory • Single threaded – but CPU should not be the bottleneck • Average Linux system can deliver even 500k requests per second • Limit is likely the available memory in your system • max. 232 keys Dominik Redis Gruber • @the_dom
  • 7. Differences to Memcached • Memcached is a “distributed memory object caching system” • Redis persists data to disk eventually • Memcached is an LRU cache • Redis has different data types and more features • Memcached is multithreaded • Similar speed Dominik Redis Gruber • @the_dom
  • 8. Prominent Adopters • Twitter • Pinterest • Tumblr • GitHub • Stack Overflow Dominik Redis Gruber • @the_dom
  • 9. Operations / Data Types Dominik Redis Gruber • @the_dom
  • 10. Basics • SET key value [EX seconds] [PX milliseconds] [NX|XX] • GET key • DEL key ! • Possible Use Case: Caching Dominik Redis Gruber • @the_dom
  • 11. Basics • EXISTS key • KEYS pattern • EXPIRE key seconds • MGET key [key …] • MSET key value [key value …] Dominik Redis Gruber • @the_dom
  • 12. Strings • STRLEN KEY • APPEND key value Dominik Redis Gruber • @the_dom
  • 13. Integer • INCR key / INCRBY key increment • DECR key / DECRBY key increment ! • Possible Use Case: Track Ad- or Page-Impressions Dominik Redis Gruber • @the_dom
  • 14. Hashes • HSET key field value • HGET key field • HGETALL key • HDEL key field [field …] ! • Possible Use Case: Session Storage Dominik Redis Gruber • @the_dom
  • 15. Lists • LSET key index value • LPUSH key value [value …] / RPUSH key value [value …] • LPOP key / RPOP key • LRANGE key start stopl • LREM key count value • Possible Use Cases: Task queue, Last modified items (with paging) Dominik Redis Gruber • @the_dom
  • 16. Sets • SADD key member [member …] • SMEMBERS key / SRANDMEMBER key [count] • SSCAN key cursor [MATCH pattern] [COUNT count] • SISMEMBER key member • SPOP key • SREM key member [member …] • Possible Use Case: Index items by category Dominik Redis Gruber • @the_dom
  • 17. Sets: Operations • SINTER key [key …] / SINTERSTORE destination key [key …] • SDIFF key [key …] / SDIFFSTORE destination key [key …] • SUNION key [key …] / SUNIONSTORE destination key [key …] Dominik Redis Gruber • @the_dom
  • 18. Sorted Sets • ZADD key score member [score member …] • ZSCORE key member • ZRANGEBYSCORE key min max [WITHSCORES] [LIMIT offset count] • ZREM key member [member ...] • ZREMRANGEBYLEX key min max • ZINCRBY key increment member • Possible Use Case: Scoreboards, Track time-based events Dominik Redis Gruber • @the_dom
  • 19. HyperLogLog “Hyperloglog is an approximate technique for computing the number of distinct entries in a set (cardinality). It does this while using a small amount of memory. For instance, to achieve 99% accuracy, it needs only 16 KB. “ – Wikipedia Dominik Redis Gruber • @the_dom
  • 20. HyperLogLog • PFADD key element [element …] • PFCOUNT key [key …] • PFMERGE destkey sourcekey [sourcekey ...] ! • Possible Use Case: Track Unique Visitors Dominik Redis Gruber • @the_dom
  • 21. Pub/Sub • SUBSCRIBE channel [channel …] • UNSUBSCRIBE [channel [channel …]] ! • PUBLISH channel message Dominik Redis Gruber • @the_dom
  • 22. Transactions • MULTI • EXEC • DISCARD Dominik Redis Gruber • @the_dom
  • 23. Transactions WATCH mykey val = GET mykey val = val + 1 MULTI SET mykey $val EXEC ! Dominik Redis Gruber • @the_dom
  • 24. Scripting • Execute Lua scripts on the server side • EVAL script numkeys key [key ...] arg [arg …] ! • SCRIPT LOAD script • EVALSHA sha1 numkeys key [key ...] arg [arg ...] Dominik Redis Gruber • @the_dom
  • 25. Scripting: Example RandomPushScript = <<EOF local i = tonumber(ARGV[1]) local res math.randomseed(tonumber(ARGV[2])) while (i > 0) do res = redis.call('lpush',KEYS[1],math.random()) i = i-1 end return res EOF ! r.del(:mylist) puts r.eval(RandomPushScript,1,:mylist,10,rand(2**32)) Dominik Redis Gruber • @the_dom
  • 26. Use Cases Dominik Redis Gruber • @the_dom
  • 27. Resque • “Resque is a Redis-backed Ruby library for creating background jobs, placing them on multiple queues, and processing them later.” • Comes with a web interface • Developed by GitHub • https://github.com/resque/resque • https://github.com/blog/542-introducing-resque Dominik Redis Gruber • @the_dom
  • 28. Typeahead Completion • ZRANGEBYLEX key min max [LIMIT offset count] • ZRANGEBYLEX uses plain binary comparison ! • ZADD autocomplete 0 apricot 0 apple 0 banana 0 brocolli 0 brinjal • ZRANGEBYLEX autocomplete [br [br(0xff) ! • ZADD 0 mango:{"name":"Mango Smoothie Recipe"} 0 smoothie:{"name":"Mango Smoothie Recipe"} 0 recipe:{"name":"Mango Smoothie Recipe"} Dominik Redis Gruber • @the_dom
  • 29. Q & A Dominik Redis Gruber • @the_dom
  • 30. Source • http://redis.io • http://highscalability.com • http://www.cucumbertown.com/craft/ autocomplete-using-redis-nginx-lua/ Dominik Redis Gruber • @the_dom