SlideShare una empresa de Scribd logo
1 de 30
Descargar para leer sin conexión
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

Más contenido relacionado

Destacado

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
 

Destacado (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
 

Último

Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
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
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
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
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
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
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 

Último (20)

Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
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...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
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
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
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...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
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?
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 

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