SlideShare a Scribd company logo
Redis  深入浅出 Http://www.hoterran.info Http://Weibo.com/hoterran
agenda use feature architecture admin replication presistence misc
use Download  http://redis.googlecode.com/files/redis-2.2.11.tar.gz install Redis-server  > /dev/null &  Redis-cli http://try.redis-db.com/
use set/get lpush/lrem/rpop/ hset/hgetall sadd/srem multi/discard/exec
feature Advanced key value store like memcachedb single threaded, no lock Event demultiplexer, no use libevent 2w lines writen in c without 3 rd  library faster
feature Difference with memached Data structure No only memcached k-v Linklist k-v1->v2->v3->v4... Set k - (v1,v2,v3,v4) Hash k – (k1 -v1, k2 – v2, k3 – v3) Need design a little Replication Presistence not support LRU Need multi instance use multi core
feature Difference with MySQL Not Heap table store Not need index, so not execute plan Not compute statistic No sql No join Capacity size limited by cache a little design before dev High rw
architecture
architecture
admin Redis.conf parameter intro Replication intro Persistence intro
replication procedure map Dual master mode? Master slave slave mode defects Without resume broken transfer 可以架两级 slave 解决 ? Without lag(slave position)
replication
replication Case replication switch old redis version running on, say, redis:6379. Install and start a new redis on redis:6380 with a different dump file location. Execute SLAVE OF redis 6379 against redis:6380. Wait for first SYNC to complete. echo "enable server redis/redis-6380" | socat stdio unix-connect:/var/run/haproxy/admin.sock echo "disable server redis/redis-6379" | socat stdio unix-connect:/var/run/haproxy/admin.sock Execute SLAVE OF no one on redis:6380. Execute SHUTDOWN on redis:6379. Assuming that you've got a HAProxy config looking something like listen redis :6378 server redis-6379 localhost:6379 check weight 256 server redis-6380 localhost:6380 check disabled
persistence Snapshot Fork process, loop hash table, save on file dump.rdb Yes!!! sequential write Write dump.rdb need O_DIRECT? Aof Like binlog, for recover after crash appendfsync Aof file is big use bgrewriteaof
Login user Design a login user system Heap table userid  login_times  last_login_time 1  5  2011-1-1 2  1  2011-1-2 3  2  2011-1-3 Last login man? Max login man?
Login user data Set userid:1:login_times 5 Set userid:2:login_times 1 Set userid:3:login_times 2 Set userid:1:last_login 2011-1-1 Set userid:2:last_login 2011-1-2 Set userid:3:last_login 2011-1-3 Last login  lpush user_last_login 1 lpush  user_last_login 2 lpush user_last_login 3 ltrim user_last_login 0 1
Login user Max login man zadd user:login_times 5 1 zadd user:login_times 1 2 zadd user:login_times 2 3 zcard user:login_times zrangebyscore user:login_times 3 +inf withscores Column store data?
tag Relational is suitable? book id  book  author 1  <<Diving into Python>>  gun 2  <<Ruby on rail>>  japan Tag Tagname id Web 1 Web  2 Python  2 Sql select id from tag t1, tag t2 where t1.tagname = 'web' and t2.tagname = 'python' and t1.id = t2.id
tag Kv design set book:1 ”diving into python” Set book:2 ”ruby on rail” sadd tag:web 2 sadd tag:web 1 sadd tag:python 1 sinter 'tag:web' 'tag:python' sunion tag:web 'tag:python' sdiff tag:web 'tag:python' 反思?
Sina weibo Recent record List, Lrange( 关注的人列表、粉丝列表、 feeds 列表 ) Set Sadd|, sdiff, sinter  ( 我的好友,我可能感兴趣的人 ) Score Zadd, zset(feeds 排名 ) Hash Hincrby, hgetall( 用户资料,关注数,粉丝数,微博数  ) Delete history data expire
Sina weibo 我关注的人 sadd user:hoterran:follows user:foolishceo sadd user:hoterran:follows user:logzgh sadd user:hoterran:follows user:sqlrush smembers user:hoterran:follows 英杰关注的人 sadd user:sqlrush:follows user:logzgh sadd user:sqlrush:follows user:hoterran
Sina weibo 我们共通关注的人 sinter user:sqlrush:follows user:hoterran:follows 我的粉丝 sadd user:logzgh:follows user:hoterran sadd user:hoterran.follower user:logzgh sadd user:hoterran.follower user:sqlrush smembers user:hoterran:follower
Sina weibo 我的好友 sinter user:hoterran:follows user:hoterran:follower 我们都关注的人 sinter user:sqlrush:follows user:hoterran:follows
Sina weibo 可能感兴趣的的人 sadd user:sqlrush:follows user:free_yz sdiff user:sqlrush:follows user:hoterran:follows 我关注的人数,我的粉丝数,我的 Hset hoterran:profile follows 1 Hset hoterran:profile follower 2 Hset hoterran:profile blog 3 Hgetall hoterran:profile Hincrby hoterran:profile blog 1
Suitable scene 轻量级的高性能消息队列服务 生产者消费者 Producer lpush Consumer blpop  Redis 的主要缺点是数据库容量受到物理内存的限制,不能用作海量数据的高性能读写,并且它没有原生的可扩展机制,不具有 scale (可扩展)能力,要依赖客户端来实现分布式读写,因此 Redis 适合的场景主要局限在较小数据量的高性能操作和运算上。
summary Defects Failover Replication Dba level Memory limit size Advantage High qps Data structure
qa Replace aliWangwang k-v(blob) Can satisfy Online Log requirement?

More Related Content

PPT
Qt native built for raspberry zero
SoheilSabzevari2
 
PDF
Performance comparison of Distributed File Systems on 1Gbit networks
Marian Marinov
 
PPTX
Big data and hadoop training - Session 5
hkbhadraa
 
PDF
OSBConf 2015 | Backups with rdiff backup and rsnapshot by christoph mitasch &...
NETWAYS
 
PDF
Oracle cluster installation with grid and nfs
Chanaka Lasantha
 
PDF
Small, Simple, and Secure: Alpine Linux under the Microscope
Docker, Inc.
 
PDF
Oracle cluster installation with grid and iscsi
Chanaka Lasantha
 
PDF
Anton Moldovan "Building an efficient replication system for thousands of ter...
Fwdays
 
Qt native built for raspberry zero
SoheilSabzevari2
 
Performance comparison of Distributed File Systems on 1Gbit networks
Marian Marinov
 
Big data and hadoop training - Session 5
hkbhadraa
 
OSBConf 2015 | Backups with rdiff backup and rsnapshot by christoph mitasch &...
NETWAYS
 
Oracle cluster installation with grid and nfs
Chanaka Lasantha
 
Small, Simple, and Secure: Alpine Linux under the Microscope
Docker, Inc.
 
Oracle cluster installation with grid and iscsi
Chanaka Lasantha
 
Anton Moldovan "Building an efficient replication system for thousands of ter...
Fwdays
 

What's hot (20)

PDF
Как понять, что происходит на сервере? / Александр Крижановский (NatSys Lab.,...
Ontico
 
DOCX
Nginx 0.8.x 安装手册
Yiwei Ma
 
PDF
Advanced backup methods (Postgres@CERN)
Anastasia Lubennikova
 
PPTX
Cpu高效编程技术
Feng Yu
 
PPT
Php perf
ericjonah
 
PPSX
Python, Keras, Hello world, Installation, Binary Classification
Hamed Shah-Hosseini
 
PDF
Docker and friends at Linux Days 2014 in Prague
tomasbart
 
PDF
2015.07.16 Способы диагностики PostgreSQL
dev1ant
 
PDF
A little systemtap
yang bingwu
 
PDF
Масштабируемая конфигурация Nginx, Игорь Сысоев (Nginx)
Ontico
 
PPTX
Big data school demo
DataArt
 
PDF
Odoo Online platform: architecture and challenges
Odoo
 
PDF
Velocity 2017 Performance analysis superpowers with Linux eBPF
Brendan Gregg
 
PDF
Setting up mongodb sharded cluster in 30 minutes
Sudheer Kondla
 
PDF
The Practice of Alluxio in Near Real-Time Data Platform at VIPShop [Chinese]
Alluxio, Inc.
 
PDF
PostgreSQL Replication with Bucardo
Robertus M. S. E. Kusumaning Negoro
 
PDF
Alluxio in MOMO
Alluxio, Inc.
 
PPTX
OpenShift4 Installation by UPI on kvm
Jooho Lee
 
PPTX
分析mysql acid 设计实现
rfyiamcool
 
PDF
2017 meetup-apache-kafka-nov
Florian Hussonnois
 
Как понять, что происходит на сервере? / Александр Крижановский (NatSys Lab.,...
Ontico
 
Nginx 0.8.x 安装手册
Yiwei Ma
 
Advanced backup methods (Postgres@CERN)
Anastasia Lubennikova
 
Cpu高效编程技术
Feng Yu
 
Php perf
ericjonah
 
Python, Keras, Hello world, Installation, Binary Classification
Hamed Shah-Hosseini
 
Docker and friends at Linux Days 2014 in Prague
tomasbart
 
2015.07.16 Способы диагностики PostgreSQL
dev1ant
 
A little systemtap
yang bingwu
 
Масштабируемая конфигурация Nginx, Игорь Сысоев (Nginx)
Ontico
 
Big data school demo
DataArt
 
Odoo Online platform: architecture and challenges
Odoo
 
Velocity 2017 Performance analysis superpowers with Linux eBPF
Brendan Gregg
 
Setting up mongodb sharded cluster in 30 minutes
Sudheer Kondla
 
The Practice of Alluxio in Near Real-Time Data Platform at VIPShop [Chinese]
Alluxio, Inc.
 
PostgreSQL Replication with Bucardo
Robertus M. S. E. Kusumaning Negoro
 
Alluxio in MOMO
Alluxio, Inc.
 
OpenShift4 Installation by UPI on kvm
Jooho Lee
 
分析mysql acid 设计实现
rfyiamcool
 
2017 meetup-apache-kafka-nov
Florian Hussonnois
 
Ad

Similar to Redis深入浅出 (20)

PDF
(Fios#02) 2. elk 포렌식 분석
INSIGHT FORENSIC
 
PPT
Redis深入浅出
iammutex
 
PPTX
Toolbox of a Ruby Team
Arto Artnik
 
PPTX
Control your deployments with Capistrano
Ramazan K
 
PPT
Redis深入浅出
锐 张
 
PDF
Can we run the Whole Web on Apache Sling?
Bertrand Delacretaz
 
ODP
Aws Quick Dirty Hadoop Mapreduce Ec2 S3
Skills Matter
 
PDF
Fisl - Deployment
Fabio Akita
 
ODP
Caching and tuning fun for high scalability
Wim Godden
 
PPT
Why Managed Service Providers Should Embrace Container Technology
Sagi Brody
 
KEY
Apache Wizardry - Ohio Linux 2011
Rich Bowen
 
PPT
Logstash
琛琳 饶
 
PPTX
Container Monitoring with Sysdig
Sreenivas Makam
 
PDF
Redispresentation apac2012
Ankur Gupta
 
PPTX
RediSearch Mumbai Meetup 2020
⚡️ Vikram Sahu
 
PPT
Python Deployment with Fabric
andymccurdy
 
PPT
EAP TLS, the Rolls-Royce of extensible authentication protocol (EAP) methods ...
Jisc
 
ODP
Drupal Efficiency using open source technologies from Sun
smattoon
 
ODP
Drupal Efficiency - Coding, Deployment, Scaling
smattoon
 
PDF
More on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB Devroom
Valeriy Kravchuk
 
(Fios#02) 2. elk 포렌식 분석
INSIGHT FORENSIC
 
Redis深入浅出
iammutex
 
Toolbox of a Ruby Team
Arto Artnik
 
Control your deployments with Capistrano
Ramazan K
 
Redis深入浅出
锐 张
 
Can we run the Whole Web on Apache Sling?
Bertrand Delacretaz
 
Aws Quick Dirty Hadoop Mapreduce Ec2 S3
Skills Matter
 
Fisl - Deployment
Fabio Akita
 
Caching and tuning fun for high scalability
Wim Godden
 
Why Managed Service Providers Should Embrace Container Technology
Sagi Brody
 
Apache Wizardry - Ohio Linux 2011
Rich Bowen
 
Logstash
琛琳 饶
 
Container Monitoring with Sysdig
Sreenivas Makam
 
Redispresentation apac2012
Ankur Gupta
 
RediSearch Mumbai Meetup 2020
⚡️ Vikram Sahu
 
Python Deployment with Fabric
andymccurdy
 
EAP TLS, the Rolls-Royce of extensible authentication protocol (EAP) methods ...
Jisc
 
Drupal Efficiency using open source technologies from Sun
smattoon
 
Drupal Efficiency - Coding, Deployment, Scaling
smattoon
 
More on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB Devroom
Valeriy Kravchuk
 
Ad

Recently uploaded (20)

PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
PDF
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
PDF
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
PDF
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PDF
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
PDF
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PDF
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PDF
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 

Redis深入浅出

  • 1. Redis 深入浅出 Http://www.hoterran.info Http://Weibo.com/hoterran
  • 2. agenda use feature architecture admin replication presistence misc
  • 3. use Download http://redis.googlecode.com/files/redis-2.2.11.tar.gz install Redis-server > /dev/null & Redis-cli http://try.redis-db.com/
  • 4. use set/get lpush/lrem/rpop/ hset/hgetall sadd/srem multi/discard/exec
  • 5. feature Advanced key value store like memcachedb single threaded, no lock Event demultiplexer, no use libevent 2w lines writen in c without 3 rd library faster
  • 6. feature Difference with memached Data structure No only memcached k-v Linklist k-v1->v2->v3->v4... Set k - (v1,v2,v3,v4) Hash k – (k1 -v1, k2 – v2, k3 – v3) Need design a little Replication Presistence not support LRU Need multi instance use multi core
  • 7. feature Difference with MySQL Not Heap table store Not need index, so not execute plan Not compute statistic No sql No join Capacity size limited by cache a little design before dev High rw
  • 10. admin Redis.conf parameter intro Replication intro Persistence intro
  • 11. replication procedure map Dual master mode? Master slave slave mode defects Without resume broken transfer 可以架两级 slave 解决 ? Without lag(slave position)
  • 13. replication Case replication switch old redis version running on, say, redis:6379. Install and start a new redis on redis:6380 with a different dump file location. Execute SLAVE OF redis 6379 against redis:6380. Wait for first SYNC to complete. echo &quot;enable server redis/redis-6380&quot; | socat stdio unix-connect:/var/run/haproxy/admin.sock echo &quot;disable server redis/redis-6379&quot; | socat stdio unix-connect:/var/run/haproxy/admin.sock Execute SLAVE OF no one on redis:6380. Execute SHUTDOWN on redis:6379. Assuming that you've got a HAProxy config looking something like listen redis :6378 server redis-6379 localhost:6379 check weight 256 server redis-6380 localhost:6380 check disabled
  • 14. persistence Snapshot Fork process, loop hash table, save on file dump.rdb Yes!!! sequential write Write dump.rdb need O_DIRECT? Aof Like binlog, for recover after crash appendfsync Aof file is big use bgrewriteaof
  • 15. Login user Design a login user system Heap table userid login_times last_login_time 1 5 2011-1-1 2 1 2011-1-2 3 2 2011-1-3 Last login man? Max login man?
  • 16. Login user data Set userid:1:login_times 5 Set userid:2:login_times 1 Set userid:3:login_times 2 Set userid:1:last_login 2011-1-1 Set userid:2:last_login 2011-1-2 Set userid:3:last_login 2011-1-3 Last login lpush user_last_login 1 lpush user_last_login 2 lpush user_last_login 3 ltrim user_last_login 0 1
  • 17. Login user Max login man zadd user:login_times 5 1 zadd user:login_times 1 2 zadd user:login_times 2 3 zcard user:login_times zrangebyscore user:login_times 3 +inf withscores Column store data?
  • 18. tag Relational is suitable? book id book author 1 <<Diving into Python>> gun 2 <<Ruby on rail>> japan Tag Tagname id Web 1 Web 2 Python 2 Sql select id from tag t1, tag t2 where t1.tagname = 'web' and t2.tagname = 'python' and t1.id = t2.id
  • 19. tag Kv design set book:1 ”diving into python” Set book:2 ”ruby on rail” sadd tag:web 2 sadd tag:web 1 sadd tag:python 1 sinter 'tag:web' 'tag:python' sunion tag:web 'tag:python' sdiff tag:web 'tag:python' 反思?
  • 20. Sina weibo Recent record List, Lrange( 关注的人列表、粉丝列表、 feeds 列表 ) Set Sadd|, sdiff, sinter ( 我的好友,我可能感兴趣的人 ) Score Zadd, zset(feeds 排名 ) Hash Hincrby, hgetall( 用户资料,关注数,粉丝数,微博数 ) Delete history data expire
  • 21. Sina weibo 我关注的人 sadd user:hoterran:follows user:foolishceo sadd user:hoterran:follows user:logzgh sadd user:hoterran:follows user:sqlrush smembers user:hoterran:follows 英杰关注的人 sadd user:sqlrush:follows user:logzgh sadd user:sqlrush:follows user:hoterran
  • 22. Sina weibo 我们共通关注的人 sinter user:sqlrush:follows user:hoterran:follows 我的粉丝 sadd user:logzgh:follows user:hoterran sadd user:hoterran.follower user:logzgh sadd user:hoterran.follower user:sqlrush smembers user:hoterran:follower
  • 23. Sina weibo 我的好友 sinter user:hoterran:follows user:hoterran:follower 我们都关注的人 sinter user:sqlrush:follows user:hoterran:follows
  • 24. Sina weibo 可能感兴趣的的人 sadd user:sqlrush:follows user:free_yz sdiff user:sqlrush:follows user:hoterran:follows 我关注的人数,我的粉丝数,我的 Hset hoterran:profile follows 1 Hset hoterran:profile follower 2 Hset hoterran:profile blog 3 Hgetall hoterran:profile Hincrby hoterran:profile blog 1
  • 25. Suitable scene 轻量级的高性能消息队列服务 生产者消费者 Producer lpush Consumer blpop Redis 的主要缺点是数据库容量受到物理内存的限制,不能用作海量数据的高性能读写,并且它没有原生的可扩展机制,不具有 scale (可扩展)能力,要依赖客户端来实现分布式读写,因此 Redis 适合的场景主要局限在较小数据量的高性能操作和运算上。
  • 26. summary Defects Failover Replication Dba level Memory limit size Advantage High qps Data structure
  • 27. qa Replace aliWangwang k-v(blob) Can satisfy Online Log requirement?