《redis深入浅出(精品).ppt》由会员分享,可在线阅读,更多相关《redis深入浅出(精品).ppt(27页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、Redis 深入浅出Http:/www.hoterran.infoHttp:/W http:/ /dev/null&Redis-clihttp:/try.redis- key value store like memcachedbsingle threaded,no lockEvent demultiplexer,no use libevent2w lines writen in c without 3rd libraryfasterfeatureDifference with memachedData structureNo only memcached k-vLinklist k-v1-v
2、2-v3-v4.Set k-(v1,v2,v3,v4)Hash k (k1-v1,k2 v2,k3 v3)Need design a littleReplicationPresistencenot support LRUNeed multi instance use multi corefeatureDifference with MySQLNot Heap table storeNot need index,so not execute planNot compute statisticNo sqlNo joinCapacity size limited by cachea little d
3、esign before devHigh rwarchitecturearchitectureadminRedis.conf parameter introReplication introPersistence introreplicationproceduremapDual master mode?Master slave slave modedefectsWithout resume broken transfer可以架两级slave解决?Without lag(slave position)replicationreplicationCase replication switchold
4、 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.sockecho disable
5、 server redis/redis-6379|socat stdio unix-connect:/var/run/haproxy/admin.sockExecute SLAVE OF no one on redis:6380.Execute SHUTDOWN on redis:6379.Assuming that youve got a HAProxy config looking something likelisten redis:6378server redis-6379 localhost:6379 check weight 256server redis-6380 localho
6、st:6380 check disabledpersistenceSnapshotFork process,loop hash table,save on file dump.rdbYes!sequential writeWrite dump.rdb need O_DIRECT?AofLike binlog,for recover after crashappendfsyncAof file is big use bgrewriteaofLogin userDesign a login user systemHeap tableuserid login_times last_login_tim
7、e1 5 2011-1-12 1 2011-1-23 2 2011-1-3Last login man?Max login man?Login userdataSet userid:1:login_times 5Set userid:2:login_times 1Set userid:3:login_times 2Set userid:1:last_login 2011-1-1Set userid:2:last_login 2011-1-2Set userid:3:last_login 2011-1-3Last login lpush user_last_login 1lpush user_l
8、ast_login 2lpush user_last_login 3ltrim user_last_login 0 1Login userMax login manzadd user:login_times 5 1zadd user:login_times 1 2zadd user:login_times 2 3zcard user:login_timeszrangebyscore user:login_times 3+inf withscoresColumn store data?tagRelational is suitable?bookid book author1 gun2 japan
9、TagTagnameidWeb1Web 2Python 2Sqlselect id from tag t1,tag t2 where t1.tagname=web and t2.tagname=python and t1.id=t2.idtagKv designset book:1”diving into python”Set book:2”ruby on rail”sadd tag:web 2sadd tag:web 1sadd tag:python 1sinter tag:web tag:pythonsunion tag:web tag:pythonsdiff tag:web tag:py
10、thon反思?Sina weiboRecent recordList,Lrange(关注的人列表、粉丝列表、feeds列表)Set Sadd|,sdiff,sinter (我的好友,我可能感兴趣的人)ScoreZadd,zset(feeds排名)HashHincrby,hgetall(用户资料,关注数,粉丝数,微博数)Delete history dataexpireSina weibo我关注的人sadd user:hoterran:follows user:foolishceosadd user:hoterran:follows user:logzghsadd user:hoterran:f
11、ollows user:sqlrushsmembers user:hoterran:follows英杰关注的人sadd user:sqlrush:follows user:logzghsadd user:sqlrush:follows user:hoterranSina weibo我们共通关注的人sinter user:sqlrush:follows user:hoterran:follows我的粉丝sadd user:logzgh:follows user:hoterran sadd user:hoterran.follower user:logzghsadd user:hoterran.f
12、ollower user:sqlrush smembers user:hoterran:followerSina weibo我的好友sinter user:hoterran:follows user:hoterran:follower 我们都关注的人sinter user:sqlrush:follows user:hoterran:followsSina weibo可能感兴趣的的人sadd user:sqlrush:follows user:free_yzsdiff user:sqlrush:follows user:hoterran:follows我关注的人数,我的粉丝数,我的Hset ho
13、terran:profile follows 1Hset hoterran:profile follower 2Hset hoterran:profile blog 3Hgetall hoterran:profileHincrby hoterran:profile blog 1Suitable scene轻量级的高性能消息队列服务生产者消费者Producer lpushConsumer blpop Redis的主要缺点是数据库容量受到物理内存的限制,不能用作海量数据的高性能读写,并且它没有原生的可扩展机制,不具有scale(可扩展)能力,要依赖客户端来实现分布式读写,因此Redis适合的场景主要局限在较小数据量的高性能操作和运算上。summaryDefectsFailoverReplicationDba levelMemory limit sizeAdvantageHigh qpsData structureqaReplace aliWangwang k-v(blob)Can satisfy Online Log requirement?
限制150内