ΪʲôʹÓà Redis¼°Æä²úÆ·¶¨Î»
ת×Ô£ºhttp://www.infoq.com/cn/articles/tq-why-choose-redis
´«Í³MySQL+ Memcached¼Ü¹¹Óöµ½µÄÎÊÌâ
ʵ¼ÊMySQLÊÇÊʺϽøÐк£Á¿Êý¾Ý´æ´¢µÄ£¬Í¨¹ýMemcached½«ÈȵãÊý¾Ý¼ÓÔص½cache£¬¼ÓËÙ·ÃÎÊ£¬ºÜ¶à¹«Ë¾¶¼Ôø¾Ê¹ÓùýÕâÑùµÄ¼Ü¹¹£¬µ«Ëæ×ÅÒµÎñÊý¾ÝÁ¿µÄ²»¶ÏÔö¼Ó£¬ºÍ·ÃÎÊÁ¿µÄ³ÖÐøÔö³¤£¬ÎÒÃÇÓöµ½Á˺ܶàÎÊÌ⣺
- MySQLÐèÒª²»¶Ï½øÐвð¿â²ð±í£¬MemcachedÒ²Ðè²»¶Ï¸ú×ÅÀ©ÈÝ£¬À©ÈݺÍά»¤¹¤×÷Õ¼¾Ý´óÁ¿¿ª·¢Ê±¼ä¡£
- MemcachedÓëMySQLÊý¾Ý¿âÊý¾ÝÒ»ÖÂÐÔÎÊÌâ¡£
- MemcachedÊý¾ÝÃüÖÐÂʵͻòdown»ú£¬´óÁ¿·ÃÎÊÖ±½Ó´©Í¸µ½DB£¬MySQLÎÞ·¨Ö§³Å¡£
- ¿ç»ú·¿cacheͬ²½ÎÊÌâ¡£
ÖÚ¶àNoSQL°Ù»¨Æë·Å£¬ÈçºÎÑ¡Ôñ
×î½ü¼¸Ä꣬ҵ½ç²»¶ÏÓ¿ÏÖ³öºÜ¶à¸÷ÖÖ¸÷ÑùµÄNoSQL²úÆ·£¬ÄÇôÈçºÎ²ÅÄÜÕýÈ·µØʹÓúÃÕâЩ²úÆ·£¬×î´ó»¯µØ·¢»ÓÆ䳤´¦£¬ÊÇÎÒÃÇÐèÒªÉîÈëÑо¿ºÍ˼¿¼µÄÎÊÌ⣬ʵ¼Ê¹é¸ù½áµ××îÖØÒªµÄÊÇÁ˽âÕâЩ²úÆ·µÄ¶¨Î»£¬²¢ÇÒÁ˽⵽ÿ¿î²úÆ·µÄtradeoffs£¬ÔÚʵ¼ÊÓ¦ÓÃÖÐ×öµ½Ñﳤ±Ü¶Ì£¬×ÜÌåÉÏÕâЩNoSQLÖ÷ÒªÓÃÓÚ½â¾öÒÔϼ¸ÖÖÎÊÌâ
- ÉÙÁ¿Êý¾Ý´æ´¢£¬¸ßËÙ¶Áд·ÃÎÊ¡£´ËÀà²úƷͨ¹ýÊý¾ÝÈ«²¿in-momery µÄ·½Ê½À´±£Ö¤¸ßËÙ·ÃÎÊ£¬Í¬Ê±ÌṩÊý¾ÝÂäµØµÄ¹¦ÄÜ£¬Êµ¼ÊÕâÕýÊÇRedis×îÖ÷ÒªµÄÊÊÓó¡¾°¡£
- º£Á¿Êý¾Ý´æ´¢£¬·Ö²¼Ê½ÏµÍ³Ö§³Ö£¬Êý¾ÝÒ»ÖÂÐÔ±£Ö¤£¬·½±ãµÄ¼¯Èº½ÚµãÌí¼Ó/ɾ³ý¡£
- Õâ·½Ãæ×î¾ß´ú±íÐÔµÄÊÇdynamoºÍbigtable 2ƪÂÛÎÄËù²ûÊöµÄ˼·¡£Ç°ÕßÊÇÒ»¸öÍêÈ«ÎÞÖÐÐĵÄÉè¼Æ£¬½ÚµãÖ®¼äͨ¹ýgossip·½Ê½´«µÝ¼¯ÈºÐÅÏ¢£¬Êý¾Ý±£Ö¤×îÖÕÒ»ÖÂÐÔ£¬ºóÕßÊÇÒ»¸öÖÐÐÄ»¯µÄ·½°¸Éè¼Æ£¬Í¨¹ýÀàËÆÒ»¸ö·Ö²¼Ê½Ëø·þÎñÀ´±£Ö¤Ç¿Ò»ÖÂÐÔ,Êý¾ÝдÈëÏÈдÄÚ´æºÍredo log£¬È»ºó¶¨ÆÚcompat¹é²¢µ½´ÅÅÌÉÏ£¬½«Ëæ»úдÓÅ»¯ÎªË³Ðòд£¬Ìá¸ßдÈëÐÔÄÜ¡£
- Schema free£¬auto-shardingµÈ¡£±ÈÈçÄ¿Ç°³£¼ûµÄһЩÎĵµÊý¾Ý¿â¶¼ÊÇÖ§³Öschema-freeµÄ£¬Ö±½Ó´æ´¢json¸ñʽÊý¾Ý£¬²¢ÇÒÖ§³Öauto-shardingµÈ¹¦ÄÜ£¬±ÈÈçmongodb¡£
Ãæ¶ÔÕâЩ²»Í¬ÀàÐ͵ÄNoSQL²úÆ·,ÎÒÃÇÐèÒª¸ù¾ÝÎÒÃǵÄÒµÎñ³¡¾°Ñ¡Ôñ×îºÏÊʵIJúÆ·¡£
RedisÊÊÓó¡¾°£¬ÈçºÎÕýÈ·µÄʹÓÃ
Ç°ÃæÒѾ·ÖÎö¹ý£¬Redis×îÊʺÏËùÓÐÊý¾Ýin-momoryµÄ³¡¾°£¬ËäÈ»RedisÒ²Ìṩ³Ö¾Ã»¯¹¦ÄÜ£¬µ«Êµ¼Ê¸ü¶àµÄÊÇÒ»¸ödisk-backedµÄ¹¦ÄÜ£¬¸ú´«Í³ÒâÒåÉϵij־û¯ÓбȽϴóµÄ²î±ð£¬ÄÇô¿ÉÄÜ´ó¼Ò¾Í»áÓÐÒÉÎÊ£¬ËƺõRedis¸üÏñÒ»¸ö¼ÓÇ¿°æµÄMemcached£¬ÄÇôºÎʱʹÓÃMemcached,ºÎʱʹÓÃRedisÄØ£¿
RedisÓëMemcachedµÄ±È½Ï
- ÍøÂçIOÄ£ÐÍ
MemcachedÊǶàỊ̈߳¬·Ç×èÈûIO¸´ÓõÄÍøÂçÄ£ÐÍ£¬·ÖΪ¼àÌýÖ÷Ï̺߳Íworker×ÓỊ̈߳¬¼àÌýÏ̼߳àÌýÍøÂçÁ¬½Ó£¬½ÓÊÜÇëÇóºó£¬½«Á¬½ÓÃèÊö×Öpipe ´«µÝ¸øworkerỊ̈߳¬½øÐжÁдIO, ÍøÂç²ãʹÓÃlibevent·â×°µÄʼþ¿â£¬¶àÏß³ÌÄ£ÐÍ¿ÉÒÔ·¢»Ó¶àºË×÷Ó㬵«ÊÇÒýÈëÁËcache coherencyºÍËøµÄÎÊÌ⣬±ÈÈ磬Memcached×î³£ÓõÄstats ÃüÁʵ¼ÊMemcachedËùÓвÙ×÷¶¼Òª¶ÔÕâ¸öÈ«¾Ö±äÁ¿¼ÓËø£¬½øÐмÆÊýµÈ¹¤×÷£¬´øÀ´ÁËÐÔÄÜËðºÄ¡£
£¨MemcachedÍøÂçIOÄ£ÐÍ£©
RedisʹÓõ¥Ï̵߳ÄIO¸´ÓÃÄ£ÐÍ£¬×Ô¼º·â×°ÁËÒ»¸ö¼òµ¥µÄAeEventʼþ´¦Àí¿ò¼Ü£¬Ö÷ҪʵÏÖÁËepoll¡¢kqueueºÍselect£¬¶ÔÓÚµ¥´¿Ö»ÓÐIO²Ù×÷À´Ëµ£¬µ¥Ï߳̿ÉÒÔ½«ËÙ¶ÈÓÅÊÆ·¢»Óµ½×î´ó£¬µ«ÊÇRedisÒ²ÌṩÁËһЩ¼òµ¥µÄ¼ÆË㹦ÄÜ£¬±ÈÈçÅÅÐò¡¢¾ÛºÏµÈ£¬¶ÔÓÚÕâЩ²Ù×÷£¬µ¥Ïß³ÌÄ£ÐÍʵ¼Ê»áÑÏÖØÓ°ÏìÕûÌåÍÌÍÂÁ¿£¬CPU¼ÆËã¹ý³ÌÖУ¬Õû¸öIOµ÷¶È¶¼ÊDZ»×èÈûסµÄ¡£
- ÄÚ´æ¹ÜÀí·½Ãæ
MemcachedʹÓÃÔ¤·ÖÅäµÄÄÚ´æ³ØµÄ·½Ê½£¬Ê¹ÓÃslabºÍ´óС²»Í¬µÄchunkÀ´¹ÜÀíÄڴ棬Item¸ù¾Ý´óСѡÔñºÏÊʵÄchunk´æ´¢£¬ÄÚ´æ³ØµÄ·½Ê½¿ÉÒÔÊ¡È¥ÉêÇë/ÊÍ·ÅÄÚ´æµÄ¿ªÏú£¬²¢ÇÒÄܼõСÄÚ´æËéƬ²úÉú£¬µ«ÕâÖÖ·½Ê½Ò²»á´øÀ´Ò»¶¨³Ì¶ÈÉϵĿռäÀË·Ñ£¬²¢ÇÒÔÚÄÚ´æÈÔÈ»Óкܴó¿Õ¼äʱ£¬ÐµÄÊý¾ÝÒ²¿ÉÄܻᱻÌÞ³ý£¬ÔÒò¿ÉÒԲο¼TimyangµÄÎÄÕ£ºhttp://timyang.net/data/Memcached-lru-evictions/
RedisʹÓÃÏÖ³¡ÉêÇëÄÚ´æµÄ·½Ê½À´´æ´¢Êý¾Ý£¬²¢ÇÒºÜÉÙʹÓÃfree-listµÈ·½Ê½À´ÓÅ»¯ÄÚ´æ·ÖÅ䣬»áÔÚÒ»¶¨³Ì¶ÈÉÏ´æÔÚÄÚ´æËéƬ£¬Redis¸ú¾Ý´æ´¢ÃüÁî²ÎÊý£¬»á°Ñ´ø¹ýÆÚʱ¼äµÄÊý¾Ýµ¥¶À´æ·ÅÔÚÒ»Æ𣬲¢°ÑËüÃdzÆΪÁÙʱÊý¾Ý£¬·ÇÁÙʱÊý¾ÝÊÇÓÀÔ¶²»»á±»ÌÞ³ýµÄ£¬¼´±ãÎïÀíÄÚ´æ²»¹»£¬µ¼ÖÂswapÒ²²»»áÌÞ³ýÈκηÇÁÙʱÊý¾Ý£¨µ«»á³¢ÊÔÌÞ³ý²¿·ÖÁÙʱÊý¾Ý£©£¬ÕâµãÉÏRedis¸üÊʺÏ×÷Ϊ´æ´¢¶ø²»ÊÇcache¡£
- Êý¾ÝÒ»ÖÂÐÔÎÊÌâ
MemcachedÌṩÁËcasÃüÁ¿ÉÒÔ±£Ö¤¶à¸ö²¢·¢·ÃÎʲÙ×÷ͬһ·ÝÊý¾ÝµÄÒ»ÖÂÐÔÎÊÌâ¡£ RedisûÓÐÌṩcas ÃüÁ²¢²»Äܱ£Ö¤Õâµã£¬²»¹ýRedisÌṩÁËÊÂÎñµÄ¹¦ÄÜ£¬¿ÉÒÔ±£Ö¤Ò»´® ÃüÁîµÄÔ×ÓÐÔ£¬Öм䲻»á±»ÈκβÙ×÷´ò¶Ï¡£
- ´æ´¢·½Ê½¼°ÆäËü·½Ãæ
Memcached»ù±¾Ö»Ö§³Ö¼òµ¥µÄkey-value´æ´¢£¬²»Ö§³Öö¾Ù£¬²»Ö§³Ö³Ö¾Ã»¯ºÍ¸´ÖƵȹ¦ÄÜ
Redis³ýkey/valueÖ®Í⣬»¹Ö§³Ölist,set,sorted set,hashµÈÖÚ¶àÊý¾Ý½á¹¹£¬ÌṩÁËKEYS
½øÐÐö¾Ù²Ù×÷£¬µ«²»ÄÜÔÚÏßÉÏʹÓã¬Èç¹ûÐèҪö¾ÙÏßÉÏÊý¾Ý£¬RedisÌṩÁ˹¤¾ß¿ÉÒÔÖ±½ÓɨÃèÆädumpÎļþ£¬Ã¶¾Ù³öËùÓÐÊý¾Ý£¬Redis»¹Í¬Ê±ÌṩÁ˳־û¯ºÍ¸´ÖƵȹ¦ÄÜ¡£
- ¹ØÓÚ²»Í¬ÓïÑԵĿͻ§¶ËÖ§³Ö
ÔÚ²»Í¬ÓïÑԵĿͻ§¶Ë·½Ã棬MemcachedºÍRedis¶¼ÓзḻµÄµÚÈý·½¿Í»§¶Ë¿É¹©Ñ¡Ôñ£¬²»¹ýÒòΪMemcached·¢Õ¹µÄʱ¼ä¸ü¾ÃһЩ£¬Ä¿Ç°¿´ÔÚ¿Í»§¶ËÖ§³Ö·½Ã棬MemcachedµÄºÜ¶à¿Í»§¶Ë¸ü¼Ó³ÉÊìÎȶ¨£¬¶øRedisÓÉÓÚÆäÐÒé±¾Éí¾Í±ÈMemcached¸´ÔÓ£¬¼ÓÉÏ×÷Õß²»¶ÏÔö¼ÓÐµĹ¦Äܵȣ¬¶ÔÓ¦µÚÈý·½¿Í»§¶Ë¸ú½øËٶȿÉÄÜ»á¸Ï²»ÉÏ£¬ÓÐʱ¿ÉÄÜÐèÒª×Ô¼ºÔÚµÚÈý·½¿Í»§¶Ë»ù´¡ÉÏ×öЩÐ޸IJÅÄܸüºÃµÄʹÓá£
¸ù¾ÝÒÔÉϱȽϲ»ÄÑ¿´³ö£¬µ±ÎÒÃDz»Ï£ÍûÊý¾Ý±»Ìß³ö£¬»òÕßÐèÒª³ýkey/valueÖ®ÍâµÄ¸ü¶àÊý¾ÝÀàÐÍʱ£¬»òÕßÐèÒªÂäµØ¹¦ÄÜʱ£¬Ê¹ÓÃRedis±ÈʹÓÃMemcached¸üºÏÊÊ¡£
¹ØÓÚRedisµÄһЩÖܱ߹¦ÄÜ
Redis³ýÁË×÷Ϊ´æ´¢Ö®Í⻹ÌṩÁËһЩÆäËü·½ÃæµÄ¹¦ÄÜ£¬±ÈÈç¾ÛºÏ¼ÆËã¡¢pubsub¡¢scriptingµÈ£¬¶ÔÓÚ´ËÀ๦ÄÜÐèÒªÁ˽âÆäʵÏÖÔÀí£¬Çå³þµØÁ˽⵽ËüµÄ¾ÖÏÞÐԺ󣬲ÅÄÜÕýÈ·µÄʹÓ㬱ÈÈçpubsub¹¦ÄÜ£¬Õâ¸öʵ¼ÊÊÇûÓÐÈκγ־û¯Ö§³ÖµÄ£¬Ïû·Ñ·½Á¬½ÓÉÁ¶Ï»òÖØÁ¬Ö®¼ä¹ýÀ´µÄÏûÏ¢ÊÇ»áÈ«²¿¶ªÊ§µÄ£¬ÓÖ±ÈÈç¾ÛºÏ¼ÆËãºÍscriptingµÈ¹¦ÄÜÊÜRedisµ¥Ïß³ÌÄ£ÐÍËùÏÞ£¬ÊDz»¿ÉÄÜ´ïµ½ºÜ¸ßµÄÍÌÍÂÁ¿µÄ£¬ÐèÒª½÷É÷ʹÓá£
×ܵÄÀ´ËµRedis×÷ÕßÊÇһλ·Ç³£ÇڷܵĿª·¢Õߣ¬¿ÉÒÔ¾³£¿´µ½×÷ÕßÔÚ³¢ÊÔן÷ÖÖ²»Í¬µÄÐÂÏÊÏë·¨ºÍ˼·£¬Õë¶ÔÕâЩ·½ÃæµÄ¹¦ÄܾÍÒªÇóÎÒÃÇÐèÒªÉîÈëÁ˽âºóÔÙʹÓá£
×ܽ᣺
- RedisʹÓÃ×î¼Ñ·½Ê½ÊÇÈ«²¿Êý¾Ýin-memory¡£
- Redis¸ü¶à³¡¾°ÊÇ×÷ΪMemcachedµÄÌæ´úÕßÀ´Ê¹Óá£
- µ±ÐèÒª³ýkey/valueÖ®ÍâµÄ¸ü¶àÊý¾ÝÀàÐÍÖ§³Öʱ£¬Ê¹ÓÃRedis¸üºÏÊÊ¡£
- µ±´æ´¢µÄÊý¾Ý²»Äܱ»ÌÞ³ýʱ£¬Ê¹ÓÃRedis¸üºÏÊÊ¡£
ºóÐø¹ØÓÚRedisÎÄÕ¼ƻ®£º
- RedisÊý¾ÝÀàÐÍÓëÈÝÁ¿¹æ»®¡£
- ÈçºÎ¸ù¾ÝÒµÎñ³¡¾°´î½¨Îȶ¨£¬¿É¿¿£¬¿ÉÀ©Õ¹µÄRedis¼¯Èº¡£
- Redis²ÎÊý£¬´úÂëÓÅ»¯¼°¶þ´Î¿ª·¢»ù´¡Êµ¼ù¡£
¹ØÓÚ×÷Õß
Ìïç÷£¬Ä¿Ç°¸ºÔðÐÂÀË΢²©Æ½Ì¨µ×²ã¼Ü¹¹ÓëÑз¢¹¤×÷£¬Ö®Ç°Ôøµ£ÈÎËѺü°×Éç»áʵʱÓÎϷƽ̨ºËÐļܹ¹¹¤×÷£¬Ö÷Òª¹Ø×¢webgame, ·Ö²¼Ê½´æ´¢£¬nosql ºÍ erlang µÈÁìÓò£¬Ä¿Ç°Ö÷Òª´ÓÊÂmysqlÔ´´úÂëµÄһЩÉîÈëÑо¿¹¤×÷£¬ÐÂÀË΢²©£º http://weibo.com/bachmozart¡£
ÍƼöÐÅÏ¢
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- php³£ÓÃÕýÔò±í´ïʽ
- phpÐÔÄܼà²âÄ£¿éXHProf
- ÈÃCI¿ò¼ÜÖ§³Öservice²ã
- ʹÓÃPHPÉú³É´øLOGOµÄ¸öÐÔ»¯¶þάÂëͼÏñ
- ¹ØÓÚCodeIgniterÄã¿ÉÄܲ»ÖªµÀµÄ5¸ö֪ʶµã
- Memcache ºÁÃ뼶³¬Ê±¼°ÆäËû³£¼ûÎÊÌâ»ã×Ü
- [PHP±Ê¼Ç]PHPQueryÒ»¸ö´¦ÀíDOMµÄÀûÆ÷
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
×î½ü¸üÐÂ
- PHP»ñÈ¡Óû§µÄÕæʵIP£¬²¢ÅжÏÊÇ·ñÄÚÍøIP
- PHP ´íÎóÈÕÖ¾ error_log
- ÀûÓÃbigpipe»úÖÆʵÏÖÒ³ÃæÄ£¿éµÄÒì²½äÖȾ chunked¼¼Êõ
- php¿ØÖÆÎļþÏÂÔØËÙ¶È
- js + php ¶ÁÈ¡¡¢²¥·ÅÊÓƵÁ÷ ¼æÈÝfirefox£¬c....
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- UNICODE Óë UTF-8 µÄ¹Øϵ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- phpʹÓÃmb_detect_encoding¼ì²â×Ö·û´®±àÂë
ÆÀÂÛ