redis 鍩烘湰鍛戒护

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了redis 鍩烘湰鍛戒护相关的知识,希望对你有一定的参考价值。

鏍囩锛?a href='http://www.mamicode.com/so/1/smo' title='smo'>smo   pat   ring   澶勭悊   妯$硦鏌ヨ   搴旂敤   hle   鑷   璇锋眰   

涓€銆乲ey pattern 鏌ヨ鐩稿簲鐨刱ey

銆€銆€锛?锛塺edis鍏佽妯$硦鏌ヨkey銆€銆€鏈?涓€氶厤绗? *銆?銆乕]

銆€銆€锛?锛塺andomkey锛氳繑鍥為殢鏈簁ey銆€銆€

銆€銆€锛?锛塼ype key锛氳繑鍥瀔ey瀛樺偍鐨勭被鍨?
銆€銆€锛?锛塭xists key锛氬垽鏂煇涓猭ey鏄惁瀛樺湪

銆€銆€锛?锛塪el key锛氬垹闄ey

銆€銆€锛?锛塺ename key newkey锛氭敼鍚?
銆€銆€锛?锛塺enamenx key newkey锛氬鏋渘ewkey涓嶅瓨鍦ㄥ垯淇敼鎴愬姛

銆€銆€锛?锛塵ove key 1锛氬皢key绉诲姩鍒?鏁版嵁搴?
銆€銆€锛?锛塼tl key锛氭煡璇ey鐨勭敓鍛藉懆鏈燂紙绉掞級

銆€銆€锛?0锛塭xpire key 鏁存暟鍊硷細璁剧疆key鐨勭敓鍛藉懆鏈熶互绉掍负鍗曚綅

銆€銆€锛?1锛塸expire key 鏁存暟鍊硷細璁剧疆key鐨勭敓鍛藉懆鏈熶互姣涓哄崟浣?
銆€銆€锛?2锛塸ttl key锛氭煡璇ey 鐨勭敓鍛藉懆鏈燂紙姣锛?
銆€銆€锛?3锛塸erisist key锛氭妸鎸囧畾key璁剧疆涓烘案涔呮湁鏁?

涓夈€侀摼琛ㄦ搷浣?/h2>
銆€銆€Redis鐨刲ist绫诲瀷鍏跺疄灏辨槸涓€涓瘡涓瓙鍏冪礌閮芥槸string绫诲瀷鐨勫弻鍚戦摼琛紝閾捐〃鐨勬渶澶ч暱搴︽槸2^32銆俵ist鏃㈠彲浠ョ敤鍋氭爤锛屼篃鍙互鐢ㄥ仛闃熷垪銆?
銆€銆€list鐨刾op鎿嶄綔杩樻湁闃诲鐗堟湰锛屼富瑕佹槸涓轰簡閬垮厤杞

銆€銆€锛?锛塴push key value锛氭妸鍊兼彃鍏ュ埌閾捐〃澶撮儴

銆€銆€锛?锛塺push key value锛氭妸鍊兼彃鍏ュ埌閾捐〃灏鹃儴

銆€銆€锛?锛塴pop key 锛氳繑鍥炲苟鍒犻櫎閾捐〃澶撮儴鍏冪礌

銆€銆€锛?锛塺pop key锛?杩斿洖骞跺垹闄ら摼琛ㄥ熬閮ㄥ厓绱?
銆€銆€锛?锛塴range key start stop锛氳繑鍥為摼琛ㄤ腑[start, stop]涓殑鍏冪礌

銆€銆€锛?锛塴rem key count value锛氫粠閾捐〃涓垹闄alue鍊硷紝鍒犻櫎count鐨勭粷瀵瑰€间釜value鍚庣粨鏉?
銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€count > 0 浠庤〃澶村垹闄ゃ€€銆€count < 0 浠庤〃灏惧垹闄ゃ€€銆€count=0 鍏ㄩ儴鍒犻櫎

銆€銆€锛?锛塴trim key start stop锛氬壀鍒噆ey瀵瑰簲鐨勯摼鎺ワ紝鍒嘯start, stop]涓€娈靛苟鎶婃敼鍒堕噸鏂拌祴缁檏ey

銆€銆€锛?锛塴index key index锛氳繑鍥瀒ndex绱㈠紩涓婄殑鍊?
銆€銆€锛?锛塴len key锛氳绠楅摼琛ㄧ殑鍏冪礌涓暟

銆€銆€锛?0锛塴insert key after|before search value锛氬湪key 閾捐〃涓鎵緎earch锛屽苟鍦╯earch鍊间箣鍓峾涔嬪悗鎻掑叆value

銆€銆€锛?1锛塺poplpush source dest锛氭妸source 鐨勬湯灏炬嬁鍑猴紝鏀惧埌dest澶撮儴锛屽苟杩斿洖鍗曞厓鍊?
銆€銆€銆€銆€搴旂敤鍦烘櫙锛?task + bak 鍙岄摼琛ㄥ畬鎴愬畨鍏ㄩ槦鍒?


銆€涓氬姟閫昏緫锛?rpoplpush task bak

銆€銆€銆€銆€銆€銆€銆€銆€銆€鎺ユ敹杩斿洖鍊煎苟鍋氫笟鍔″鐞?
銆€銆€銆€銆€銆€銆€銆€銆€銆€濡傛灉鎴愬姛鍒檙pop bak娓呴櫎浠诲姟锛屽鏋滀笉鎴愬姛锛屼笅娆′粠bak琛ㄥ彇浠诲姟

銆€銆€锛?2锛塨rpop锛宐lpop key timeout锛氱瓑寰呭脊鍑簁ey鐨勫熬/澶村厓绱?
銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€timeout涓虹瓑寰呰秴鏃舵椂闂达紝濡傛灉timeout涓?鍒欎竴鐩寸瓑寰呬笅鍘?
銆€銆€銆€銆€銆€銆€搴旂敤鍦烘櫙锛氶暱杞ajax锛屽湪绾胯亰澶╂椂鑳界敤鍒?

浜斻€侀泦鍚堢粨鏋勬搷浣?/h2>
銆€銆€鐗圭偣锛氭棤搴忔€с€佺‘瀹氭€с€佸敮涓€鎬?
銆€銆€锛?锛塻add key value1 value2锛氬線闆嗗悎閲岄潰娣诲姞鍏冪礌

銆€銆€锛?锛塻members key锛氳幏鍙栭泦鍚堟墍鏈夌殑鍏冪礌

銆€銆€锛?锛塻rem key value锛氬垹闄ら泦鍚堟煇涓厓绱?
銆€銆€锛?锛塻pop key锛氳繑鍥炲苟鍒犻櫎闆嗗悎涓?涓殢鏈哄厓绱狅紙鍙互鍧愭娊濂栵紝涓嶄細閲嶅鎶藉埌鏌愪汉锛夈€€銆€銆€

銆€銆€锛?锛塻randmember key锛氶殢鏈哄彇涓€涓厓绱?
銆€銆€锛?锛塻ismember key value锛氬垽鏂泦鍚堟槸鍚︽湁鏌愪釜鍊?
銆€銆€锛?锛塻card key锛氳繑鍥為泦鍚堝厓绱犵殑涓暟

銆€銆€锛?锛塻move source dest value锛氭妸source鐨剉alue绉诲姩鍒癲est闆嗗悎涓?
銆€銆€锛?锛塻inter key1 key2 key3锛氭眰key1 key2 key3鐨勪氦闆?
銆€銆€锛?0锛塻union key1 key2锛氭眰key1 key2 鐨勫苟闆?
銆€銆€锛?1锛塻diff key1 key2锛氭眰key1 key2鐨勫樊闆?
銆€銆€锛?2锛塻interstore res key1 key2锛氭眰key1 key2鐨勪氦闆嗗苟瀛樺湪res閲屻€€

mysql琛紝涓€鍒楀瓨鍌╲alue锛屼竴鍒楀瓨鍌ㄩ『搴忥紝鎿嶄綔涓璳ey鐞嗚В涓簔set鐨勫悕瀛椼€? 銆€銆€鍜宻et涓€鏍穝orted锛宻ets涔熸槸string绫诲瀷鍏冪礌鐨勯泦鍚堬紝涓嶅悓鐨勬槸姣忎釜鍏冪礌閮戒細鍏宠仈涓€涓猟ouble鍨嬬殑score銆俿orted set鐨勫疄鐜版槸skip list鍜宧ash table鐨勬贩鍚堜綋銆? 銆€銆€褰撳厓绱犺娣诲姞鍒伴泦鍚堜腑鏃讹紝涓€涓厓绱犲埌score鐨勬槧灏勮娣诲姞鍒癶ash table涓紝鎵€浠ョ粰瀹氫竴涓厓绱犺幏鍙杝core鐨勫紑閿€鏄疧(1)銆傚彟涓€涓猻core鍒板厓绱犵殑鏄犲皠琚坊鍔犵殑skip list锛屽苟鎸夌収score鎺掑簭锛屾墍浠ュ氨鍙互鏈夊簭鍦拌幏鍙栭泦鍚堜腑鐨勫厓绱犮€傛坊鍔犮€佸垹闄ゆ搷浣滃紑閿€閮芥槸O(logN)鍜宻kip list鐨勫紑閿€涓€鑷达紝redis鐨剆kip list 瀹炵幇鏄弻鍚戦摼琛紝杩欐牱灏卞彲浠ラ€嗗簭浠庡熬閮ㄥ幓鍏冪礌銆俿orted set鏈€缁忓父浣跨敤鏂瑰紡搴旇灏辨槸浣滀负绱㈠紩鏉ヤ娇鐢紝鎴戜滑鍙互鎶婅鎺掑簭鐨勫瓧娈典綔涓簊core瀛樺偍锛屽璞$殑ID褰撳厓绱犲瓨鍌ㄣ€? 銆€銆€锛?锛墇add key score1 value1锛氭坊鍔犲厓绱? 銆€銆€锛?锛墇range key start stop [withscore]锛氭妸闆嗗悎鎺掑簭鍚?杩斿洖鍚嶆[start,stop]鐨勫厓绱? 榛樿鏄崌缁帓鍒? withscores 鏄妸score涔熸墦鍗板嚭鏉? 銆€銆€锛?锛墇rank key member锛氭煡璇ember鐨勬帓鍚嶏紙鍗囧簭0鍚嶅紑濮嬶級 銆€銆€锛?锛墇rangebyscore key min max [withscores] limit offset N锛氶泦鍚堬紙鍗囧簭锛夋帓搴忓悗鍙杝core鍦╗min, max]鍐呯殑鍏冪礌锛屽苟璺宠繃offset涓紝鍙栧嚭N涓? 銆€銆€锛?锛墇revrank key member锛氭煡璇ember鎺掑悕锛堥檷搴?0鍚嶅紑濮嬶級 銆€銆€锛?锛墇remrangebyscore key min max锛氭寜鐓core鏉ュ垹闄ゅ厓绱狅紝鍒犻櫎score鍦╗min, max]涔嬮棿 銆€銆€锛?锛墇rem key value1 value2锛氬垹闄ら泦鍚堜腑鐨勫厓绱? 銆€銆€锛?锛墇remrangebyrank key start end锛氭寜鎺掑悕鍒犻櫎鍏冪礌锛屽垹闄ゅ悕娆″湪[start, end]涔嬮棿鐨? 銆€銆€锛?锛墇card key锛氳繑鍥為泦鍚堝厓绱犵殑涓暟 銆€銆€锛?0锛墇count key min max锛氳繑鍥瀃min, max]鍖洪棿鍐呭厓绱犳暟閲? 銆€銆€锛?1锛墇interstore dest numkeys key1[key2..] [WEIGHTS weight1 [weight2...]] [AGGREGATE SUM|MIN|MAX] 銆€銆€銆€銆€銆€銆€姹俴ey1锛宬ey2鐨勪氦闆嗭紝key1锛宬ey2鐨勬潈鍊煎垎鍒槸weight1锛寃eight2 銆€銆€銆€銆€銆€銆€鑱氬悎鏂规硶鐢?sum|min|max 銆€銆€銆€銆€銆€銆€鑱氬悎缁撴灉 淇濆瓨瀛恉est闆嗗悎鍐? 銆€銆€銆€銆€銆€銆€娉ㄦ剰锛歸eights,aggregate濡備綍鐞嗚В锛? 銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€绛旓細濡傛灉鏈変氦闆嗭紝浜ら泦鍏冪礌鍙堟湁score锛宻core鎬庝箞澶勭悊锛焌ggregate num->score鐩稿姞锛宮in鏈€灏弒core锛宮ax鏈€澶core锛屽彟澶栧彲浠ラ€氳繃weights璁剧疆涓嶅悓鐨刱ey鐨勬潈閲嶏紝浜ら泦鏃? score*weight

涓冦€佹湇鍔″櫒鐩稿叧鍛戒护

銆€銆€锛?锛塸ing锛氭祴瀹氳繛鎺ユ槸鍚﹀瓨娲?
銆€銆€锛?锛塭cho锛氬湪鍛戒护琛屾墦鍗颁竴浜涘唴瀹?
銆€銆€锛?锛塻elect锛氶€夋嫨鏁版嵁搴?
銆€銆€锛?锛塹uit锛氶€€鍑鸿繛鎺?
銆€銆€锛?锛塪bsize锛氳繑鍥炲綋鍓嶆暟鎹簱涓璳ey鐨勬暟鐩?
銆€銆€锛?锛塱nfo锛氳幏鍙栨湇鍔″櫒鐨勪俊鎭拰缁熻

銆€銆€锛?锛塵onitor锛氬疄鏃惰浆鍌ㄦ敹鍒扮殑璇锋眰

銆€銆€锛?锛塩onfig get 閰嶇疆椤癸細鑾峰彇鏈嶅姟鍣ㄩ厤缃殑淇℃伅

銆€銆€銆€銆€ config set 閰嶇疆椤? 鍊硷細璁剧疆閰嶇疆椤逛俊鎭?
銆€銆€锛?锛塮lushdb锛氬垹闄ゅ綋鍓嶉€夋嫨鏁版嵁搴撲腑鎵€鏈夌殑key

銆€銆€锛?0锛塮lushall锛氬垹闄ゆ墍鏈夋暟鎹簱涓殑鎵€鏈夌殑key

銆€銆€锛?1锛塼ime锛氭樉绀烘湇鍔″櫒鏃堕棿锛屾椂闂存埑锛堢锛夛紝寰鏁?
銆€銆€锛?2锛塨grewriteaof锛氬悗鍙颁繚瀛榬db蹇収

銆€銆€锛?3锛塨gsave锛氬悗鍙颁繚瀛榬db蹇収

銆€銆€锛?4锛塻ave锛氫繚瀛榬db蹇収

銆€銆€锛?5锛塴astsave锛氫笂娆′繚瀛樻椂闂?
銆€銆€锛?6锛塻hutdown [save/nosave]

銆€銆€銆€銆€銆€銆€娉ㄦ剰锛氬鏋滀笉灏忓績杩愯浜唂lushall锛岀珛鍗硈hutdown nosave锛屽叧闂湇鍔″櫒锛岀劧鍚庢墜宸ョ紪杈慳of鏂囦欢锛屽幓鎺夋枃浠朵腑鐨刦lushall鐩稿叧琛岋紝鐒跺悗寮€鍚湇鍔″櫒锛屽氨鍙互鍊掑洖鍘熸潵鏄暟鎹€傚鏋渇lushall涔嬪悗锛岀郴缁熸伆濂絙gwriteaof浜嗭紝閭d箞aof灏辨竻绌轰簡锛屾暟鎹涪澶便€?
銆€銆€锛?7锛塻howlog锛氭樉绀烘參鏌ヨ

銆€銆€銆€銆€銆€銆€闂細澶氭參鎵嶅彨鎱紵

銆€銆€銆€銆€銆€銆€绛旓細鐢眘lowlog-log-slower-than 10000锛屾潵鎸囧畾锛堝崟浣嶄负寰锛?
銆€銆€銆€銆€銆€銆€闂細鏈嶅姟鍣ㄥ瓨鍌ㄥ灏戞潯鎱㈡煡璇㈣褰?
銆€銆€銆€銆€銆€銆€绛旓細鐢眘lowlog-max-len 128锛屾潵鍋氶檺鍒?/code>

以上是关于redis 鍩烘湰鍛戒护的主要内容,如果未能解决你的问题,请参考以下文章

redis鍩烘湰鎿嶄綔

PHP鍩烘湰璇硶

python鍩烘湰璇硶(鎸佺画鏇存柊)

鍩烘湰妯$増

Android SearchView 鍩烘湰浣跨敤

MySQL-鍩烘湰鎿嶄綔