SlideShare uma empresa Scribd logo
1 de 21
Baixar para ler offline
Michael Parker
June 2, 2012
What is Redis?
● Like the key-value store Memcache
● Optional persistence to disk
● Treats values not as opaque data, but as
data structures
○ Calls itself a "data structure server"
Memcache

Redis

key1

value1

key1

[1, 1, "foo"]

key2

value2

key2

{2, 3, "bar", "mgp"}

key3

value3

key3

"f1"→"v1", "f2"→"v2"
Types and abstractions in
your code
● Numbers (integer, floating point, booleans)
● Strings (including characters)
● Hash tables (including objects)
○ get, set, contains, delete

● Lists
○ push, pop, get, set

● Sets
○ add, remove, union, intersection, difference

● Sorted sets
○ add, remove, first, last, range
Types and abstractions in
Redis
● Numbers (integer, floating point, booleans)
● Strings (including characters)
● Hash tables (including objects)
○ get, set, contains, delete

● Lists
○ push, pop, get, set

● Sets
○ add, remove, union, intersection, difference

● Sorted sets
○ add, remove, first, last, range
Play along!
http://try.redis-db.com
Numbers and strings
> SET "num1" 5
"OK"
> INCR "num1"
6
> SET "str1" "hackernews"
"OK"
> GET "str1"
"hackernews"
> MGET "num1" "str1" "unknown_key"
["6","hackernews",null]
Lists
> LPUSH "list1" 5
1
> LPUSH "list1" 4
2
> RPUSH "list1" 6
3
> LSET "list1" 1 "moo"
"OK"
> LRANGE "list1" 0 -1
["4","moo","6"]
Sets
> SADD "set1" "cats"
true
> SADD "set1" "dogs"
true
> SADD "set2" "dogs"
true
> SADD "set2" "monkeys"
true
> SUNION "set1" "set2"
["cats","dogs","monkeys"]
Maps (hashes)
> HSET "map1" "field1" "value1"
true
> HSET "map1" "field2" "value2"
true
> HEXISTS "map1" "field3"
false
> HGETALL "map1"
{"field1":"value1","field2":"value2"}
Transactions
● Commands to set/get values in maps, and
add/remove values in lists and sets and
sorted sets already take multiple arguments
● But transactions work across multiple keys
○ Atomicity
○ Fewer RPCs
Transactions - writing
> MULTI
"OK"
> HSET "map1" "field1" "value1"
"QUEUED"
> LPUSH "list1" 5
"QUEUED"
> SADD "set1" "cats"
"QUEUED"
> EXEC
[1,1,1]
Transactions - reading
> MULTI
"OK"
> HGETALL "map1"
"QUEUED"
> LRANGE "list1" 0 -1
"QUEUED"
> SMEMBERS "set1"
"QUEUED"
> EXEC
[["field1","value1"],["5"],["cats"]]
Odds and ends
● Sorted sets
○ Allow you to implement a heap or priority queue

● Publish and subscribe
○ Like an event bus
○ Kind of out of place
○ Spun off from blocking pop on lists
ReadyUp!
Creating plan identifiers
> INCR "next_plan_id"
1
> INCR "next_plan_id"
2
> INCR "next_plan_id"
3

Do the same for user identifiers.
Reading new messages
Client sends plan_id and num_messages
messages_key = "%s_messages" % plan_id
new_messages = redis.lrange(
messages_key, num_messages, -1)

So if num_messages = 2
msg1

msg2

msg3

msg4

0

1

2

3 (-1)
Reading one plan
def get_plan(plan_id):
pipeline = redis.pipeline()
pipeline.hgetall("%s_hash" % plan_id)
pipeline.smembers("%s_attendees" % plan_id)
pipeline.lrange("%s_messages" % plan_id,
0, -1)
plan_data, attendees, messages =
pipeline.execute()
return Plan(
plan_id, plan_data, attendees, messages)
Reading multiple plans filling the pipeline
pipeline = redis.pipeline()
for plan_id in plan_ids:
pipeline_get_plan(plan_id, pipeline)
def pipeline_get_plan(plan_id, pipeline)
pipeline.hgetall("%s_hash" % plan_id)
pipeline.smembers("%s_attendees" % plan_id)
pipeline.lrange("%s_messages" % plan_id,
0, -1)

hash1

attendees1

messages1

hash2

attendees2

messages2
Reading multiple plans emptying the pipeline
results = pipeline.execute()
iterator = iter(results)
plans = [get_pipelined_plan(plan_id, iterator)
for plan_id in plan_ids]
def get_pipelined_plan(plan_id, iterator):
plan_data = next(iterator)
attendees = next(iterator)
messages = next(iterator)
return Plan(
plan_id, plan_data, attendees, messages)
In the works
● 2.6 (soon)
○ Lua scripting on the server-side
○ Performance and replication improvements
○ Redis ASCII art logo at startup

● 3.0
○ Clustering
Thanks!
http://redis.io
michael.g.parker@gmail.com
https://github.com/mgp
http://mgp.github.com/redis-la-hn.pdf

Mais conteúdo relacionado

Destaque

Aerospike Architecture
Aerospike ArchitectureAerospike Architecture
Aerospike ArchitecturePeter Milne
 
NoSQL in Real-time Architectures
NoSQL in Real-time ArchitecturesNoSQL in Real-time Architectures
NoSQL in Real-time ArchitecturesRonen Botzer
 
Aerospike v3 install
Aerospike v3 installAerospike v3 install
Aerospike v3 installMakoto Uehara
 
Elasticsearch - Devoxx France 2012 - English version
Elasticsearch - Devoxx France 2012 - English versionElasticsearch - Devoxx France 2012 - English version
Elasticsearch - Devoxx France 2012 - English versionDavid Pilato
 
Brief introduction on Hadoop,Dremel, Pig, FlumeJava and Cassandra
Brief introduction on Hadoop,Dremel, Pig, FlumeJava and CassandraBrief introduction on Hadoop,Dremel, Pig, FlumeJava and Cassandra
Brief introduction on Hadoop,Dremel, Pig, FlumeJava and CassandraSomnath Mazumdar
 
Aerospike: Key Value Data Access
Aerospike: Key Value Data AccessAerospike: Key Value Data Access
Aerospike: Key Value Data AccessAerospike, Inc.
 
Aerospike Rapid Rebalance
Aerospike Rapid Rebalance Aerospike Rapid Rebalance
Aerospike Rapid Rebalance Makoto Uehara
 
Aerospike Hybrid Memory Architecture
Aerospike Hybrid Memory ArchitectureAerospike Hybrid Memory Architecture
Aerospike Hybrid Memory ArchitectureAerospike, Inc.
 
Battle of the giants: Apache Solr vs ElasticSearch
Battle of the giants: Apache Solr vs ElasticSearchBattle of the giants: Apache Solr vs ElasticSearch
Battle of the giants: Apache Solr vs ElasticSearchRafał Kuć
 

Destaque (11)

Aerospike Architecture
Aerospike ArchitectureAerospike Architecture
Aerospike Architecture
 
NoSQL in Real-time Architectures
NoSQL in Real-time ArchitecturesNoSQL in Real-time Architectures
NoSQL in Real-time Architectures
 
Aerospike & GCE (LSPE Talk)
Aerospike & GCE (LSPE Talk)Aerospike & GCE (LSPE Talk)
Aerospike & GCE (LSPE Talk)
 
Aerospike v3 install
Aerospike v3 installAerospike v3 install
Aerospike v3 install
 
Aerospike deep dive LDTs
Aerospike deep dive LDTsAerospike deep dive LDTs
Aerospike deep dive LDTs
 
Elasticsearch - Devoxx France 2012 - English version
Elasticsearch - Devoxx France 2012 - English versionElasticsearch - Devoxx France 2012 - English version
Elasticsearch - Devoxx France 2012 - English version
 
Brief introduction on Hadoop,Dremel, Pig, FlumeJava and Cassandra
Brief introduction on Hadoop,Dremel, Pig, FlumeJava and CassandraBrief introduction on Hadoop,Dremel, Pig, FlumeJava and Cassandra
Brief introduction on Hadoop,Dremel, Pig, FlumeJava and Cassandra
 
Aerospike: Key Value Data Access
Aerospike: Key Value Data AccessAerospike: Key Value Data Access
Aerospike: Key Value Data Access
 
Aerospike Rapid Rebalance
Aerospike Rapid Rebalance Aerospike Rapid Rebalance
Aerospike Rapid Rebalance
 
Aerospike Hybrid Memory Architecture
Aerospike Hybrid Memory ArchitectureAerospike Hybrid Memory Architecture
Aerospike Hybrid Memory Architecture
 
Battle of the giants: Apache Solr vs ElasticSearch
Battle of the giants: Apache Solr vs ElasticSearchBattle of the giants: Apache Solr vs ElasticSearch
Battle of the giants: Apache Solr vs ElasticSearch
 

Semelhante a Introduction to Redis - LA Hacker News

Tuga IT 2017 - Redis
Tuga IT 2017 - RedisTuga IT 2017 - Redis
Tuga IT 2017 - RedisNuno Caneco
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to pythonAhmed Salama
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to RedisDvir Volk
 
BIS and DDE In Action
BIS and DDE In ActionBIS and DDE In Action
BIS and DDE In ActionJerry Merrill
 
Introduction to redis - version 2
Introduction to redis - version 2Introduction to redis - version 2
Introduction to redis - version 2Dvir Volk
 
R for Pirates. ESCCONF October 27, 2011
R for Pirates. ESCCONF October 27, 2011R for Pirates. ESCCONF October 27, 2011
R for Pirates. ESCCONF October 27, 2011Mandi Walls
 
Distributed Computing with Apache Hadoop. Introduction to MapReduce.
Distributed Computing with Apache Hadoop. Introduction to MapReduce.Distributed Computing with Apache Hadoop. Introduction to MapReduce.
Distributed Computing with Apache Hadoop. Introduction to MapReduce.Konstantin V. Shvachko
 
Erlang for data ops
Erlang for data opsErlang for data ops
Erlang for data opsmnacos
 
Introduction to Haskell: 2011-04-13
Introduction to Haskell: 2011-04-13Introduction to Haskell: 2011-04-13
Introduction to Haskell: 2011-04-13Jay Coskey
 
JDD 2016 - Tomasz Borek - DB for next project? Why, Postgres, of course
JDD 2016 - Tomasz Borek - DB for next project? Why, Postgres, of course JDD 2016 - Tomasz Borek - DB for next project? Why, Postgres, of course
JDD 2016 - Tomasz Borek - DB for next project? Why, Postgres, of course PROIDEA
 
PostgreSQL - Object Relational Database
PostgreSQL - Object Relational DatabasePostgreSQL - Object Relational Database
PostgreSQL - Object Relational DatabaseMubashar Iqbal
 
Hadoop Overview & Architecture
Hadoop Overview & Architecture  Hadoop Overview & Architecture
Hadoop Overview & Architecture EMC
 
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!Daniel Cousineau
 

Semelhante a Introduction to Redis - LA Hacker News (20)

Tuga IT 2017 - Redis
Tuga IT 2017 - RedisTuga IT 2017 - Redis
Tuga IT 2017 - Redis
 
Redis introduction
Redis introductionRedis introduction
Redis introduction
 
R for hadoopers
R for hadoopersR for hadoopers
R for hadoopers
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
MongoDB 3.0
MongoDB 3.0 MongoDB 3.0
MongoDB 3.0
 
BIS and DDE In Action
BIS and DDE In ActionBIS and DDE In Action
BIS and DDE In Action
 
Introduction to redis - version 2
Introduction to redis - version 2Introduction to redis - version 2
Introduction to redis - version 2
 
Randamization.pdf
Randamization.pdfRandamization.pdf
Randamization.pdf
 
R for Pirates. ESCCONF October 27, 2011
R for Pirates. ESCCONF October 27, 2011R for Pirates. ESCCONF October 27, 2011
R for Pirates. ESCCONF October 27, 2011
 
Distributed Computing with Apache Hadoop. Introduction to MapReduce.
Distributed Computing with Apache Hadoop. Introduction to MapReduce.Distributed Computing with Apache Hadoop. Introduction to MapReduce.
Distributed Computing with Apache Hadoop. Introduction to MapReduce.
 
Erlang for data ops
Erlang for data opsErlang for data ops
Erlang for data ops
 
Redis basics
Redis basicsRedis basics
Redis basics
 
Introduction to Haskell: 2011-04-13
Introduction to Haskell: 2011-04-13Introduction to Haskell: 2011-04-13
Introduction to Haskell: 2011-04-13
 
JDD 2016 - Tomasz Borek - DB for next project? Why, Postgres, of course
JDD 2016 - Tomasz Borek - DB for next project? Why, Postgres, of course JDD 2016 - Tomasz Borek - DB for next project? Why, Postgres, of course
JDD 2016 - Tomasz Borek - DB for next project? Why, Postgres, of course
 
P2 2017 python_strings
P2 2017 python_stringsP2 2017 python_strings
P2 2017 python_strings
 
PostgreSQL - Object Relational Database
PostgreSQL - Object Relational DatabasePostgreSQL - Object Relational Database
PostgreSQL - Object Relational Database
 
Hadoop Overview & Architecture
Hadoop Overview & Architecture  Hadoop Overview & Architecture
Hadoop Overview & Architecture
 
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
 

Último

The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
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
 
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
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
[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
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
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
 

Último (20)

The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
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...
 
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
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
[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
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
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...
 

Introduction to Redis - LA Hacker News

  • 2. What is Redis? ● Like the key-value store Memcache ● Optional persistence to disk ● Treats values not as opaque data, but as data structures ○ Calls itself a "data structure server" Memcache Redis key1 value1 key1 [1, 1, "foo"] key2 value2 key2 {2, 3, "bar", "mgp"} key3 value3 key3 "f1"→"v1", "f2"→"v2"
  • 3. Types and abstractions in your code ● Numbers (integer, floating point, booleans) ● Strings (including characters) ● Hash tables (including objects) ○ get, set, contains, delete ● Lists ○ push, pop, get, set ● Sets ○ add, remove, union, intersection, difference ● Sorted sets ○ add, remove, first, last, range
  • 4. Types and abstractions in Redis ● Numbers (integer, floating point, booleans) ● Strings (including characters) ● Hash tables (including objects) ○ get, set, contains, delete ● Lists ○ push, pop, get, set ● Sets ○ add, remove, union, intersection, difference ● Sorted sets ○ add, remove, first, last, range
  • 6. Numbers and strings > SET "num1" 5 "OK" > INCR "num1" 6 > SET "str1" "hackernews" "OK" > GET "str1" "hackernews" > MGET "num1" "str1" "unknown_key" ["6","hackernews",null]
  • 7. Lists > LPUSH "list1" 5 1 > LPUSH "list1" 4 2 > RPUSH "list1" 6 3 > LSET "list1" 1 "moo" "OK" > LRANGE "list1" 0 -1 ["4","moo","6"]
  • 8. Sets > SADD "set1" "cats" true > SADD "set1" "dogs" true > SADD "set2" "dogs" true > SADD "set2" "monkeys" true > SUNION "set1" "set2" ["cats","dogs","monkeys"]
  • 9. Maps (hashes) > HSET "map1" "field1" "value1" true > HSET "map1" "field2" "value2" true > HEXISTS "map1" "field3" false > HGETALL "map1" {"field1":"value1","field2":"value2"}
  • 10. Transactions ● Commands to set/get values in maps, and add/remove values in lists and sets and sorted sets already take multiple arguments ● But transactions work across multiple keys ○ Atomicity ○ Fewer RPCs
  • 11. Transactions - writing > MULTI "OK" > HSET "map1" "field1" "value1" "QUEUED" > LPUSH "list1" 5 "QUEUED" > SADD "set1" "cats" "QUEUED" > EXEC [1,1,1]
  • 12. Transactions - reading > MULTI "OK" > HGETALL "map1" "QUEUED" > LRANGE "list1" 0 -1 "QUEUED" > SMEMBERS "set1" "QUEUED" > EXEC [["field1","value1"],["5"],["cats"]]
  • 13. Odds and ends ● Sorted sets ○ Allow you to implement a heap or priority queue ● Publish and subscribe ○ Like an event bus ○ Kind of out of place ○ Spun off from blocking pop on lists
  • 15. Creating plan identifiers > INCR "next_plan_id" 1 > INCR "next_plan_id" 2 > INCR "next_plan_id" 3 Do the same for user identifiers.
  • 16. Reading new messages Client sends plan_id and num_messages messages_key = "%s_messages" % plan_id new_messages = redis.lrange( messages_key, num_messages, -1) So if num_messages = 2 msg1 msg2 msg3 msg4 0 1 2 3 (-1)
  • 17. Reading one plan def get_plan(plan_id): pipeline = redis.pipeline() pipeline.hgetall("%s_hash" % plan_id) pipeline.smembers("%s_attendees" % plan_id) pipeline.lrange("%s_messages" % plan_id, 0, -1) plan_data, attendees, messages = pipeline.execute() return Plan( plan_id, plan_data, attendees, messages)
  • 18. Reading multiple plans filling the pipeline pipeline = redis.pipeline() for plan_id in plan_ids: pipeline_get_plan(plan_id, pipeline) def pipeline_get_plan(plan_id, pipeline) pipeline.hgetall("%s_hash" % plan_id) pipeline.smembers("%s_attendees" % plan_id) pipeline.lrange("%s_messages" % plan_id, 0, -1) hash1 attendees1 messages1 hash2 attendees2 messages2
  • 19. Reading multiple plans emptying the pipeline results = pipeline.execute() iterator = iter(results) plans = [get_pipelined_plan(plan_id, iterator) for plan_id in plan_ids] def get_pipelined_plan(plan_id, iterator): plan_data = next(iterator) attendees = next(iterator) messages = next(iterator) return Plan( plan_id, plan_data, attendees, messages)
  • 20. In the works ● 2.6 (soon) ○ Lua scripting on the server-side ○ Performance and replication improvements ○ Redis ASCII art logo at startup ● 3.0 ○ Clustering