• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Redis
 

Redis

on

  • 1,494 views

珠三角技术沙龙2011年10月分享

珠三角技术沙龙2011年10月分享

Statistics

Views

Total Views
1,494
Views on SlideShare
1,494
Embed Views
0

Actions

Likes
7
Downloads
79
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

Redis Redis Presentation Transcript

  • Redis实践 翁伟
  • 翁伟 / Wuvist• 新加坡海龟• 汕头招聘海盗创业中• email/gtalk/G+: wuvist@gmail.com• QQ: 124424• http://twitter.com/Wuvist
  • Redis是什么?• 源K/V 数据库• V支持丰富的数据类型 • strings, hashes, lists, sets, sorted sets.• 单机• 比memcached还快
  • Redis能做什么?• 最新数据列表• 排行榜• 计数器• 消息队列• 缓存
  • 我拿Redis做什么?• 缓存 • Cache-Money Pattern
  • Cache-Money• Twitter 源: • https://github.com/nkallen/cache-money• “A write-through and read-through caching library for ActiveRecord.”• 基于memcached• 理想情况下,数据库零读压力
  • Read Through 直读• obj = Obj.FetchById(...) • 缓存不存在 • 读取数据库后写入缓存
  • Active Record• 透明缓存: • 一或者多个等于条件 • ID排倒序
  • 查询 => Key• select id from blogs where author_id = x and is_deleted = 0 order by id desc • blog:author_id=1:is_deleted=0• select count(*) from blogs where author_id = x and is_deleted = 0 • blog:author_id=1:is_deleted=0/c
  • Write Through 直写• Obj.Save() • 写入数据库时自动写入缓存 • 下次直接读取直接命中缓存
  • 实际上...• 插入新blog: • Get: blog:author_id=1:is_deleted=0 • Deserialized to Array • Append to new ID • Serialized to bytes • Set: blog:author_id=1:is_deleted=0
  • 并发怎么办?• Check and Save (CAS)• 有原子操作的Append就好了∼ • Redis List
  • 上Redis• Redis List • Append 无需Get/Set、无需CAS• 原生分页支持
  • 更多功能• 只能ID排倒序 • Sorted Set: 任意数字化列
  • Schema - less• How FriendFeed use mysql? • http://bret.appspot.com/entry/how- friendfeed-uses-mysql• 数据表: id + 单二进制列• 索引表: id + 查询条件列
  • • Redis 替代索引表
  • • 查询 => key• “预先”存储查询结果• 查询时间 杂度恒定 • 无“ 杂SQL”
  • 还可以...• 全文搜索 • blog:fulltext:title:Redis• Type Ahead • blog:type_ahead:title:re
  • • 查询 => Key• 本质上是HashTable查找• 数据库索引是B+树 • select * from blogs where author_id > 10 and is_deleted = 0
  • • Sorted Set仅实现部分功能• Redis不能100%替代数据库索引
  • 数据表?• 消灭MySQL,数据也放Redis• 内存限制 • 一半的可用物理内存 • 1/10问题 • MySQL解决得较好
  • 分布式• Redis仅是单机方案• Sharding容易,但细节。。。
  • Plurk - LightCloud• Consistent Hash Ring http://opensource.plurk.com/LightCloud/
  • 我选择冬眠...• http://redis.io/presentation/Redis_Cluster.pdf
  • Demo
  • Q &A
  • 轮子• MongoDB • 最初有误解• Redis + MySQL的轮子并不 杂,可控程 度高• FourSquare / 视觉中国也都为MongoDB 出 重的学习成本