SlideShare uma empresa Scribd logo
1 de 91
Baixar para ler offline
Redis Begins
charsyam@naver.com
Redis?
Redis?
Redis is an open source.
http://redis.io
Redis?
Redis is an open source.
BSD licensed.
http://redis.io
Redis?
Redis is an open source.
BSD licensed.
advanced key-value store.
http://redis.io
Redis?
Redis.io
http://redis.io
Why Redis?
Why Redis?
Simple.
Performance.
Build
$ make
But
You can meet some errors in Linux
Solution:
$> make distclean; make;
Why?
Redis saves settings to .make-* files
And they disturb normal building.
Argenda
Single Thread.
Collections.
Persistent.
Replication.
The one thing
you should know.
Redis is
Single Threaded!
Single Thread
Means!
Don’t execute
long task.
Example:
Keys command
Flushall/flushdb command
O(n)
Keys *
di = dictGetSafeIterator(c->db->dict);
allkeys = (pattern[0] == '*' && pattern[1] == '0');
while((de = dictNext(di)) != NULL) {
……
stringmatchlen(pattern,plen,key,sdslen(key),0)
}
FlushAll
Cache Item Count Time
Memcache 1,000,000 1~2ms
Redis 1,000,000 1000ms(1 second)
Memcache’s flush
is faster than
Redis’s flush.
Memcache’s flush
is faster than
Redis’s flush?
FlushAll-Redis
for (i = 0; i < ht->size && ht->used > 0; i++) {
dictEntry *he, *nextHe;
if ((he = ht->table[i]) == NULL) continue;
while(he) {
nextHe = he->next;
dictFreeKey(d, he);
dictFreeVal(d, he);
zfree(he);
ht->used--;
he = nextHe;
}
}
FlushAll-Memcache
if (exptime > 0)
settings.oldest_live = realtime(exptime) - 1;
else /* exptime == 0 */
settings.oldest_live = current_time - 1;
FlushAll-Memcache
if (settings.oldest_live != 0 &&
settings.oldest_live <= current_time &&
it->time <= settings.oldest_live) {
do_item_unlink(it, hv);
do_item_remove(it);
it = NULL;
}
Argenda
Single Thread.
Collections.
Persistent.
Replication.
Collections
Memcached supports just K-V
List
Set
Sorted Set
Hash
Key:Value
$> set key value
$> get key
Key:Value
sql> insert into userinfo (name,
email) values(‘charsyam’,
‘test@abc.com’);
Key:Value
$> set id:name “charsyam”
$> set id:email test@abc.com
$> mget id:name id:email
1) “charsyam”
2) test@abc.com”
List
$> rpush listname a --- (a)
$> rpush listname b --- (a, b)
$> lpush listname c --- (c, a, b)
$> rpop listname(or lpop listname)
List - when
When you need job queue or stack.
Set
$> sadd setname id1
$> sadd setname id2
$> smember setname
1) “id2”
2) “id1”
set - when
When you need follwers ids or
group members id
Sorted Set
$> zadd zsetname 1 “one”
$> zadd zsetname 2 “two”
$> zadd zsetname 3 “three”
Sorted Set
$> zrange zsetname 0 -1
1) “one”
2) “two”
3) “three”
zset - when
When you need ranking
Sorted Set
$> zrange zsetname 1 3
1) “two”
2) “three”
Hash
sql> insert into userinfo (name,
email) values(‘charsyam’,
‘test@abc.com’);
Hash$> hmset id name “charsyam”
email test@abc.com
Hash$> hgetall
1) “name”
2) “charsyam”
3) “email”
4) “test@abc.com”
Hash$> hset id email abc@abc.com
$> hgetall
1) “name”
2) “charsyam”
3) “email”
4) “abc@abc.com”
Remember!!!!!
The one thing
you should know.
Redis is
Single Threaded!
Don’t insert too
many items into
collections.
Delete collections
Item Count Time
list 1,000,000 1000ms(1 second)
set
Sorted set
hash
Argenda
Single Thread.
Collections.
Persistent.
Replication.
Redis can store
its memory
snapshot.
RDB
RDB is not
Relation DBMS.
RDB is redis
snapshot name.
Fork()
RDB - BAD
• Bad Performance in Large memory.
• Twice memory problem.
• Denying write problem when storing
RDB fails.
• If you just want Cache. Turn off RDB
RDB – Large Memory
• Performance is relevant to Memory
Size.
17.1 GB
34.2 GB
68.4 GB
117 GB
RDB – Twice Memory
• fork() and COW(copy on write) Issue
–In Write Heavy System:
RDB – Twice Memory
RDB – Twice Memory
RDB – Twice Memory
Real Case Study
• Background
–Can’t write to Redis Server
–Sentinel doesn’t find Server’s failure.
Real Case Study
• Reason
–If redis fails to save RDB, Redis basically
denies write operations from client.
–“MISCONF Redis is configured to save RDB
snapshots, but is currently not able to
persist on disk. Commands that may modify
the data set are disabled. Please check Redis
logs for details about the error.”
Real Case Study
• Reason
if (server.stop_writes_on_bgsave_err &&
server.saveparamslen > 0
&& server.lastbgsave_status == REDIS_ERR &&
c->cmd->flags & REDIS_CMD_WRITE)
{
flagTransaction(c);
addReply(c, shared.bgsaveerr);
return REDIS_OK;
}
Real Case Study
• Solution #1
• Solution #2
config set stop-writes-on-bgsave-error no
Turn off RDB Setting
2.6.12 부터 conf 에서 stop-writes-on-bgsave-error
설정이 가능해짐.
AOF
AOF is append
only file.
AOF memorizes
all requests.
AOF*3rn$3rnsetrn$1rnA
rn$3rn123rn*3rn$3rn
setrn$1rnBrn$3rn123
rn*3rn$3rnsetrn$1r
nCrn$3rn123rn
AOF*3
$3
Set
$1
A
……
AOF Rewrite
When size of AOF grows than redis
rewrite memory state to AOF.
Argenda
Single Thread.
Collections.
Persistent.
Replication.
Redis support
master/slave
replication
Replication
•Support Chained Replication
Master 1st Slave 2nd Slave
1st slave is master of 2nd slave
Replication
Master Slave
replicationCron
Health check
Replication
Master Slave
replicationCron
Health check
Replication
Master Slave
replicationCron
When master reruns, Resync with Master
Mistake: Replication
Master Slave
replicationCron
Slave will has no data after resyncing
If master has no data.
Initial Replication Step
Replication
Don’t forget
“slave of no one”
Sentinel
Sentinel
• Sentinel is Failover Solution for Redis.
Master Slave
Sentinel
Sentinel periodically checks Redis Master
Sentinel
Master Slave
Sentinel
Send “slaveof no one” to slave node
Sentinel
Master Slave
Sentinel
Notify to client about changing master
Client
Sentinel
redis 127.0.0.1:2003> psubscribe *
Reading messages... (press Ctrl-C to quit)
1) "pmessage"
2) "*"
3) "+switch-master"
4) "resque 127.0.0.1 1999 127.0.0.1 2002"
Sentinel
• Sentinel will connect correct master
even if you set slave’s ip in conf
Master Slave
Sentinel
Slave’s ip in sentinel.conf
Sentinel
• INFO
# Replication
role:slave
master_host:127.0.0.1
master_port:6379
……
Sentinel
• Reconnect to correct master using
master_host and master_port.
Master Slave
Sentinel
Reconnect to master of slave.
Sentinel.conf
port 26379
sentinel monitor mymaster 127.0.0.1 6379 1
sentinel down-after-milliseconds mymaster 30000
sentinel can-failover mymaster yes
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 900000
Wrap Up
Redis is
Single Threaded!
Q & A
Thank you!

Mais conteúdo relacionado

Mais procurados

Redis — The AK-47 of Post-relational Databases
Redis — The AK-47 of Post-relational DatabasesRedis — The AK-47 of Post-relational Databases
Redis — The AK-47 of Post-relational Databases
Karel Minarik
 
Kicking ass with redis
Kicking ass with redisKicking ass with redis
Kicking ass with redis
Dvir Volk
 
Replication and replica sets
Replication and replica setsReplication and replica sets
Replication and replica sets
Randall Hunt
 
WebClusters, Redis
WebClusters, RedisWebClusters, Redis
WebClusters, Redis
Filip Tepper
 
Facebook的缓存系统
Facebook的缓存系统Facebook的缓存系统
Facebook的缓存系统
yiditushe
 

Mais procurados (20)

Redis modules 101
Redis modules 101Redis modules 101
Redis modules 101
 
Redis — The AK-47 of Post-relational Databases
Redis — The AK-47 of Post-relational DatabasesRedis — The AK-47 of Post-relational Databases
Redis — The AK-47 of Post-relational Databases
 
Redis SoCraTes 2014
Redis SoCraTes 2014Redis SoCraTes 2014
Redis SoCraTes 2014
 
Building Scalable, Distributed Job Queues with Redis and Redis::Client
Building Scalable, Distributed Job Queues with Redis and Redis::ClientBuilding Scalable, Distributed Job Queues with Redis and Redis::Client
Building Scalable, Distributed Job Queues with Redis and Redis::Client
 
Introduction to redis - version 2
Introduction to redis - version 2Introduction to redis - version 2
Introduction to redis - version 2
 
Kicking ass with redis
Kicking ass with redisKicking ass with redis
Kicking ass with redis
 
Redis in Practice
Redis in PracticeRedis in Practice
Redis in Practice
 
Troubleshooting redis
Troubleshooting redisTroubleshooting redis
Troubleshooting redis
 
Perl at SkyCon'12
Perl at SkyCon'12Perl at SkyCon'12
Perl at SkyCon'12
 
MongoDB: How it Works
MongoDB: How it WorksMongoDB: How it Works
MongoDB: How it Works
 
RestMQ - HTTP/Redis based Message Queue
RestMQ - HTTP/Redis based Message QueueRestMQ - HTTP/Redis based Message Queue
RestMQ - HTTP/Redis based Message Queue
 
Redis in Practice: Scenarios, Performance and Practice with PHP
Redis in Practice: Scenarios, Performance and Practice with PHPRedis in Practice: Scenarios, Performance and Practice with PHP
Redis in Practice: Scenarios, Performance and Practice with PHP
 
Replication and replica sets
Replication and replica setsReplication and replica sets
Replication and replica sets
 
WebClusters, Redis
WebClusters, RedisWebClusters, Redis
WebClusters, Redis
 
Serializing Ruby Objects in Redis
Serializing Ruby Objects in RedisSerializing Ruby Objects in Redis
Serializing Ruby Objects in Redis
 
Redis for the Everyday Developer
Redis for the Everyday DeveloperRedis for the Everyday Developer
Redis for the Everyday Developer
 
Perl Memory Use 201207 (OUTDATED, see 201209 )
Perl Memory Use 201207 (OUTDATED, see 201209 )Perl Memory Use 201207 (OUTDATED, see 201209 )
Perl Memory Use 201207 (OUTDATED, see 201209 )
 
Paris Redis Meetup Introduction
Paris Redis Meetup IntroductionParis Redis Meetup Introduction
Paris Redis Meetup Introduction
 
Facebook的缓存系统
Facebook的缓存系统Facebook的缓存系统
Facebook的缓存系统
 
Perl Memory Use 201209
Perl Memory Use 201209Perl Memory Use 201209
Perl Memory Use 201209
 

Destaque (6)

Redis edu 4
Redis edu 4Redis edu 4
Redis edu 4
 
Redis edu 5
Redis edu 5Redis edu 5
Redis edu 5
 
Redis edu 1
Redis edu 1Redis edu 1
Redis edu 1
 
Redis edu 2
Redis edu 2Redis edu 2
Redis edu 2
 
Redis edu 3
Redis edu 3Redis edu 3
Redis edu 3
 
Webservice cache strategy
Webservice cache strategyWebservice cache strategy
Webservice cache strategy
 

Semelhante a Redis begins

From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)
Night Sailer
 
Php tips-and-tricks4128
Php tips-and-tricks4128Php tips-and-tricks4128
Php tips-and-tricks4128
PrinceGuru MS
 
Debugger Principle Overview & GDB Tricks
Debugger Principle Overview & GDB TricksDebugger Principle Overview & GDB Tricks
Debugger Principle Overview & GDB Tricks
dutor
 

Semelhante a Redis begins (20)

Working with databases in Perl
Working with databases in PerlWorking with databases in Perl
Working with databases in Perl
 
Mongodb workshop
Mongodb workshopMongodb workshop
Mongodb workshop
 
mongodb-introduction
mongodb-introductionmongodb-introduction
mongodb-introduction
 
DataMapper
DataMapperDataMapper
DataMapper
 
Apache Spark - Basics of RDD | Big Data Hadoop Spark Tutorial | CloudxLab
Apache Spark - Basics of RDD | Big Data Hadoop Spark Tutorial | CloudxLabApache Spark - Basics of RDD | Big Data Hadoop Spark Tutorial | CloudxLab
Apache Spark - Basics of RDD | Big Data Hadoop Spark Tutorial | CloudxLab
 
SequoiaDB Distributed Relational Database
SequoiaDB Distributed Relational DatabaseSequoiaDB Distributed Relational Database
SequoiaDB Distributed Relational Database
 
From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)
 
veracruz
veracruzveracruz
veracruz
 
veracruz
veracruzveracruz
veracruz
 
veracruz
veracruzveracruz
veracruz
 
veracruz
veracruzveracruz
veracruz
 
Php tips-and-tricks4128
Php tips-and-tricks4128Php tips-and-tricks4128
Php tips-and-tricks4128
 
Introduction to Active Record at MySQL Conference 2007
Introduction to Active Record at MySQL Conference 2007Introduction to Active Record at MySQL Conference 2007
Introduction to Active Record at MySQL Conference 2007
 
PHP tips and tricks
PHP tips and tricks PHP tips and tricks
PHP tips and tricks
 
Simple Ways To Be A Better Programmer (OSCON 2007)
Simple Ways To Be A Better Programmer (OSCON 2007)Simple Ways To Be A Better Programmer (OSCON 2007)
Simple Ways To Be A Better Programmer (OSCON 2007)
 
BADCamp 2008 DB Sync
BADCamp 2008 DB SyncBADCamp 2008 DB Sync
BADCamp 2008 DB Sync
 
Scaling php applications with redis
Scaling php applications with redisScaling php applications with redis
Scaling php applications with redis
 
Redispresentation apac2012
Redispresentation apac2012Redispresentation apac2012
Redispresentation apac2012
 
Scaling Databases with DBIx::Router
Scaling Databases with DBIx::RouterScaling Databases with DBIx::Router
Scaling Databases with DBIx::Router
 
Debugger Principle Overview & GDB Tricks
Debugger Principle Overview & GDB TricksDebugger Principle Overview & GDB Tricks
Debugger Principle Overview & GDB Tricks
 

Mais de DaeMyung Kang

Mais de DaeMyung Kang (20)

Count min sketch
Count min sketchCount min sketch
Count min sketch
 
Redis
RedisRedis
Redis
 
Ansible
AnsibleAnsible
Ansible
 
Why GUID is needed
Why GUID is neededWhy GUID is needed
Why GUID is needed
 
How to use redis well
How to use redis wellHow to use redis well
How to use redis well
 
The easiest consistent hashing
The easiest consistent hashingThe easiest consistent hashing
The easiest consistent hashing
 
How to name a cache key
How to name a cache keyHow to name a cache key
How to name a cache key
 
Integration between Filebeat and logstash
Integration between Filebeat and logstash Integration between Filebeat and logstash
Integration between Filebeat and logstash
 
How to build massive service for advance
How to build massive service for advanceHow to build massive service for advance
How to build massive service for advance
 
Massive service basic
Massive service basicMassive service basic
Massive service basic
 
Data Engineering 101
Data Engineering 101Data Engineering 101
Data Engineering 101
 
How To Become Better Engineer
How To Become Better EngineerHow To Become Better Engineer
How To Become Better Engineer
 
Kafka timestamp offset_final
Kafka timestamp offset_finalKafka timestamp offset_final
Kafka timestamp offset_final
 
Kafka timestamp offset
Kafka timestamp offsetKafka timestamp offset
Kafka timestamp offset
 
Data pipeline and data lake
Data pipeline and data lakeData pipeline and data lake
Data pipeline and data lake
 
Redis acl
Redis aclRedis acl
Redis acl
 
Coffee store
Coffee storeCoffee store
Coffee store
 
Scalable webservice
Scalable webserviceScalable webservice
Scalable webservice
 
Number system
Number systemNumber system
Number system
 
webservice scaling for newbie
webservice scaling for newbiewebservice scaling for newbie
webservice scaling for newbie
 

Último

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Último (20)

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
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...
 
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
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
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
 
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
 
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...
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
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
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
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...
 
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
 
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
 
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
 
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...
 
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
 

Redis begins