• 1. redis深入浅出
  • 2. AgendaFeature&Architecture Admin&capcity forecast Replication Presistence Table design
  • 3. Featureredismemcacheddata structurestring|list|hash|set|zsetstringthread modelthird(main thread, two auxiliary thread)manydemultiplexerae.clibevent(3rd library)persistenceyesnoreplicationyesnodesignweakno
  • 4. StringSet hello world Set hello 1234567 Set hello 1234
  • 5. ListLpush list aaaa bbb ccc Double link list, so can lpush,rpush,lpop,rpop
  • 6. ZipmapHset test hello world Hset test aliyun dba Zipmap defect:Zmlen one bytes, only 253 subkey
  • 7. Architecture
  • 8. Rehash
  • 9. Cache forecaststring类型的内存大小 = 键值个数 * (dictEntry大小 + redisObject大小 + 包含key的sds大小 + 包含value的sds大小) + bucket个数 * 4 zipmap类型的内存大小 = hashkey个数 * (dictEntry大小 + redisObject大小 + 包含key的sds大小 + subkey的总大小) + bucket个数 * 4 Jemalloc size class
  • 10. AdminRedis.conf(static), config set(dynamic) maxmemory Appendfsync everysec(fsync pagecache to disk) hash-max-zipmap-entries 512 hash-max-zipmap-value 64
  • 11. Replicationprocedure map Master slave – slave – slave - slave defects Without resume broken transfer Without lag(slave position)
  • 12. replication
  • 13. PersistenceSnapshot 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
  • 14. Auxiliary thread
  • 15. Table desgin login userDesign 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!!!
  • 16. Login userdata 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 userMax 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. Suitable Scene轻量级的高性能消息队列服务,生产者消费者 跨机器的共享内存 Redis的主要缺点是数据库容量受到物理内存的限制,不能用作海量数据的高性能读写,并且它没有原生的可扩展机制,不具有scale(可扩展)能力,要依赖客户端来实现分布式读写,因此Redis适合的场景主要局限在较小数据量的高性能操作和运算上。
  • 19. QA@hoterran www.hoterran.info