当前位置: 首页 > >

¾­ÑéÕûÀí-1-Redis×Üƪ-1-100-@

发布时间:

RedisÊǵ¥Ï̵߳ÄΪʲô»¹Õâô¿ì£¿

µ¥Ï̱߳ȶàÏß³ÌÊÇÒªÂýһЩµÄ£¬ÕâÊÇredisµÄÒ»¸öȱÏÝ£¨ÎªÁË°²È«¿¼ÂÇ£©£»
µ«ÊÇ¿ìµÄÔ­ÒòÖ÷ÒªÊÇÒÔϼ¸µã£º
1¡¢»ùÓÚÄڴ棬·Ç³£¿ìËÙ¡££¬ÀàËÆÓÚHashMap£¬HashMapµÄÓÅÊƾÍÊDzéÕҺͲÙ×÷µÄʱ¼ä¸´ÔӶȶ¼ÊÇO(1)£»
2¡¢Êý¾Ý½á¹¹¼òµ¥£¬¶ÔÊý¾Ý²Ù×÷Ò²¼òµ¥£¬RedisÖеÄÊý¾Ý½á¹¹ÊÇרÃŽøÐÐÉè¼ÆµÄ£»
3¡¢²ÉÓõ¥Ị̈߳¬±ÜÃâÁ˲»±ØÒªµÄÉÏÏÂÎÄÇл»ºÍ¾ºÕùÌõ¼þ£¬Ò²²»´æÔÚ¶àÏß³ÌÇ뻶øÏûºÄ CPU£¬²»ÓÃÈ¥¿¼ÂǸ÷ÖÖËøµÄÎÊÌ⣬²»´æÔÚ¼ÓËøÊÍ·ÅËø²Ù×÷£¬Ã»¿ÉÄܳöÏÖËÀËø¶øµ¼ÖµÄÐÔÄÜÏûºÄ£»£¨Ö»Êǵ¥Ïß³ÌÈ¥´¦Àíselector¹ÜÀíµÄËùÓÐÍøÂçÇëÇó£¬ÆäËûÄ£¿éÈÔÓÃÁ˶à¸öỊ̈߳©
4¡¢Ê¹Óöà·I/O¸´ÓÃÄ£ÐÍselector£¬·Ç×èÈûIO£»
5¡¢Ê¹ÓõײãÄ£ÐͲ»Í¬£¬ËüÃÇÖ®¼äµ×²ãʵÏÖ·½Ê½ÒÔ¼°Óë¿Í»§¶ËÖ®¼äͨÐŵÄÓ¦ÓÃЭÒé²»Ò»Ñù£¬RedisÖ±½Ó×Ô¼º¹¹½¨ÁËVM »úÖÆ £¬ÒòΪһ°ãµÄϵͳµ÷ÓÃϵͳº¯ÊýµÄ»°£¬»áÀË·ÑÒ»¶¨µÄʱ¼äÈ¥Òƶ¯ºÍÇëÇó£»


---------RedisÔ­Àí---------


¾ÍÊÇÀàËÆÓÚ java nio£¬¶ÓÁл·¾³²»Í¬£¬java? nioÊÇbuffer»º´æ



ÊÇ·ñʹÓùýRedis¼¯Èº£¬¼¯ÈºµÄ¸ß¿ÉÓÃÔõô±£Ö¤£¬ÈýÖÖ¼¯ÈºµÄÔ­ÀíÊÇʲô£¿

1¡¢Ö÷´Óģʽ£ºÈômaster¹Òµô£¬ÔòredisÎÞ·¨¶ÔÍâÌṩд·þÎñ¡£Ò»Ö÷¶à´Ó£¬´Ó¿âÖ»¶Á£¬Í¬²½½ÓÊÕÖ÷¿âÊý¾Ý
´æÔÚÎÊÌ⣺
¿ÉÒÔÒ»Ö÷¶à´Ó£¬Ö÷´ÓÊý¾Ýͬ²½±£Ö¤Êý¾ÝÍêÕûÐÔ£¬ÇÒ¿ÉÒÔʵÏÖдÖ÷¡¢¶Á´Ó£¬ÐÔÄÜÓÐËùÌáÉý£¬µ«Ö÷½Úµã¹ÊÕϺóÎÞ·¨Ð´È룬ûÓйÊÕÏÑ¡¾Ù¹¦ÄÜ£¬ÇÒÎÞ¼à¿Ø¸÷Ö÷´ÓÔËÐÐ״̬¹¦ÄÜ£»
2¡¢SentinelÉÚ±øģʽ£º×ÅÑÛÓڸ߿ÉÓã¬ÔÚmasterå´»úʱ»á×Ô¶¯½«slaveÌáÉýΪmaster£¬¼ÌÐøÌṩ·þÎñ¡£
´æÔÚÎÊÌ⣺
¼à¿Ø¸÷½ÚµãÔËÐÐ״̬£¬Ö÷½Úµã·¢Éú¹ÊÕϺ󣬿ÉÒÔͨ¹ýÔÙ´ÎÑ¡¾Ù²úÉúÖ÷½Úµã£¬ÊµÏÖ¹ÊÕϻָ´£¬µ«Èô´Ó½Úµã¹ÒÁ˲»ÄÜʵÏÖ´Ó½ÚµãµÄ¹ÊÕÏתÒÆ£¬ÒÆ£¬µ±´Î²éѯ±¨´í£»
1£©ÄÔÁѵ¼ÖµÄÊý¾Ý¶ªÊ§£º¾ÉmasterÔٴλָ´µÄʱºò£¬»á±»×÷Ϊһ¸öslave¹Òµ½ÐµÄmasterÉÏÈ¥£¬×Ô¼ºµÄÊý¾Ý»áÇå¿Õ£¬ÖØдÓеÄmaster¸´ÖÆÊý¾Ý¡£
2£©Òì²½¸´ÖÆ£¬masteå´»úµ¼ÖµÄÊý¾Ý¶ªÊ§
3¡¢Redis ClusterÔ­Àí£º²Ûλ¶¨Î»Ëã·¨£¨ÕÒµ½Ä³²ÛÇø¼ä£¬¶ÔÓ¦Ò»¸öÉÚ±øģʽ£©+SentinelÉÚ±øģʽ


×ÅÑÛÓÚÀ©Õ¹ÐÔ£¬ÔÚµ¥¸öredisÄÚ´æ²»×ãʱ£¬Ê¹ÓÃCluster½øÐзÖƬ´æ´¢¡£

-----------------------------¼¯Èº-----------------


------ Ò»ÖÂÐÔhashËã·¨Ô­Àí------

Ò»ÖÂÐÔHashËã·¨ÊÇÔ¤ÏȶÔ2^32È¡Ä££¬µÃµ½2^32¸öδ·ÖÅäµÄ×ӽڵ㣻
½«¸÷¸ö·þÎñÆ÷°´IP»òÖ÷»úÃû½øÐйþÏ££¬±ÈÈçIP1,IP2,IP3,µÃµ½¶ÔÓ¦Õ游½Úµã£¬²¢°Ñ×Ó½ÚµãÓë˳ʱÕëÏòÇ°×î*ÄǸöÕ游½Úµã°ó¶¨Ó³ÉäÔÚÒ»Æð¡£
ÒÔºóеĸºÔØÇëÇó½øÀ´£¬ÊÇÏÈ°´×ӽڵ㼴2^32×öhashµÄ£¬ÏÈÕÒµ½×ӽڵ㣬ÔÙÕÒµ½¶ÔÓ¦µÄ¸¸½Úµã¡£
Èç¹ûå´»úһ̨¸¸½Úµã£¬ÄÇôºóÃæµÄÏàÁÙ¸¸½Úµã¾Í»áÔö¼ÓÕⲿ·ÖеÄ×ӽڵ㣨Èç¹û¼Ó»úÆ÷ÊǺóÃæµÄÉÙ×ӽڵ㣩¡£ÕâÑù¾Í²»ÐèÒªÖØÐÂhash£¬×Ô¶¯·ÖÅäµ½ºóÃæÏàÁÙµÄÄǸö¸¸½ÚµãÉÏÁË¡£


------ Ò»ÖÂÐÔhashËã·¨Êý¾ÝÇãбÎÊÌ⣨·ÖÅä²»¾ù£©-----

Èç¹û¸¸½Úµã¹ýÉÙ£¬ÄÇ·ÖÅä²»¾ù¾Í¸üÈÝÒ׳öÏÖÁË£¬»¹¸üÑÏÖØ¡££¨¸¸½Úµã¶àÒ²Ö»ÊÇ×öµ½Ïà¶Ô¾ùÔÈ£©
ÐéÄâ½Úµã»úÖÆ£º±ÈÈçÖ»ÓÐABÁ½½Úµã£¬ÄÇͨ¹ý×îÖÕ¸¸½Úµã#ºÅºöÂÔµÄÌØÐÔ£¬ÔÚ#ºóÃæ²ð·Ö³É¶à¸ö¸¸½Úµã£¬À´Ôö¼Ó·Ö²¼¾ùÔȵĻúÂÊ¡£¡°Node A#1¡±¡¢¡°Node A#2¡±¡¢¡°Node A#3¡±¡¢¡°Node B#1¡±¡¢¡°Node B#2¡±¡¢¡°Node B#3¡±


------ Ò»ÖÂÐÔhashËã·¨µÄ¸Ä½ø°æ------hash slot Ëã·¨------

redis cluster Óй̶¨µÄ 16384 ¸ö hash slot(±È2µÄ32´Î·½Éٺܶ࣬ÇÒ¾ùÔÈ·ÖÅäµ½¸÷¸öÉÚ±øȺ)£¬¶Ôÿ¸ö key ¼ÆËã CRC16 Öµ£¬È»ºó¶Ô 16384 È¡Ä££¬¿ÉÒÔ»ñÈ¡ key ¶ÔÓ¦µÄ hash slot
redis cluster ÖÐÿ¸ö master ¶¼»á³ÖÓв¿·Ö slot£¬±ÈÈçÓÐ 3 ¸ö master£¬ÄÇô¿ÉÄÜÿ¸ö master ³ÖÓÐ 5000 ¶à¸ö hash slot
hash slot Èà node µÄÔö¼ÓºÍÒƳýºÜ¼òµ¥£º
¼õÉÙÒ»¸ö master£¬¾Í½«ËüµÄ hash slot Òƶ¯µ½ÆäËû master ÉÏÈ¥
¿Í»§¶ËµÄ api£¬¿ÉÒÔ¶ÔÖ¸¶¨µÄÊý¾Ý£¬ÈÃËûÃÇ×ßͬһ¸ö hash slot£¬Í¨¹ý hash tag À´ÊµÏÖ£º¿´µ½{}£¬¾ÍÖ»hashÀïÃæµÄÖµ£¬¿Ï¶¨ÔÚͬһ¸ö²Û


?


£¿ÎªÊ²Ã´Ñ¡Redis£¿ÎªÊ²Ã´Ê¹ÓÃRedis¼¯Èº£¿Ôõô°²×°cluster?ģʽµÄ¼¯ÈºRedis£¨hash slot Ëã·¨£©£¿

Ò»¡¢ÎªÊ²Ã´Ñ¡Redis£ºÒòΪḬ̈߳²È«µÄ
¶þ
¡¢ÎªÊ²Ã´Ê¹Óü¯Èº£ºµ¥»úÎÞ·¨·¢»Ó¶àºËCPUÐÔÄÜ
1.½¨Æðһ̨?redis.confÉèÖÃΪÆô¶¯¼¯ÈºÄ£Ê½µÄredisʵÀý£¬±ÈÈç9001¶Ë¿Ú£¬È»ºó°Ñ?9001?ʵÀý?¸´ÖƵ½ÁíÍâÎå¸öÎļþ¼ÐÖÐ(cp?-rf?)£¬Î¨Ò»ÒªÐ޸ĵľÍÊÇ?redis.conf?ÖеÄËùÓкͶ˿ڵÄÏà¹ØµÄÐÅÏ¢.
ËÄ¡¢Ô­Àí£º



Redis¼¯ÈºÑ¡¾ÙÔ­Àí-£¨ºÍÉÚ±øÒ»Ñù£©

1£©µ±Ç°slave·¢ÏÖ×Ô¼ºµÄmaster¹ÒÁË£¬
¸ø×ÔÒÑͶһƱ¼Ó1,slaveÏòÆäËû½ÚµãÇëÇóͶƱ¸ø×Ô¼º³ÉΪmaster
µ±slaveÊÕµ½µÄͶƱ³¬¹ý°ëÊýºó¾Í¿ÉÒÔ³ÉΪmaster
µ±slave·¢ÏÖ×Ô¼ºµÄmaster¹ÒÁ˲¢²»»áÁ¢¼´½øÐÐÇëÇóͶƱ,»áÓÐÒ»¶¨µÄÑÓʱ,È·±£ÆäËûµÄmasterÒ²Òâʶµ½µ±Ç°µÄmaster¹ÒÁË,·ñÔòmaster¿ÉÄÜ»á¾Ü¾øͶƱ
ÑÓʱ¼ÆË㹫ʽDelay=500ms+random(0-500)ms+Slave_rank* 100ms(slave_rankΪ¸´ÖÆÊý¾ÝµÄµÈ¼¶,µÈ¼¶Ô½Ð¡±íʾ¸´ÖÆÊý¾ÝÔ½¶àÒ²ÊÇΪÁ˱£Ö¤ÄÜÈÃÓµÓÐ×îÐÂÊý¾ÝµÄslave×îÏÈ·¢ÆðÑ¡¾Ù)


ÉÚ±øleaderÑ¡¾ÙÁ÷³Ì£¿

sentinel»áÒÔÿÃëÒ»´ÎµÄƵÂÊÏòÖ÷´ÓºÍÆäËûsentienl·¢ËÍpingÃüÁî,µ±³¬¹ýÉèÖõÄdown-after-millisecondsºóδÊÕµ½µÄÓÐЧµÄÏìÓ¦»áÈÏΪ¸ÃmasterÖ÷¹ÛÏÂÏß,½Ó×ÅÏòÆäËûsentiel½øÐÐÈ·ÈÏ,½ÓÊÕµ½×ã¹»ÊýÁ¿µÄºó,sentinel»áÅж¨¸Ã·þÎñÆ÷¿Í¹ÛÏÂÏß
¸Ãsentinel»áÏëÆäËûsentinel·¢ËÍÇëÇóÆäËûsentinelÊÓ×Ô¼ºÎªleader,ÿ¸ösentinelÿ´ÎÑ¡¾Ù»á×ÔÔöÅäÖüÍÔª,ÿ¸ösentinelÖ»ÄÜÑ¡ÔñÒ»´Î,µ±ÊÕµ½°ëÊýÒÔÉϵÄƱ,sentinel»á½øÐÐslaveµÄÑ¡¾Ù
slaveµÄÑ¡¾Ù.½øÐв»½¡¿µµÄslaveÅųý(Ö÷¹ÛÏÂÏßµÄ,´óÓÚ5Ãëδ»ØÓ¦µÄ,Óëmaster½ÚµãʧÁªµÄ),¶Ô½¡¿µ½Úµã½øÐÐÅÅÐò(ÉèÖõÄÓÅÏȼ¶,ÈôÏàͬ½øÐÐÏÂÒ»²½,Ñ¡ÔñÆ«ÒÆÁ¿´óµÄ´Ó½Úµã)
Ñ¡¾Ù³öµÄslave»áÖ´ÐÐslaveof no one³ÉΪÖ÷½Úµã,ÏòÆäËûslave·¢ËÍÃüÁîÆä³ÉΪеÄmasterµÄslave,¼àÊӾɵÄmaster»Ö¸´ºó³ÉΪеÄmasterµÄslave²¢½øÐÐͬ²½


£¿¶¯Ì¬À©ÈÝ¡¢Ôö¼Ó½ÚµãºÍ¼õÉٽڵ㣬ÖØзÖÅä²Û´óС£¿

Redis?¼¯ÈºÖÐ×ܹ²ÓÐÇÒ½öÓÐ?16383?¸ö?solt£¬Ä¬ÈÏÇé¿ö»á¸øÎÒÃÇ*¾ù·ÖÅ䣬µ±È»Äã¿ÉÒÔÖ¸¶¨£¬ºóÐøµÄÔö¼õ½ÚµãÒ²¿ÉÒÔÖØзÖÅä¡£


?
£¿Redis¼¯ÈºÖ§³ÖÊÂÎïÂð£¿

Redis¼¯Èº²»Ö§³ÖÊÂÎֻÓнڵãÄÚ²¿²ÅÖ§³Ö¡£Èç¹ûÏëʵÏÖ£¬Ö»ÄÜ¿¿Èý·½²å¼þ£¬±ÈÈçluaÀ´Ð´½Å±¾ÊµÏÖÊÂÎï.


£¿redisÈçºÎʹÓöþ¼¶»º´æ£¿

mvnÒýÈëEhcache¹¤¾ßÀ࣬ͨ¹ýRedis+ehCacheʵÏÖÁ½¼¶¼¶»º´æ£¬Ï൱ÓÚÔÚÇ°Ãæ¼ÓÁËehCache×öΪһ¼¶»º´æ£¬²éʱÓÅÏȲéËü£¬Èç¹û²»´æÔÚ£¬ÔÙ²éredis£¨Í¬Ê±¸üÐÂÒ»¼¶»º´æehCache£©£¬×îºó²é²»µ½ÔÙ²émysql£¨Í¬Ê±¸üжþ¼¶»º´æredis£©


¶þ¼¶»º´æehcacheÈçºÎ±£Ö¤Óë·Ö²¼Ê½redisµÄÒ»ÖÂÐÔ£¿

ÎÞ·¨±£Ö¤Ç¿Ò»ÖÂÐÔ£¬Ö»Äܾ¡Á¿×¼Ò»ÖÂÐÔ¡£
1¡¢Ehcache¶¨Ê±ÂÖѯRedis»º´æ·þÎñÆ÷¸üͬ²½¸üб¾µØ»º´æ£¬È±µãÊÇÒòΪÿ̨·þÎñÆ÷¶¨Ê±EhcacheµÄʱ¼ä²»Ò»Ñù£¬ÄÇô²»Í¬·þÎñÆ÷Ë¢ÐÂ×îлº´æµÄʱ¼äÒ²²»Ò»Ñù£¬»á²úÉúÊý¾Ý²»Ò»ÖÂÎÊÌ⣬¶ÔÒ»ÖÂÐÔÒªÇ󲻸߿ÉÒÔʹÓá£
2¡¢·¢²¼¶©ÔÄ·½°¸£¨redis»òMQ£©£¬Í¨¹ýÒýÈëÁËMQ¶ÓÁУ¬Ê¹Ã¿Ì¨Ó¦Ó÷þÎñÆ÷µÄEhcacheͬ²½ÕìÌýMQÏûÏ¢,Redis±ä¸ü£¬ÊµÊ±Í¬²½µ½ehcache£¬ÕâÑùÔÚÒ»¶¨³Ì¶ÈÉÏ¿ÉÒԴﵽ׼ͬ²½¸üÐÂÊý¾Ý£¬Í¨¹ýMQÍÆËÍ»òÕßÀ­È¡µÄ·½Ê½£¬µ«ÊÇÒòΪ²»Í¬·þÎñÆ÷Ö®¼äµÄÍøÂçËٶȵÄÔ­Òò£¬ËùÒÔÒ²²»ÄÜÍêÈ«´ïµ½Ç¿Ò»ÖÂÐÔ¡£»ùÓÚ´ËÔ­ÀíʹÓÃZookeeperµÈ·Ö²¼Ê½Ð­µ÷֪ͨ×é¼þÒ²ÊÇÈç´Ë¡£


£¿»º´æÑ©±ÀÊÇʲô£¿½â¾ö·½°¸£¿£¨²¢·¢²éÊý¾Ý¿â£¬¸ã»µÊý¾Ý¿â£©£¬»º´æ»÷´©ÄØ£¨¶ñÒâ¹¥»÷Ò»Ìõ£©

£¨»º´æ»÷´©¸ú»º´æÑ©±ÀÓеãÏñ.»º´æÑ©±ÀÊÇÒòΪ´óÃæ»ýµÄ»º´æʧЧ£¬´ò±ÀÁËDB£¬¶ø»º´æ»÷´©²»Í¬µÄÊÇ»º´æ»÷´©ÊÇÖ¸Ò»¸öKey·Ç³£Èȵ㣬ÔÚ²»Í£µÄ¿¸×Å´ó²¢·¢£¬´ó²¢·¢¼¯ÖжÔÕâÒ»¸öµã½øÐзÃÎÊ£¬µ±Õâ¸öKeyÔÚʧЧµÄ˲¼ä£¬³ÖÐøµÄ´ó²¢·¢¾Í´©ÆÆ»º´æ£¬Ö±½ÓÇëÇóÊý¾Ý¿â£¬¾ÍÏñÔÚÒ»¸öÍêºÃÎÞËðµÄÍ°ÉÏÔ俪ÁËÒ»¸ö¶´¡££©

´ð£º1£ºÔÚ»º´æʧЧºó£¬Í¨¹ý¼ÓËø(·Ö²¼Ê½Ëøzk)»òÕ߶ÓÁÐÀ´¿ØÖƶÁÊý¾Ý¿âд»º´æµÄÏß³ÌÊýÁ¿¡£±ÈÈç¶Ôij¸ökeyÖ»ÔÊÐíÒ»¸öÏ̲߳éѯÊý¿âºÍдredis»º´æ£¬ÆäËûÏ̵߳ȴý¡££¨Ó°ÏìÍÌÍÂÁ¿£©
1£ºÔÚ»º´æʧЧºó£¬Í¨¹ý¶ÓÁÐÀ´¿ØÖƶÁÊý¾Ý¿âд»º´æµÄÏß³ÌÊýÁ¿¡£±ÈÈç¶Ôij¸ökeyÖ»ÔÊÐíÒ»¸öÏ̲߳éѯÊý¿âºÍдredis»º´æ£¬ÆäËûÏ̵߳ȴý¡££¨×îºÃµÄ·½·¨£©
3£º²»Í¬µÄkey£¬ÉèÖò»Í¬µÄ¹ýÆÚʱ¼ä£¬Èûº´æʧЧµÄʱ¼äµã¾¡Á¿¾ùÔÈ¡£(ÿ¸öKeyµÄʧЧʱ¼ä¶¼¼Ó¸öËæ»úÖµ)
ÊÂÖУº±¾µØehcache»º´æ+ hystrixÏÞÁ÷&½µ¼¶£¬±ÜÃâMySQL±Àµô
ʺó£ºÀûÓÃredis³Ö¾Ã»¯»úÖƱ£´æµÄÊý¾Ý¾¡¿ì»Ö¸´»º´æ


´ð£ºÇɼǣºÈý¸öÇø±ð
»º´æ»÷´©ÊDZ»¶ñÒâ¹¥»÷Ƶ·±²éѯһÌõÊý¾Ý£¬ÕâÌõÊý¾Ý¸ÕºÃµ½ÆÚ£»---½â¾ö
2£©»º´æ´©Í¸ÊÇredisûÓУ¬Èƹýredis´©Í¸µ½ÁËmysql----½â¾ö
ͨÓõĽâ¾ö·½°¸£º
?


setRedis£¨Key£¬value£¬time + Math.random() * 10000£©£»

4¡£ÈȵãÊý¾ÝÓÀÔ¶²»¹ýÆÚ(¹þ¹þ£¬²»Ì«¿ÉÈ¡£©
5£ºEhcache×ö¶þ¼¶»º´æ£¬A1Ϊԭʼ»º´æ£¬A2Ϊ¿½±´»º´æ£¬A1ʧЧʱ£¬¿ÉÒÔ·ÃÎÊA2£¬A1»º´æʧЧʱ¼äÉèÖÃΪ¶ÌÆÚ£¬A2ÉèÖÃΪ³¤ÆÚ£¨´ËµãΪ²¹³ä£©


¾Ù¸ö¼òµ¥µÄÀý×Ó£ºÎÒÁ˽âµÄ£¬Ä¿Ç°µçÉÌÊ×Ò³ÒÔ¼°ÈȵãÊý¾Ý¶¼»áÈ¥×ö»º´æ £¬Ò»°ã»º´æ¶¼ÊǶ¨Ê±ÈÎÎñȥˢУ¬»òÕßÊDz鲻µ½Ö®ºóÈ¥¸üеģ¬µ«ÊÇÓÐÒ»¸öÎÊÌâ¡£Èç¹ûËùÓÐÊ×Ò³µÄKeyʧЧʱ¼ä¶¼ÊÇ12Сʱ£¬ÖÐÎç12µãˢеģ¬ÎÒÁãµãÓиöÃëɱ»î¶¯´óÁ¿Óû§Ó¿È룬¼ÙÉ赱ʱÿÃë 6000 ¸öÇëÇ󣬱¾À´»º´æÔÚ¿ÉÒÔ¿¸×¡Ã¿Ãë 5000 ¸öÇëÇ󣬵«ÊÇ»º´æµ±Ê±ËùÓеÄKey¶¼Ê§Ð§ÁË¡£´Ëʱ 1 Ãë 6000 ¸öÇëÇóÈ«²¿ÂäÊý¾Ý¿â£¬Êý¾Ý¿â±ØÈ»¿¸²»×¡£¬Ëü»á±¨Ò»Ï¾¯£¬ÕæʵÇé¿ö¿ÉÄÜDBA¶¼Ã»·´Ó¦¹ýÀ´¾ÍÖ±½Ó¹ÒÁË¡£´Ëʱ£¬Èç¹ûûÓÃʲôÌرðµÄ·½°¸À´´¦ÀíÕâ¸ö¹ÊÕÏ£¬DBA ºÜ׿±£¬Ö*ôÊý¾Ý¿â£¬µ«ÊÇÊý¾Ý¿âÁ¢ÂíÓÖ±»ÐµÄÁ÷Á¿¸ø´òËÀÁË¡£Õâ¾ÍÊÇÎÒÀí½âµÄ»º´æÑ©±À¡£Í¬Ò»Ê±¼ä´óÃæ»ýʧЧ£¬ÄÇһ˲¼äRedis¸úûÓÐÒ»Ñù£¬ÄÇÕâ¸öÊýÁ¿¼¶±ðµÄÇëÇóÖ±½Ó´òµ½Êý¾Ý¿â¼¸ºõÊÇÔÖÄÑÐԵģ¬ÄãÏëÏëÈç¹û´ò¹ÒµÄÊÇÒ»¸öÓû§·þÎñµÄ¿â£¬ÄÇÆäËûÒÀÀµËûµÄ¿âËùÓеĽӿڼ¸ºõ¶¼»á±¨´í£¬Èç¹ûû×öÈ۶ϵȲßÂÔ»ù±¾ÉϾÍÊÇ˲¼ä¹ÒһƬµÄ½Ú×࣬ÄãÔõôÖ*ôÓû§¶¼»á°ÑÄã´ò¹Ò£¬µÈÄãÄÜÖ*ôµÄʱºò£¬Óû§Ôç¾Í˯¾õÈ¥ÁË£¬²¢ÇÒ¶ÔÄãµÄ²úƷʧȥÁËÐÅÐÄ£¬Ê²Ã´À¬»ø²úÆ·¡£


£¿»º´æ´©Í¸ÊÇʲô£¿½â¾ö·½°¸£¿£¨²¢·¢²éÊý¾Ý¿â£¬¸ã»µÊý¾Ý¿â£©£¿

´ð£ºRedis»º´æ´©Í¸£º±ÈÈçÓû§²éѯÊý¾Ý£¬±¾ÉíûÓд´½¨¹ýÊý¾Ý£¬ÔÚ»º´æÖе±È»Ò²ÕÒ²»µ½£¬±ÈÈ磬idΪ¡°-1¡±Ã¿´Î¶¼ÒªÈ¥Êý¾Ý¿âÔÙ²éѯһ±é£¨µÍЧµØ²éÁ½´Î£¬Ö®ºó»¹Æµ·±À´²é£¬ÕâÑù¾Í¶à´Î´©¹ý»º´æ£¬¸øÊý¾Ý¿âÔö¼ÓѹÁ¦£©£¬È»ºó·µ»Ø¿Õ¡£ÕâÑùÇëÇó¾ÍÈƹý»º´æÖ±½Ó²éÊý¾Ý¿â£¬ÕâÒ²ÊǾ­³£ÌáµÄ»º´æÃüÖÐÂÊÎÊÌâ¡¢
´ð£º


1¡¢Èç¹û²éѯÊý¾Ý¿âҲΪ¿Õ£¬Ö±½ÓÉèÖÃÒ»¸öĬÈÏÖµ´æ·Åµ½»º´æ£¨-999£¬unkown£©,ÕâÑùµÚ¶þ´Îµ½»º³åÖлñÈ¡¾ÍÓÐÖµÁË£¬¶ø²»»á¼ÌÐø·ÃÎÊÊý¾Ý¿â£¬ÕâÖÖ°ì·¨×î¼òµ¥´Ö±©¡£(±ÈÈçÎÒÃǶ¼ÒªÈ¥²éÓû§ÐÅÏ¢ÊÇ·ñ´æÔÚ£¬²»´æÔÚ£¬¾Í±ê¼ÇΪnotfound£¬´æÈ뻺´æ£¬Ï´ÎÔÙÕÒ²»µ½¾Í·µ»ØÕâ¸ö»º´æÀïµÄ±ê¼Ç×÷ΪÕÒ²»µ½µÄ±êʶ£¬²»»á²éÊý¾Ý¿â)
×¢Ò⣺ÔÙ¸ø¶ÔÓ¦µÄip´æ·ÅÕæÖµµÄʱºò£¬ÐèÒªÏÈÇå³ý¶ÔÓ¦µÄ֮ǰµÄ¿Õ»º´æ¡£
2¡¢×î³£¼ûµÄÔòÊDzÉÓò¼Â¡¹ýÂËÆ÷£¬½«ËùÓпÉÄÜ´æÔÚµÄÊý¾Ý¹þÏ£µ½Ò»¸ö×ã¹»´óµÄbitmapÖУ¬Ò»¸öÒ»¶¨²»´æÔÚµÄÊý¾Ý»á±»Õâ¸öbitmapÀ¹½Øµô£¬´Ó¶ø±ÜÃâÁ˶Եײã´æ´¢ÏµÍ³µÄ²éѯѹÁ¦
?


£¿ÈȵãkeyÊÇʲô£¿½â¾ö·½°¸£¿£¨²¢·¢´æredis£¬¸ã»µredis£©

´ð£ºÈȵãkey¼´Ê§Ð§Èȵã·ÃÎʲ¢·¢:±ÈÈ磬µ±Ä³¸ökeyʧЧµÄʱºò£¬ÓдóÁ¿Ïß³ÌÀ´·ÃÎʲéѯ£¬¸ÕºÃ¶¼´ÓÊý¾Ý¿â»ØÀ´²éµ½Êý¾Ý£¬Í¬Ê±È¥redis¹¹½¨»º´æ£¬µ¼Ö¸ºÔØÔö¼Ó£¬ÏµÍ³±ÀÀ£¡£


´ð£º½â¾ö°ì·¨£º


¢ÙʹÓÃËø£¬µ¥»úÓÃsynchronized,lockµÈ£¬·Ö²¼Ê½Ó÷ֲ¼Ê½Ëøzk£¬Ö»ÔÊÐíÒ»¸öÏ̲߳éѯÊý¿âºÍдredis»º´æ¡£


¢Ú»º´æ¹ýÆÚʱ¼ä²»ÉèÖ㬶øÊÇÉèÖÃÔÚkey¶ÔÓ¦µÄvalueÀï¡£Èç¹û¼ì²âµ½´æµÄʱ¼ä³¬¹ý¹ýÆÚʱ¼äÔòÒì²½¸üлº´æ¡£


¢ÛÔÚvalueÉèÖÃÒ»¸ö±È¹ýÆÚʱ¼ät0СµÄ¹ýÆÚʱ¼äÖµt1£¬µ±t1¹ýÆÚµÄʱºò£¬ÑÓ³¤t1²¢×ö¸üлº´æ²Ù×÷¡£


4¡¢¹ýÆÚʱ¼äºóÃæ´øÉÏһЩֵ


£¿ÄãÃÇÈçºÎ½â¾ö·Ö²¼Ê½¶¨Ê±ÈÎÎñÃݵÈÐÔÖظ´ÐԵģ¿

redis·Ö²¼Ê½Ëø£¬·¢ÏÖ´æÔÚÁË£¬¾ÍÌø¹ý


¡¢


£¿redis·Ö²¼Ê½ËøÔ­ÀíÓëʵÏÖ£¿

¹ý³Ì·ÖÎö£º


1¡¢Aͨ¹ýsetnx(lockkey,currenttime+timeout)ÃüÁ¶Ôlockkey½øÐÐsetnx,½«valueÖµÉèÖÃΪµ±Ç°Ê±¼ä+Ëø³¬Ê±Ê±¼ä£»
2¡¢Èç¹û·µ»ØֵΪ1£¬ËµÃ÷Ç°ÃæûÓÐÈË£¬Ò²¾ÍÊÇûÓÐÆäËûÓû§ÓµÓÐÕâ¸öËø£¬A¾ÍÄÜ»ñÈ¡Ëø³É¹¦£»
3¡¢AÍê³Éºó£¬ÒªÊÍ·ÅÓµÓеÄËø£¬del(lockkey)£¬Ò²¾ÍÊÇɾ³ýredisÖиÃËøµÄÄÚÈÝ£¬½ÓÏÂÀ´µÄÓû§²ÅÄܽøÐÐÖØÐÂÉèÖÃËøÐÂÖµ¡£


redis 5ÖÖ»ù±¾ÀàÐÍʵÏÖÔ­Àí

https://my.oschina.net/u/3847203/blog/3022900
List -----Ë«ÏòÁ´±í£¨ÔªËظöÊýºÍµ¥¸öÔªËصij¤¶È±È½ÏСµÄʱºòÓÃziplist£¨Ñ¹ËõÁÐ±í£©£©£¬quicklist=linkedlist+ziplist
Hash -----hashtable£¬ÁíÒ»ÖÖÊÇÇ°Ãæ½²µÄziplist£¬
Set -----µ×²ãÊý¾Ý½á¹¹ÒÔintset»òÕßhashtableÀ´´æ´¢
?Sorted Set -----ÒÔziplist»òÕßskiplist+hashtableÀ´ÊµÏÖ


£¿redis¶¨Ê±È¡Ïû¶©µ¥»¹Ô­¿â´æ£¬ÑÓʱ²Ù×÷µÄÔ­Àí£¨¶©ÔÄPub/SubƵµÀ £©£¿

ÔÚ¶©µ¥Éú²úʱ£¬ÉèÖÃÒ»¸ökey£¬Í¬Ê±ÉèÖÃ10·ÖÖÓºó¹ýÆÚ£¬ ÎÒÃÇÔÚºǫ́ʵÏÖÒ»¸ö¼àÌýÆ÷£¬¼àÌýkeyµÄʵЧ£¬¼àÌýµ½keyʧЧʱ½«ºóÐøÂß¼­¼ÓÉÏ¡£ µ±È»ÎÒÃÇÒ²¿ÉÒÔÀûÓÃrabbitmq¡¢activemqµÈÏûÏ¢Öмä¼þµÄÑÓ³Ù¶ÓÁзþÎñʵÏÖ¸ÃÐèÇó¡£


£¿µãÔÞÅÅÃû¡¢ºÃÓÑÁбíµÄÔ­Àí£¨set--sismember/sadd £©£¿

Ò»¡¢µãÔÞÅÅÃû»¹ÊÇʹÓÃzsetºÃÒ»µã£¬Èç¹ûûÓÐÅÅÃûÒ²¿ÉÒÔÓÃset;
¶þ¡¢ºÃÓÑÁбíÖ»ÐèÒª¿¼ÂÇÈ¥ÖØ£¬ÓÃset;ÈçÏ£º
sismember?ÎÒµÄID?ºÃÓÑID? ?£¨Èç¹û´æÔڻ᷵»ØºÃÓÑÐÅÏ¢£¬¾Í²»ÒªÔÚ²åÈëÁË£©


?


£¿redis¶ÔÕËÕÒ²îÒìµÄÔ­Àí£¨set--sinterstore¡¢sdiffstore£©£¿

1¡¢·Ö±ðµÃµ½ÎÒ·½µÄ½»Ò×¼¯ºÏset1ºÍÈý·½µÄ½»Ò×¼¯ºÏset2¡£
£¬±íʾ¸øÎÒ·½Ìí¼ÓÁ½¸ö¶©µ¥½øredisÕâ¸ö{account}:localSet¼¯ºÏ¡£{account}ÕâÑùдÊÇΪÁ˼¯Èºµ½Í¬Ò»¸ö²ÛÀ¼¯ÈºÖ»¿´{}ÀïÃæµÄÖµ¡£
2¡¢È»ºóʹÓÃredisµÄsinterstore¹¦ÄܶÔÁ½¸öSET¼¯ºÏ½øÐн»¼¯µÃµ½sinter1¼¯ºÏ£¬
3¡¢°ÑÈý·½ÕËÎñ¼¯ºÏÓëÎÒ·½¼Ç¼¼¯ºÏ·Ö±ðºÍ½»¼¯½á¹û±È½Ï£¬
4¡¢È»ºó°Ñ²î¼¯ÄóöÀ´£¬

Öð¸ö¶Ô±ÈÒ»ÏÂÁ½¸ö¼¯ºÏ¾ßÌå´íÔÚÄÄ£¬¼Ç¼²îÒìÕË£¬µÈ´ýÈ˹¤ÉóºË¡£Èç¹ûÊÇÎÒ·½µ¥±ß¶àÕË£¬¿ÉÄÜÊÇÈý·½»¹Î´½áË㣬ÕâÖÖ»áµÈµÚ¶þÌì¶ÔÕË·¢ÏÖÈý·½µ¥±ß¶àÕË£¬ÔÙÀ´²éÒ»ÏÂÇ°Ò»ÌìµÄ¶ÔÕ˽á¹ûÀïÊÇ·ñÓжàµÄ¼Ç¼£¬Èç¹ûÓоÍĨµô£¬Ã»ÓоÍÊDzîÕË£¨¿ÉÄÜÊÇ©¼Ç£©¡£


?


£¿redisʵʱÅÅÐаñµÄÔ­Àí£¨zset--zunionstore£©£¿

¾ÙÀý£¬ÉÌÆ·ÊÕ²ØÔÂÅÅÐаñʵÏÖ¡£
(Ê×´ÎÈç¹ûÐèÒªÌí¼Ó£¬Ê¹ÓÃÓï¾ä£ºzadd rank:202001 3 ÉÌÆ·ID1?5 ÉÌÆ·ID2 £¬±íʾ¸øÁ½¸öÉÌÆ·³õʼ3ºÍ5µÄÊÕ²ØÊý)
1¡¢´´½¨ÊղصÄʱºò£¬¼¯ºÏÃû³Æ=ÉÌÆ·_µ±Ç°ÄêÔ£¬Ôö¼Ó¼õÉÙÓï¾ä(²»´æÔÚ¾ÍÐÂÔö)£º
±ÈÈç?zincrby? rank:202001 1 ÉÌÆ·ID1? ?£¬±íʾ¸ÃÉÌÆ·ID1ÀÛ¼ÓÒ»¸öÊղأ¬Èç?zincrby?rank:202001 1 ÉÌÆ·ID2? ?£¬±íʾ¸ÃÉÌÆ·ID2Ôö¼ÓÒ»¸öÊÕ²Ø
2¡¢»ñÈ¡×ÔÈ»ÔÂÅÅÐаñÇ°10µÄ·½·¨ÈçÏ£¬zrange? rank:202001 0 9 withscores£¬µ¹Ðò£»zrevrange rank:202001 0 9 withscores£¬ÉýÐò
3¡¢Èç¹ûҪͳ¼ÆÈÕ°ñ£¬¾ÍÖØн¨Ò»¸öÓÐÐò¼¯ºÏ£¬Ãû³ÆÒÔrank:20200101¿ªÍ·¡£
Èç¹ûÊÇÖÜ°ñ£¬¾ÍµÃËãÊÇÄÄÖÜÁË£¬Ëãµ½ÄÄÖܵķ½·¨£ºnew SimpleDateFormat("yyyy-MM-dd").applyPattern("W").format(date);//ËãÒ»ÔÂÖеĵڼ¸ÖÜ
4.Èç¹ûÊÇʵʱÖÜÆÚÐÔ£¬´Óµ±Ç°Ê±¼äÖÁÇ°ÃæÒ»ÖÜÄÚ£¬ÄǾ͵ÃÓãºzunionstore ·ÅÈëм¯ºÏµÄÃû³Æ?³ÉÔ±¸öÊý Ô­¼¯ºÏ1Ãû³Æ Ô­¼¯ºÏ2Ãû³Æ Ô­¼¯ºÏ3Ãû³Æ weights 1 1 1 £¬±íʾºÏ²¢3¸öÔ­¼¯ºÏÖÁм¯ºÏÀȨÖض¼ÊÇ1£¨weights ȨÖØ¿ÉÒÔ²»ÉèÖã¬Ä¬ÈϾÍÊÇ1£©£¬Ã¿¸ö¼¯ºÏÖÐÏàͬµÄÉÌÆ·IDÒòΪÊÇΨһµÄ£¬ËùÒÔ¶ÔÓ¦µÄÊÕ²ØÊý»á¼ÓÏàµÄ
¼ÆËã¸ø¶¨µÄÒ»¸ö»ò¶à¸öÓÐÐò¼¯µÄ²¢¼¯£¬²¢´æ´¢ÔÚеÄ?key?ÖÐ
ʵʱÖÜ°ñ»ñÈ¡·½·¨£º
1£©zunionstore rank:last_week 7 rank:20200101 rank:20200102 rank:20200103 rank:20200104 rank:20200105 rank:20200106 rank:20200107 WEIGHTS 1 1 1 1 1 1 1
2£©ÊµÊ±Ô°ñ»ñÈ¡·½·¨£¬Ò²ÓÃzunionstore £¬°Ñ×î*Ò»¸öÔµÄÿÌìµÄ¸ø²¢¼¯ÔÚÒ»Æð¡£
Èç¹ûÒª¾«È·µ½ÃëµÄ»°£¬ÄÇÖ»ÄÜ°´Ãë´æÁË£¬ÔÙ²¢¼¯Ãë

£¿redisÃëɱ¼õ¿â´æ£¬¼¯Èº¸ß²¢·¢µÄÔ­Àí£¨Áбí(¶ÓÁÐÐÔÖÊ)list--rpush¡¢lpop£¬Hash---hset £©£¿Hash£¨ÉÌÆ·¼°¹æ¸ñ-Óû§-ÊýÁ¿£©

¸ßÐÔÄÜϵͳµÄÓÅ»¯Ô­Ôò£ºÐ´ÈëÄÚ´æ¶ø²»ÊÇдÈëÓ²ÅÌ£¬Òì²½´¦Àí¶ø²»ÊÇͬ²½´¦Àí£¬·Ö²¼Ê½´¦Àí
1¡¢ZKʵÏֵķֲ¼Ê½¼ÆÊýÆ÷DistributedAtomicInteger´æ¿â´æ£¬µ½ÁË100¸ö¾ÍÀ¹½Ø
2¡¢list´æÇÀ¹º³É¹¦µÄÓû§ÐÅÏ¢¼°ÉÌÆ·ÐòºÅ¡£
rpush key value£¬²åÈëÃëɱÇëÇó¡£È»ºó¿ìËÙ·µ»Ø¡£
lpop key£¬£¨Òì²½£©¶ÁÈ¡Ãëɱ³É¹¦Õߣ¬ÒÀ´Î×öϵ¥ºóÐø´¦Àí¡£
1¡¢list´æ¿â´æ£¬½«¿â´æ100ÏȷŽøÒ»¸öredisµÄlist½á¹¹ÖУ¬À´Ò»¸öÓû§popÒ»¸ö£¬Ö±µ½×îºópop³öµÚ100¸öÃëɱ½áÊø¡£Ìáʾ¡°ÇÀ¹âÁË£¡¡±pop³É¹¦Ôò½øÈëϵ¥Á÷³Ì£¬²åÈëж©µ¥µ½Êý¾Ý¿â£¬³õʼ״̬0δ֧¸¶£¨0£ºÎ´Ö§¸¶ 1£ºÒÑÖ§¸¶£¬2£º30minÒѹýÆÚ£©¡£¶ÔÓÚ¹ýÆÚµÄÔò¹é»¹¿â´æµ½redisµÄ¿â´ælistÖеȴýpop¡£ÃüÁîÈçÏ£º
rpush key value£¬²åÈë¿â´æ¡£
lpop key£¬¼õ¿â´æ¡£
2¡¢HashÀ´´æ·ÅÇÀ¹º³É¹¦µÄÓû§ID£¬·ÀÖ¹Öظ´ÇÀ¹ºË¢µ¥£¨ÉÌÆ·key->(Óû§key,val)£©¡£µÈµ½£¬ÃüÁîÈçÏ£º
hset ?ÉÌÆ·key Óû§key?MapValue? £¨Èç¹û´æÔڻḲ¸Ç£¬µ«·µ»Ø0£©£¨HSETNX key field value
---×îºÃÓÃÕâ¸öÃüÁֻÓÐÔÚ×ֶΠfield ²»´æÔÚʱ£¬ÉèÖùþÏ£±í×ֶεÄÖµ³É¹¦·µ»Ø1£¬·ñÔò·µ»Ø0¡££©
£¨Èç¹ûÒ»ÈËÄÜÇÀ5´ÎµÄ»°£¬¾Í°ÑmapÀïµÄvalue´æÀÛ¼ÆÇÀµ½µÄÊýÁ¿£©
3¡¢list´æÇÀ¹º³É¹¦µÄÓû§ÐÅÏ¢¼°ÉÌÆ·ÐòºÅ¡££¨×îºÃÓÃmqÀ´Òì²½´¦Àí£¬Í³Ò»Ïû·Ñ£¬ÉÌÆ·ÀàÐÍÇø·Ö²»Í¬ÉÌÆ·£©
rpush key value£¬²åÈëÃëɱÇëÇó¡£È»ºó¿ìËÙ·µ»Ø¡£
lpop key£¬£¨Òì²½£©¶ÁÈ¡Ãëɱ³É¹¦Õߣ¬ÒÀ´Î×öϵ¥ºóÐø´¦Àí¡£
4¡¢È¡ÏûµÄ²¹³¥ÓÃMQÑÓ³Ù¶ÓÁУ¬»ò×Ô¶¨Òå´úÂ붨ʱȥ²éskuID¶ÔÓ¦µÄredis¹ýÆÚʱ¼ä


£¨stringÀàÐÍÈç¹ûvalueÊÇIntµÈÊý¾ÝÀàÐÍ£¬¿ÉÒÔÓÃIncrby key 2 //ʵÏÖ¼Ó2
,decrby key 1 //ÊǼõ£©


£¿redis¹ºÎï³µ»ù±¾¹¦ÄÜ£¬¼¯Èº¸ß²¢·¢µÄÔ­Àí£¨Áбí(¶ÓÁÐÐÔÖÊ)list--rpush¡¢lpop£¬Hash---hset £©£¿Hash£¨Óû§-ÉÌÆ·¼°¹æ¸ñ-ÊýÁ¿£©

spu£¨ÉÌÆ·£©ºÍsku£¨¹æ¸ñµ¥Æ·£©


ÉÌÆ··ÖÀà±í--mmall_categoryÉÌÆ·±í--------mmall_productÉÌÆ·¹æ¸ñ±í--mmall_product_specsÊôÐÔkey±í---mmall_attribute_keyÊôÐÔvalue±í-mmall_attribute_value
²Î¿¼£ºhttps://www.cnblogs.com/jiqing9006/p/10535974.html

hset ´æ/Ð޸ģºhset appid:openid:cart 3:1 10? (hset Óû§IDÏà¹Ø ?spu_id:sku_id? ?ÊýÁ¿)
hgetall È¡ËùÓÐ:hgetall appid:openid:cart
hdel ɾ³ý£ºhdel appid:openid:cart 3:1
hincrby Ôö¼Ó£¬¼õÉÙ:hincrby appid:openid:cart 3:1 -1


£¿·¢²¼Ó붩ÔÄ£¨pub/sub£©£¿

¶©ÔÄÒ»¸öƵµÀ£ºsubscribe? ?ƵµÀÃû
ͨ¹ýÃüÁîpublishÏòƵµÀ·¢ËÍÐÅÏ¢£ºpublish???ƵµÀÃû? ? ¡°ÏûÏ¢¡±






Èç¹û¶Ô·½¾¿¼«TM×·ÎÊRedisÈçºÎʵÏÖÑÓʱ¶ÓÁУ¿(zset--zadd¡¢zrangebyscore)--Á½ÖÖ·½·¨


1.¾«×¼¶ÈÒªÇó¸ß
.ÑÓʱ¶ÓÁУºÊ¹ÓÃsortedset£¬ÄÃʱ¼ä´Á×÷Ϊscore£¬ÏûÏ¢ÄÚÈÝ×÷Ϊkeyµ÷ÓÃzaddÀ´Éú²úÏûÏ¢£¬Ïû·ÑÕßÓÃzrangebyscoreÖ¸Áî»ñÈ¡NÃë֮ǰµÄʱ¼ä´ÁÊý¾ÝÂÖѯ½øÐд¦Àí£º
zadd??ijµãÇ°µÄʱ¼ä´ÁlongÖµ?key?
zrangebyscore key -inf ijµãÇ°µÄʱ¼ä´ÁlongÖµ


2.1.¾«×¼¶ÈÒªÇóµÍ£¬Ò×ʵÏÖ


zrangebyscore ÊÇÖ¸Öµ£º
zrangebyscore key -inf ʱ¼ä´ÁlongÖµ//СÓÚµÈÓÚ? £¬-inf±íʾ¸ºÎÞÇî´ó
zrangebyscore key ʱ¼ä´ÁlongÖµ? +inf //´óÓÚµÈÓÚ£¬»ùÓÚÕâ¸öÓï·¨zrangebyscore key min max? ?·µ»ØÓÐÐò¼¯ºÏÖÐÖ¸¶¨·ÖÊýÖµÇø¼äµÄ³ÉÔ±Áбí


?


£¿redis³Ö¾Ã»¯Ô­Àí£¿½áºÏ?redis å´»úÁËÔÙÖ*ô˵Ã÷һϴ¦Àí¹ý³Ì£¿£¨£©

Ò»¡¢³Ö¾Ã»¯Ô­Àí£º£¨Æô¶¯Ê±»áÏȼì²éAOFÎļþÊÇ·ñ´æÔÚ£¬Èç¹û²»´æÔھͳ¢ÊÔ¼ÓÔØRDB£©¡£
redis ³Ö¾Ã»¯µÄÁ½ÖÖ·½Ê½£¬RDB£ºRDB ³Ö¾Ã»¯»úÖÆ£¬ÊÇ¶Ô redis ÖеÄÊý¾ÝÖ´ÐÐÖÜÆÚÐԵij־û¯£¬»Ö¸´Ëٶȿ죬¶ªÊ§¶à¡£AOF£ºAOF »úÖƶÔÿÌõдÈëÃüÁî×÷ΪÈÕÖ¾£¬£¬»Ö¸´ËٶȿìÂý£¬ÈÕÖ¾Îļþ´ó£¬¶ªÊ§ÉÙ¡£
¶þ¡¢redis å´»úÁËÔÙÖ*ô£ºÈç¹û redis å´»úÖ*ô£¬×Ô¶¯´Ó´ÅÅÌÉϼÓÔØÔöÁ¿ÈÕÖ¾ÎļþAOF»Ö¸´Êý¾Ý£¬Èç¹ûAOFË𻵻ò»Ö¸´¹ÊÕÏ£¬»á´ÓRDBÈÕÖ¾¿ìÕÕÀïÄõ½Êý¾Ý»Ö¸´¡£

£¿redis å´»úÔõô°ì£¬Ôõô±£³ÖÊý¾ÝÒ»ÖÂÐÔ£¿*ʱû崻úÄØ£¬Ôõô±£³ÖÊý¾ÝÒ»ÖÂÐÔ£¿

´ð1£º1£©redisÓг־û¯£¬Æô¶¯Ê±»áÏȼì²éAOFÎļþÊÇ·ñ´æÔÚ£¬Èç¹û²»´æÔھͳ¢ÊÔ¼ÓÔØRDB£¬»Ö¸´Êý¾Ý¡£
2£©Èç¹ûÄãµÄϵͳ²»ÊÇÑϸñÒªÇ󻺴æ+Êý¾Ý¿â±ØÐëÒ»ÖÂÐԵĻ°£¬¾ÍÖ*ô¾ÍºÃÁË¡£
´ð2£º
1£©Èç¹ûÄãµÄϵͳ²»ÊÇÑϸñÒªÇ󻺴æ+Êý¾Ý¿â±ØÐëÒ»ÖÂÐԵĻ°£¬²»ÓÃÓÅ»¯¡£¶¨Ê±ÈÎÎñɨÃè»áÖØÖ᣻òcannal¶©¿öMYSQL¸ü×¼¡£
2£©redis¶ÁÐд®Ðл¯£¬´®µ½Ò»¸öÄÚ´æ¶ÓÁÐÀïÈ¥£¬ÕâÑù¾Í¿ÉÒÔ±£Ö¤Ò»¶¨²»»á³öÏÖ²»Ò»ÖÂ
µÄÇé¿ö----µ¼ÖÂϵͳµÄÍÌÍÂÁ¿»á´ó·ù¶ÈµÄ½µµÍ£¬¼Ó»úÆ÷ÁË


?


Êý¾ÝÔõôÖ÷´Óͬ²½µÄÄØ£¿

slaveÆô¶¯£¬»á·¢ËÍÒ»¸öpsyncÃüÁî¸ømaster £¬
1£©Èç¹ûÊǵÚÒ»´ÎÁ¬½Óµ½master£¬Ëû»á´¥·¢È«Á¿¸´ÖÆ¡£master¾Í»áÆô¶¯Ò»¸öỊ̈߳¬Éú³ÉRDB¿ìÕÕ£¬Í¬²½¸ø´Ó½Úµã¡£slaveдÈëRDBÖÁ±¾µØ¡£
2)Ö®ºómaster»á°ÑеÄдÇëÇóÃüÁͬ²½¸øslave£¬¼´aofͬ²½¡£


?
--------------RedisÀïÃæËùÓеÄkeyʱ¼ä¹ýÆÚÁËÔõô´¦ÀíµÄ£¿£¨TTLÇå³ý²ßÂÔÓëÄÚ´æÌÔÌ­²ßÂÔÈçLRU£©------------
ÇɼǣºttlºÍlru

Ö÷½áµã¡±del key¡±Í¬²½µ½´Ó½áµã¡£


Ò»¡¢RedisµÄTTLɾ³ý²ßÂÔ£¨¹ýÆÚ²ßÂÔ/Çå³ý²ßÂÔ£©£¬ÊÇÓж¨ÆÚɾ³ý+¶èÐÔɾ³ýÁ½ÖÖ¡£

¶¨ÆÚɾ³ý£¬ºÃÀí½â£¬Ä¬ÈÏ100s¾ÍËæ»ú³éһЩÉèÖÃÁ˹ýÆÚʱ¼äTTLµÄkey£¬È¥¼ì²éÊÇ·ñ¹ýÆÚ£¬¹ýÆÚÁ˾ÍɾÁË¡££¨Çɼǣº100m³éÑù³å´Ì£¬¹ýÆÚɾ³ý£©

¶þ¡¢ÄÚ´æÌÔÌ­²ßÂÔ»úÖÆÈçLRU£¡£¨ÄÚ´æÂúµÄʱºò´¥·¢/³¬¹ý×î´óãÐÖµÁ¿£©

¹ÙÍøÉϸøµ½µÄÄÚ´æÌÔÌ­»úÖÆÊÇÒÔϼ¸¸ö£º
? ? ? ? ? ?1£ºÍ¨¹ýLRUËã·¨£¬´ÓËùÓÐkey£¬ÇýÖð×î¾ÃûÓÐʹÓõļü (×î¾Ã-)--ÌÔÌ­×î*×îÉÙʹÓÃ
? ? ? ? ? ? 2£º´ÓÉèÖÃÁ˹ýÆÚʱ¼äµÄkey¼¯ºÏÖУ¬ÇýÖð×î¾ÃûÓÐʹÓõļü(×î¾Ã-)
?? ??? ??? ?3£ºÄÚ´æ²»¹»£¬Ð´¾Í±¨´í(ÄÚ´æ-)
?? ??? ??? ?4£º´ÓËùÓÐkey£¬Ëæ»úɾ³ý(Ëæ»ú-)
?? ??? ??? ?5£º´Ó¹ýÆÚkeyµÄ¼¯ºÏÖУ¬Ëæ»úÇýÖð(Ëæ»ú-)
?? ??? ??? ?6£º´ÓËùÓÐkey£¬ÇýÖðʹÓÃƵÂÊ×îÉٵļü(ƵÂÊ-)?
?? ??? ??? ?7£º´ÓËùÓÐÅäÖÃÁ˹ýÆÚʱ¼äµÄkey¼¯ºÏÖУ¬ÇýÖðʹÓÃƵÂÊ×îÉٵļü(ƵÂÊ-)
?? ??? ??? ?8£º´ÓÅäÖÃÁ˹ýÆÚʱ¼äµÄ¼üÖÐÇýÖðÂíÉϼ´½«¹ýÆڵļü(¼´½«¹ýÆÚ-)
noeviction:·µ»Ø´íÎóµ±ÄÚ´æÏÞÖÆ´ïµ½²¢ÇÒ¿Í»§¶Ë³¢ÊÔÖ´ÐлáÈøü¶àÄڴ汻ʹÓõÄÃüÁ´ó²¿·ÖµÄдÈëÖ¸Áµ«DELºÍ¼¸¸öÀýÍ⣩
allkeys-random: »ØÊÕËæ»úµÄ¼üʹµÃÐÂÌí¼ÓµÄÊý¾ÝÓпռä´æ·Å¡£
volatile-random: »ØÊÕËæ»úµÄ¼üʹµÃÐÂÌí¼ÓµÄÊý¾ÝÓпռä´æ·Å£¬µ«½öÏÞÓÚÔÚ¹ýÆÚ¼¯ºÏµÄ¼ü¡£
volatile-ttl: »ØÊÕÔÚ¹ýÆÚ¼¯ºÏµÄ¼ü£¬²¢ÇÒÓÅÏÈ»ØÊÕ´æ»îʱ¼ä£¨TTL£©½Ï¶ÌµÄ¼ü,ʹµÃÐÂÌí¼ÓµÄÊý¾ÝÓпռä´æ·Å¡£
Èç¹ûûÓмüÂú×ã»ØÊÕµÄÇ°ÌáÌõ¼þµÄ»°£¬²ßÂÔvolatile-lru, volatile-randomÒÔ¼°volatile-ttl¾ÍºÍnoeviction ²î²»¶àÁË¡£


ÊÖдLru:

ÖØдLinkedHashMapµÄÅжÏÊÇ·ñremoveµÄÌõ¼þ£¬¸Ä³ÉÈÝÁ¿>100£¬¾Í×ßĬÈÏɾ³ý×îÉÙʹÓõļü


? 2.1 redis ¿Í»§¶Ë

? ? ´ð£ºLettuce £¨springbootĬÈÏʹÓõĿͻ§¶Ë£©£¬Jedis
?? ?jedisºÍlettuceÓÐʲôÇø±ð£º
?? ?jedis²ÉÓõÄÊÇÖ±Á¬redis server£¬µ¥jedisʵÀýʱ£¬ÊÇÏ̲߳»°²È«µÄ£¨·¢ËÍÃüÁîºÍ»ñÈ¡·µ»ØֵʱʹÓÃÈ«¾Ö±äÁ¿RedisOutputStreamºÍRedisInputStream£©¡£ÒªÊ¹ÓÃÁ¬½Ó³Øpool(ÅäÖÃÒýÓÃjedis.pool¼´¿É)£¬ÕâÑùÿ¸öÏ̵߳¥¶ÀʹÓÃÒ»¸öjedisʵÀý¡£ÓÉ´Ë´øÀ´µÄÎÊÌâʱ£¬Èç¹ûÏß³ÌÊý¹ý¶à£¬´øÀ´redis serverµÄ¸ºÔؼӴó¡£ÓеãÀàËÆÓÚBIOµÄģʽ¡£


lettuce²ÉÓÃnettyÁ¬½Óredis server£¬ÊµÀý¿ÉÒÔÔÚ¶à¸öÏ̼߳乲Ïí£¬²»´æÔÚÏ̲߳»°²È«µÄÇé¿ö£¬ÕâÑù¿ÉÒÔ¼õÉÙÏß³ÌÊýÁ¿¡£µ±È»£¬ÔÚÌØÊâÇé¿öÏ£¬lettuceÒ²¿ÉÒÔʹÓöà¸öʵÀý¡£ÓеãÀàËÆÓÚNIOµÄģʽ


ÐÔÄܲ¶à£¬jedisÁ¬½Ó³Ø±ÈlettuceÈõÒ»µã


?redis¸ßΣÃüÁî

? ? ´ð£º


?


redisºÍmemcached¶Ô±È£¬ÓÐʲôÓŵ㣿


µ¥»ú¶ÁËÙ¶È11w/s£¬Ð´ËÙ¶È8.1W/S


ÈçºÎ±£Ö¤redisÓëmysqlÊý¾Ýͬ²½µÄÒ»ÖÂÐÔ?

ÎÞ·¨Ç¿Ö¤Ç¿Ò»ÖÂÐÔ£¬ÒòΪÊý¾Ýͬ²½ÓÐÑÓ³Ù£¬Ò²ÐèҪʱ¼ä£¬µ«¿ÉÒÔ×îÖÕÒ»ÖÂÐÔ¡£


1¡¢ÒÀÀµMQʵÏÖ´®Ðл¯--дÍêMysql°Ñд²Ù×÷ÍùMQ¶ÓÁзţ¬ÒÀ´ÎÈ¥Ö´ÐÐredisÏàͬµÄд²Ù×÷
¶ÁдÇëÇó´®Ðл¯£¬»á½µµÍϵͳÍÌÍÂÁ¿
ÓÅ»¯£º
1.2)½â¾öÒ쳣ʧ°Ü--ÿ´Îд²Ù×÷·ÅMQºó£¬Ö´ÐÐredisÏàͬµÄд²Ù×÷·¢ÉúÒ쳣δ³É¹¦Ê±£¬²Å»»³É´ÓMysql²é×îеģ¬Ë¢ÐÂredis£¬Èç¹û»¹Ê§°Ü£¬¾Í±¨¾¯È˹¤¸ú½ø¡£



2.°¢À↑ԴCana---- Ö±½Ó»ùÓÚbinlogÈÕÖ¾½øÐÐͬ²½
3.zk·Ö²¼Ê½Ëø¶Ôÿ¸öID¶ÔÓ¦µÄ²Ù×÷½øÐд®Ðл¯£¬ÓеãÏñ1·½·¨£¬ÊµÏÖ·½Ê½²»Í¬¶øÒÑ
4¡¢×Ô¶¨Ò嶨ʱÈÎÎñдredis


?


RedisÖв¼Â¡¹ýÂËÆ÷

Redis4.0°æ±¾ÌṩÁ˲å¼þ¹¦ÄÜ--²¼Â¡¹ýÂËÆ÷¡££¨Ö®Ç°µÄ²¼Â¡¹ýÂËÆ÷¿ÉÒÔʹÓÃRedisÖеÄλͼ²Ù×÷ʵÏÖ£©


ȱµã£ºÎóÅС£²»´æÔÚʱ£¨×¼£©£¬ÄÇôÕâÖÖ¶«Î÷Ò»¶¨²»´æÔÚ£»Ä³ÖÖ¶«Î÷´æÔÚʱ£¨²»×¼-ÎóÅУ©£¬ÕâÖÖ¶«Î÷¿ÉÄܲ»´æÔÚ¡£
Óŵ㣺¸ü¸ßЧµØ²åÈëºÍ²éѯ£¬²¢ÇÒÕ¼Óÿռä¸üÉÙ


1¡¢½â¾ö»º´æ´©Í¸µÄÎÊÌâ----µ±ÓÐеÄÇëÇóʱ£¬Ïȵ½²¼Â¡¹ýÂËÆ÷ÖвéѯÊÇ·ñ´æÔÚ£¬Èç¹û²»´æÔÚ¸ÃÌõÊý¾ÝÖ±½Ó·µ»Ø£»Èç¹û´æÔÚ¸ÃÌõÊý¾ÝÔÙ²éѯ»º´æ²éѯÊý¾Ý¿â¡£
1¡¢ºÚÃûµ¥Ð£Ñé----°ÑËùÓкÚÃûµ¥¶¼·ÅÔÚ²¼Â¡¹ýÂËÆ÷ÖУ¬ÔÙÊÕµ½Óʼþʱ£¬ÅжÏÓʼþµØÖ·ÊÇ·ñÔÚ²¼Â¡¹ýÂËÆ÷Öм´¿É


相关推荐


友情链接: