• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Redis深入浅出
 

Redis深入浅出

on

  • 972 views

 

Statistics

Views

Total Views
972
Views on SlideShare
919
Embed Views
53

Actions

Likes
0
Downloads
10
Comments
0

2 Embeds 53

http://www.note4u.net 52
http://cache.baidu.com 1

Accessibility

Upload Details

Uploaded via as Microsoft PowerPoint

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

    Redis深入浅出 Redis深入浅出 Presentation Transcript

    • redis 深入浅出
    • Agenda Feature&Architecture Admin&capcity forecast Replication Presistence Table design
    • Feature redis memcacheddata structure string|list|hash|set|zset stringthread model third(main thread, two many auxiliary thread)demultiplexer ae.c libevent(3rd library)persistence yes noreplication yes nodesign weak no
    • String Set hello world Set hello 1234567 Set hello 1234
    • List Lpush list aaaa bbb ccc Double link list, so can lpush,rpush,lpop,rpop
    • ZipmapHset test hello worldHset test aliyun dbaZipmap defect:Zmlen one bytes, only 253 subkey
    • Architecture
    • Rehash
    • Cache forecaststring 类型的内存大小 = 键值个数 * (dictEntry 大 小 + redisObject 大小 + 包含 key 的 sds 大小 + 包含 value 的 sds 大小 ) + bucket 个数 * 4zipmap 类型的内存大小 = hashkey 个数 * (dictEntry 大小 + redisObject 大小 + 包含 key 的 sds 大小 + subkey 的总大小 ) + bucket 个数 * 4Jemalloc size class
    • Admin Redis.conf(static), config set(dynamic) – maxmemory <bytes> – Appendfsync everysec(fsync pagecache to disk) – hash-max-zipmap-entries 512 – hash-max-zipmap-value 64
    • Replication procedure  map  Master slave – slave – slave - slave defects  Without resume broken transfer  Without lag(slave position)
    • replication
    • Persistence Snapshot  Fork process, loop hash table, save file dump.rdb  Yes!!! sequential write  Write dump.rdb need O_DIRECT Aof  Like binlog, for recover after crash  Auto bgrewrteaof  Auxiliary threads  Postpone fsync
    • Auxiliary thread
    • Table desgin 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? Create index on last_login_time  Max login man? Create index on login_times  Index, explan plan, compute statistics is suck!!!
    • 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?
    • Suitable Scene 轻量级的高性能消息队列服务 , 生产者消费者 跨机器的共享内存 Redis 的主要缺点是数据库容量受到物理内存 的限制,不能用作海量数据的高性能读写,并 且它没有原生的可扩展机制,不具有 scale (可扩展)能力,要依赖客户端来实现 分布式读写,因此 Redis 适合的场景主要局限 在较小数据量的高性能操作和运算上。
    • QA @hoterranwww.hoterran.info