SlideShare a Scribd company logo
redis 
überall 
Mariano Vallés! 
@zucaritask
redis 
/rədɪs/ 
@zucaritask
redis 
/rədɪs/ 
in memory key-value cache and store 
@zucaritask
redis 
/rədɪs/ 
in memory key-value cache and store 
Considered a data structure server since keys 
can contain strings, hashes, lists, sets … 
@zucaritask
First: Nested hashes 
In redis: 
[ ! 
] a hash has values 
[ ] those values can be hashes
First: Nested hashes 
In redis: 
! ✓ 
[ ] a hash has values 
[ ] those values can be hashes
First: Nested hashes 
In redis: 
✓ 
[ ] a hash has values 
[ ] those values can be hashes 
! 
✘
First: Nested hashes 
:001 
> 
$redis.hgetall(“levels:1234"). 
! 
{ 
easy_10: 
“{"progress":0,"goal":10,"started_at":1415278026,"finished_at":0}", 
easy_20: 
"{"progress":0,"goal":20,"started_at":1415278050,"finished_at":0}" 
}
First: Nested hashes 
:001 
> 
$redis.hgetall(“levels:1234"). 
! 
{ 
easy_10: 
“{"progress":0,"goal":10,"started_at":1415278026,"finished_at":0}", 
easy_20: 
"{"progress":0,"goal":20,"started_at":1415278050,"finished_at":0}" 
} 
:002 
> 
$redis.hgetall(“levels:1234").inject({}) 
do 
|result, 
(key, 
value)| 
result[key] 
= 
JSON.parse(value); 
result 
end 
=> 
{ 
easy_10: 
{progress: 
0, 
goal: 
10, 
started_at: 
1415278026, 
finished_at: 
0} 
easy_20: 
{progress: 
0, 
:goal: 
20, 
started_at: 
1415278050, 
finished_at: 
0} 
}
Redis hash 
:001 
> 
$redis.hgetall(“levels:1234"). 
! 
{ 
easy_10: 
“{"progress":0,"goal":10,"started_at":1415278026,"finished_at":0}", 
easy_20: 
"{"progress":0,"goal":20,"started_at":1415278050,"finished_at":0}" 
} 
:002 
>$redis.hgetall(“levels:1234").inject({}) 
do 
|result, 
(key, 
value)| 
result[key] 
= 
JSON.parse(value); 
result 
end 
=> 
{ 
easy_10: 
{:progress 
=> 
0, 
:goal 
=> 
10, 
started_at: 
1415278026, 
finished_at: 
0} 
easy_20: 
{:progress 
=> 
0, 
:goal 
=> 
20, 
started_at: 
1415278050, 
finished_at: 
0} 
}
Redis hash 
:001 
> 
$redis.hgetall(“levels:1234"). 
! 
{ 
! 
easy_10: 
“{"progress":0,"goal":10,"started_at":1415278026,"finished_at":0}", 
easy_20: 
"{"progress":0,"goal":20,"started_at":1415278050,"finished_at":0}" 
} 
deal with 
le crowd 
:002 
>$redis.hgetall(“levels:1234").inject({}) 
do 
|result, 
(key, 
value)| 
result[key] 
= 
JSON.parse(value); 
result 
end 
=> 
{ 
easy_10: 
{:progress 
=> 
0, 
:goal 
=> 
10, 
started_at: 
1415278026, 
finished_at: 
0} 
easy_20: 
{:progress 
=> 
0, 
:goal 
=> 
20, 
started_at: 
1415278050, 
finished_at: 
0} 
}
First: Nested hashes 
From: 
{ 
easy_10: 
“{"progress":0,"goal":10,"started_at":1415278026,"finished_at":easy_20: 
"{"progress":0,"goal":20,"started_at":1415278050,"finished_at":}
First: Nested hashes 
From: 
{ 
easy_10: 
“{"progress":0,"goal":10,"started_at":1415278026,"finished_at":easy_20: 
"{"progress":0,"goal":20,"started_at":1415278050,"finished_at":} 
To:
First: Nested hashes 
From: 
{ 
easy_10: 
“{"progress":0,"goal":10,"started_at":1415278026,"finished_at":easy_20: 
"{"progress":0,"goal":20,"started_at":1415278050,"finished_at":} 
To: 
{ 
easy_10: 
"0,10,1415278026,0", 
easy_20: 
"4,20,1415278050,0" 
}
First: Nested hashes 
{ 
easy_10: 
"0,10,1415278026,0", 
easy_20: 
"4,20,1415278050,0" 
} To:
First: Nested hashes 
goal 
{ 
easy_10: 
"0,10,1415278026,0", 
easy_20: 
"4,20,1415278050,0" 
} To: 
progress 
started_at 
finished at
In redis: 
[ ] hashes are memory efficient 
[ ] millions of hashes are memory 
efficient 
! 
Last: Avoiding hashes
Last: Avoiding hashes 
In redis: 
[ ] hashes are memory efficient 
[ ] millions of hashes are memory 
efficient 
! ✓
Last: Avoiding hashes 
In redis: 
✓ 
[ ] hashes are memory efficient 
[ ] millions of hashes are memory 
efficient 
! 
✘
Last: Avoiding hashes
Last: Avoiding hashes 
:01 
> 
$redis.hgetall(“counter:1234”)
Last: Avoiding hashes 
:01 
> 
$redis.hgetall(“counter:1234”) 
=> 
{ 
popup_shown: 
1, 
extra_life_given: 
0 
}
redis überall
the crowd 
has no mercy
the crowd 
has no mercy 
de a l w i th i t
Last: Avoiding hashes 
From: 
To: 
:01 
> 
$redis.hgetall(“counter:1234”) 
=> 
{ 
popup_shown: 
1, 
extra_life_given: 
0 
}
Last: Avoiding hashes 
From: 
To: 
:01 
> 
$redis.hgetall(“counter:1234”) 
=> 
{ 
popup_shown: 
1, 
extra_life_given: 
0 
} 
:01 
> 
$redis.get(“counter:1234”) 
=> 
"u0000u0001"
Last: Avoiding hashes 
From: 
To: 
:01 
> 
$redis.hgetall(“counter:1234”) 
=> 
{ 
popup_shown: 
1, 
extra_life_given: 
0 
} 
:01 
> 
$redis.get(“counter:1234”) 
=> 
"u0000u0001" 
A sequence of binary data
Last: Avoiding hashes 
From: 
To: 
:01 
> 
$redis.hgetall(“counter:1234”) 
=> 
{ 
popup_shown: 
1, 
extra_life_given: 
0 
} 
:01 
> 
$redis.get(“counter:1234”) 
=> 
"u0000u0001" 
A sequence of binary data 
Less memory usage FTW!
Last: Avoiding hashes 
class 
Counter 
! 
COUNTERS 
= 
%w[ 
VERSION 
popup_shown 
extra_life_given 
] 
! 
def 
set(key, 
value) 
$redis.setrange( 
user_id, 
COUNTERS.index(key), 
[value].pack("C*") 
) 
end 
! 
def 
[](key) 
char 
= 
$redis.getrange(user_id, 
index, 
index) 
char.unpack("C*").first.to_i 
end 
end
Last: Avoiding hashes 
class 
Counter 
! 
COUNTERS 
= 
%w[ 
VERSION 
popup_shown 
extra_life_given 
] 
! 
def 
set(key, 
value) 
$redis.setrange( 
user_id, 
COUNTERS.index(key), 
[value].pack("C*") 
) 
end 
! 
def 
[](key) 
char 
= 
$redis.getrange(user_id, 
index, 
index) 
char.unpack("C*").first.to_i 
end 
end
Last: Avoiding hashes 
class 
Counter 
! 
COUNTERS 
= 
%w[ 
VERSION 
popup_shown 
extra_life_given 
] 
! 
def 
set(key, 
value) 
$redis.setrange( 
user_id, 
COUNTERS.index(key), 
[value].pack("C*") 
) 
end 
! 
def 
[](key) 
char 
= 
$redis.getrange(user_id, 
index, 
index) 
char.unpack("C*").first.to_i 
end 
end
Last: Avoiding hashes 
class 
Counter 
! 
COUNTERS 
= 
%w[ 
VERSION 
popup_shown 
extra_life_given 
] 
! 
def 
set(key, 
value) 
$redis.setrange( 
user_id, 
COUNTERS.index(key), 
[value].pack("C*") 
) 
end 
! 
def 
set the value for a part of a string 
[](key) 
char 
= 
$redis.getrange(user_id, 
index, 
index) 
char.unpack("C*").first.to_i 
end 
end
Last: Avoiding hashes 
class 
Counter 
! 
COUNTERS 
= 
%w[ 
VERSION 
popup_shown 
extra_life_given 
] 
! 
def 
set(key, 
value) 
$redis.setrange( 
user_id, 
COUNTERS.index(key), 
[value].pack("C*") 
) 
end 
! 
def 
set the value for a part of a string 
starting in this position 
[](key) 
char 
= 
$redis.getrange(user_id, 
index, 
index) 
char.unpack("C*").first.to_i 
end 
end
Last: Avoiding hashes 
class 
Counter 
! 
COUNTERS 
= 
%w[ 
VERSION 
popup_shown 
extra_life_given 
] 
! 
def 
set(key, 
value) 
$redis.setrange( 
user_id, 
COUNTERS.index(key), 
[value].pack("C*") 
) 
end 
! 
def 
set the value for a part of a string 
starting in this position 
turn an integer into an 8-bit unsigned char 
[](key) 
char 
= 
$redis.getrange(user_id, 
index, 
index) 
char.unpack("C*").first.to_i 
end 
end
Last: Avoiding hashes
Last: Avoiding hashes 
:01 
> 
[0].pack(“C*”) 
=> 
"x00"
Last: Avoiding hashes 
:01 
> 
[0].pack(“C*”) 
=> 
"x00" 
:02 
> 
[256].pack(“C*”) 
=> 
"x00"
Last: Avoiding hashes 
Ac h t u n g , 8 bits ! 
:01 
> 
[0].pack(“C*”) 
=> 
"x00" 
:02 
> 
[256].pack(“C*”) 
=> 
"x00"
redis 
überall 
but 
@zucaritask 
use 
beware of the crowds

More Related Content

PPT
An Elephant of a Different Colour: Hack
PPTX
Coding Horrors
KEY
循環参照のはなし
KEY
Crazy things done on PHP
PDF
Ruby Language - A quick tour
PDF
Object Calisthenics Adapted for PHP
KEY
CS442 - Rogue: A Scala DSL for MongoDB
PDF
R57shell
An Elephant of a Different Colour: Hack
Coding Horrors
循環参照のはなし
Crazy things done on PHP
Ruby Language - A quick tour
Object Calisthenics Adapted for PHP
CS442 - Rogue: A Scala DSL for MongoDB
R57shell

What's hot (20)

PDF
Introduccion administracion
TXT
Gta v savegame
PDF
Aggregation Pipeline Power++: MongoDB 4.2 파이프 라인 쿼리, 업데이트 및 구체화된 뷰 소개 [MongoDB]
TXT
Codigos
KEY
Object Calisthenics Applied to PHP
TXT
Daily notes
PDF
You Got Async in my PHP!
PDF
Command Bus To Awesome Town
KEY
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
PDF
PHP for Adults: Clean Code and Object Calisthenics
PDF
Things I Believe Now That I'm Old
RTF
PDF
Devs for Leokz e 7Masters - WTF Oriented Programming
PDF
PDF
PHP tips and tricks
PDF
Everything About PowerShell
DOC
PDF
Models and Service Layers, Hemoglobin and Hobgoblins
PPTX
Groovy puzzlers jug-moscow-part 2
PPT
PHP and MySQL
Introduccion administracion
Gta v savegame
Aggregation Pipeline Power++: MongoDB 4.2 파이프 라인 쿼리, 업데이트 및 구체화된 뷰 소개 [MongoDB]
Codigos
Object Calisthenics Applied to PHP
Daily notes
You Got Async in my PHP!
Command Bus To Awesome Town
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
PHP for Adults: Clean Code and Object Calisthenics
Things I Believe Now That I'm Old
Devs for Leokz e 7Masters - WTF Oriented Programming
PHP tips and tricks
Everything About PowerShell
Models and Service Layers, Hemoglobin and Hobgoblins
Groovy puzzlers jug-moscow-part 2
PHP and MySQL
Ad

Viewers also liked (15)

PDF
Information systems and technologys in the economic by Klimushin_Orlov_Serenok
PPS
Формування системи законодавчого забезпечення охорони здоров'я в Україні
PPT
Transmedia storytelling
PDF
Серенок А.О. - Автореферат дисертаційної роботи "Механізми взаємодії органів ...
PPT
НОРМАТИВНО-ПРАВОВІ ЗАСАДИ ОБІГУ ЛІКАРСЬКИХ ЗАСОБІВ В УКРАЇНІ
PDF
How I earned 0.00009BTC - Lighning.io 2014
PDF
An Analysis of a Checkpointing Mechanism for a Stream Processing System
PPT
Introduction to the EDF Innovation Exchange
PPT
Green Portfolio Framework 7 09
PPT
Climate Change: Current Policy Landscape and Implications for U.S. Industry
PPT
Green Returns: Key Environmental Performance Areas
PPT
Green Returns: Why It Matters, What It Takes, How It Works
PPT
Green Returns - Case Studies
PDF
EcoValuScreen
PPT
20 Years of Partnerships. What's Next?
Information systems and technologys in the economic by Klimushin_Orlov_Serenok
Формування системи законодавчого забезпечення охорони здоров'я в Україні
Transmedia storytelling
Серенок А.О. - Автореферат дисертаційної роботи "Механізми взаємодії органів ...
НОРМАТИВНО-ПРАВОВІ ЗАСАДИ ОБІГУ ЛІКАРСЬКИХ ЗАСОБІВ В УКРАЇНІ
How I earned 0.00009BTC - Lighning.io 2014
An Analysis of a Checkpointing Mechanism for a Stream Processing System
Introduction to the EDF Innovation Exchange
Green Portfolio Framework 7 09
Climate Change: Current Policy Landscape and Implications for U.S. Industry
Green Returns: Key Environmental Performance Areas
Green Returns: Why It Matters, What It Takes, How It Works
Green Returns - Case Studies
EcoValuScreen
20 Years of Partnerships. What's Next?
Ad

Similar to redis überall (20)

PDF
Kicking ass with redis
PDF
Redis — The AK-47 of Post-relational Databases
PDF
Introduction to Redis
PDF
PDF
Redispresentation apac2012
PPTX
05 integrate redis
PDF
Introduction to Redis
PDF
Redis basics
PPTX
KEY
PDF
Redis Cheat Sheet
PPTX
Probabilistic Data Structures (Edmonton Data Science Meetup, March 2018)
PDF
Amir Salihefendic: Redis - the hacker's database
PDF
Serializing Ruby Objects in Redis
PDF
Redis Workshop on Data Structures, Commands, Administration
PDF
Introduction to Redis
PPTX
Redis Use Patterns (DevconTLV June 2014)
PDF
Paris Redis Meetup Introduction
ODP
An Introduction to REDIS NoSQL database
PDF
Redis - Usability and Use Cases
Kicking ass with redis
Redis — The AK-47 of Post-relational Databases
Introduction to Redis
Redispresentation apac2012
05 integrate redis
Introduction to Redis
Redis basics
Redis Cheat Sheet
Probabilistic Data Structures (Edmonton Data Science Meetup, March 2018)
Amir Salihefendic: Redis - the hacker's database
Serializing Ruby Objects in Redis
Redis Workshop on Data Structures, Commands, Administration
Introduction to Redis
Redis Use Patterns (DevconTLV June 2014)
Paris Redis Meetup Introduction
An Introduction to REDIS NoSQL database
Redis - Usability and Use Cases

Recently uploaded (20)

PPTX
The various Industrial Revolutions .pptx
PDF
Developing a website for English-speaking practice to English as a foreign la...
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PPTX
Benefits of Physical activity for teenagers.pptx
PDF
sustainability-14-14877-v2.pddhzftheheeeee
PDF
NewMind AI Weekly Chronicles – August ’25 Week III
PDF
Architecture types and enterprise applications.pdf
PDF
Hybrid model detection and classification of lung cancer
PDF
A novel scalable deep ensemble learning framework for big data classification...
PPTX
Web Crawler for Trend Tracking Gen Z Insights.pptx
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
PDF
Taming the Chaos: How to Turn Unstructured Data into Decisions
PDF
STKI Israel Market Study 2025 version august
PDF
DP Operators-handbook-extract for the Mautical Institute
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
The various Industrial Revolutions .pptx
Developing a website for English-speaking practice to English as a foreign la...
Assigned Numbers - 2025 - Bluetooth® Document
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
Group 1 Presentation -Planning and Decision Making .pptx
Benefits of Physical activity for teenagers.pptx
sustainability-14-14877-v2.pddhzftheheeeee
NewMind AI Weekly Chronicles – August ’25 Week III
Architecture types and enterprise applications.pdf
Hybrid model detection and classification of lung cancer
A novel scalable deep ensemble learning framework for big data classification...
Web Crawler for Trend Tracking Gen Z Insights.pptx
A comparative study of natural language inference in Swahili using monolingua...
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
Taming the Chaos: How to Turn Unstructured Data into Decisions
STKI Israel Market Study 2025 version august
DP Operators-handbook-extract for the Mautical Institute
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
Final SEM Unit 1 for mit wpu at pune .pptx

redis überall

  • 1. redis überall Mariano Vallés! @zucaritask
  • 3. redis /rədɪs/ in memory key-value cache and store @zucaritask
  • 4. redis /rədɪs/ in memory key-value cache and store Considered a data structure server since keys can contain strings, hashes, lists, sets … @zucaritask
  • 5. First: Nested hashes In redis: [ ! ] a hash has values [ ] those values can be hashes
  • 6. First: Nested hashes In redis: ! ✓ [ ] a hash has values [ ] those values can be hashes
  • 7. First: Nested hashes In redis: ✓ [ ] a hash has values [ ] those values can be hashes ! ✘
  • 8. First: Nested hashes :001 > $redis.hgetall(“levels:1234"). ! { easy_10: “{"progress":0,"goal":10,"started_at":1415278026,"finished_at":0}", easy_20: "{"progress":0,"goal":20,"started_at":1415278050,"finished_at":0}" }
  • 9. First: Nested hashes :001 > $redis.hgetall(“levels:1234"). ! { easy_10: “{"progress":0,"goal":10,"started_at":1415278026,"finished_at":0}", easy_20: "{"progress":0,"goal":20,"started_at":1415278050,"finished_at":0}" } :002 > $redis.hgetall(“levels:1234").inject({}) do |result, (key, value)| result[key] = JSON.parse(value); result end => { easy_10: {progress: 0, goal: 10, started_at: 1415278026, finished_at: 0} easy_20: {progress: 0, :goal: 20, started_at: 1415278050, finished_at: 0} }
  • 10. Redis hash :001 > $redis.hgetall(“levels:1234"). ! { easy_10: “{"progress":0,"goal":10,"started_at":1415278026,"finished_at":0}", easy_20: "{"progress":0,"goal":20,"started_at":1415278050,"finished_at":0}" } :002 >$redis.hgetall(“levels:1234").inject({}) do |result, (key, value)| result[key] = JSON.parse(value); result end => { easy_10: {:progress => 0, :goal => 10, started_at: 1415278026, finished_at: 0} easy_20: {:progress => 0, :goal => 20, started_at: 1415278050, finished_at: 0} }
  • 11. Redis hash :001 > $redis.hgetall(“levels:1234"). ! { ! easy_10: “{"progress":0,"goal":10,"started_at":1415278026,"finished_at":0}", easy_20: "{"progress":0,"goal":20,"started_at":1415278050,"finished_at":0}" } deal with le crowd :002 >$redis.hgetall(“levels:1234").inject({}) do |result, (key, value)| result[key] = JSON.parse(value); result end => { easy_10: {:progress => 0, :goal => 10, started_at: 1415278026, finished_at: 0} easy_20: {:progress => 0, :goal => 20, started_at: 1415278050, finished_at: 0} }
  • 12. First: Nested hashes From: { easy_10: “{"progress":0,"goal":10,"started_at":1415278026,"finished_at":easy_20: "{"progress":0,"goal":20,"started_at":1415278050,"finished_at":}
  • 13. First: Nested hashes From: { easy_10: “{"progress":0,"goal":10,"started_at":1415278026,"finished_at":easy_20: "{"progress":0,"goal":20,"started_at":1415278050,"finished_at":} To:
  • 14. First: Nested hashes From: { easy_10: “{"progress":0,"goal":10,"started_at":1415278026,"finished_at":easy_20: "{"progress":0,"goal":20,"started_at":1415278050,"finished_at":} To: { easy_10: "0,10,1415278026,0", easy_20: "4,20,1415278050,0" }
  • 15. First: Nested hashes { easy_10: "0,10,1415278026,0", easy_20: "4,20,1415278050,0" } To:
  • 16. First: Nested hashes goal { easy_10: "0,10,1415278026,0", easy_20: "4,20,1415278050,0" } To: progress started_at finished at
  • 17. In redis: [ ] hashes are memory efficient [ ] millions of hashes are memory efficient ! Last: Avoiding hashes
  • 18. Last: Avoiding hashes In redis: [ ] hashes are memory efficient [ ] millions of hashes are memory efficient ! ✓
  • 19. Last: Avoiding hashes In redis: ✓ [ ] hashes are memory efficient [ ] millions of hashes are memory efficient ! ✘
  • 21. Last: Avoiding hashes :01 > $redis.hgetall(“counter:1234”)
  • 22. Last: Avoiding hashes :01 > $redis.hgetall(“counter:1234”) => { popup_shown: 1, extra_life_given: 0 }
  • 24. the crowd has no mercy
  • 25. the crowd has no mercy de a l w i th i t
  • 26. Last: Avoiding hashes From: To: :01 > $redis.hgetall(“counter:1234”) => { popup_shown: 1, extra_life_given: 0 }
  • 27. Last: Avoiding hashes From: To: :01 > $redis.hgetall(“counter:1234”) => { popup_shown: 1, extra_life_given: 0 } :01 > $redis.get(“counter:1234”) => "u0000u0001"
  • 28. Last: Avoiding hashes From: To: :01 > $redis.hgetall(“counter:1234”) => { popup_shown: 1, extra_life_given: 0 } :01 > $redis.get(“counter:1234”) => "u0000u0001" A sequence of binary data
  • 29. Last: Avoiding hashes From: To: :01 > $redis.hgetall(“counter:1234”) => { popup_shown: 1, extra_life_given: 0 } :01 > $redis.get(“counter:1234”) => "u0000u0001" A sequence of binary data Less memory usage FTW!
  • 30. Last: Avoiding hashes class Counter ! COUNTERS = %w[ VERSION popup_shown extra_life_given ] ! def set(key, value) $redis.setrange( user_id, COUNTERS.index(key), [value].pack("C*") ) end ! def [](key) char = $redis.getrange(user_id, index, index) char.unpack("C*").first.to_i end end
  • 31. Last: Avoiding hashes class Counter ! COUNTERS = %w[ VERSION popup_shown extra_life_given ] ! def set(key, value) $redis.setrange( user_id, COUNTERS.index(key), [value].pack("C*") ) end ! def [](key) char = $redis.getrange(user_id, index, index) char.unpack("C*").first.to_i end end
  • 32. Last: Avoiding hashes class Counter ! COUNTERS = %w[ VERSION popup_shown extra_life_given ] ! def set(key, value) $redis.setrange( user_id, COUNTERS.index(key), [value].pack("C*") ) end ! def [](key) char = $redis.getrange(user_id, index, index) char.unpack("C*").first.to_i end end
  • 33. Last: Avoiding hashes class Counter ! COUNTERS = %w[ VERSION popup_shown extra_life_given ] ! def set(key, value) $redis.setrange( user_id, COUNTERS.index(key), [value].pack("C*") ) end ! def set the value for a part of a string [](key) char = $redis.getrange(user_id, index, index) char.unpack("C*").first.to_i end end
  • 34. Last: Avoiding hashes class Counter ! COUNTERS = %w[ VERSION popup_shown extra_life_given ] ! def set(key, value) $redis.setrange( user_id, COUNTERS.index(key), [value].pack("C*") ) end ! def set the value for a part of a string starting in this position [](key) char = $redis.getrange(user_id, index, index) char.unpack("C*").first.to_i end end
  • 35. Last: Avoiding hashes class Counter ! COUNTERS = %w[ VERSION popup_shown extra_life_given ] ! def set(key, value) $redis.setrange( user_id, COUNTERS.index(key), [value].pack("C*") ) end ! def set the value for a part of a string starting in this position turn an integer into an 8-bit unsigned char [](key) char = $redis.getrange(user_id, index, index) char.unpack("C*").first.to_i end end
  • 37. Last: Avoiding hashes :01 > [0].pack(“C*”) => "x00"
  • 38. Last: Avoiding hashes :01 > [0].pack(“C*”) => "x00" :02 > [256].pack(“C*”) => "x00"
  • 39. Last: Avoiding hashes Ac h t u n g , 8 bits ! :01 > [0].pack(“C*”) => "x00" :02 > [256].pack(“C*”) => "x00"
  • 40. redis überall but @zucaritask use beware of the crowds