Mac涓婄殑redis瀹夎涓巎edis鍏ラ棬
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Mac涓婄殑redis瀹夎涓巎edis鍏ラ棬相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/https' title='https'>https 鍊掓暟 鏁版嵁缁撴瀯 str int server 浠g爜 reac
Redis 鏄竴涓紑婧愶紙BSD璁稿彲锛夌殑锛屽唴瀛樹腑鐨勬暟鎹粨鏋勫瓨鍌ㄧ郴缁燂紝瀹冨彲浠ョ敤浣滄暟鎹簱銆佺紦瀛樺拰娑堟伅涓棿浠?/p>
瀹夎涓庨厤缃?/h2>
(1) https://redis.io/download涓嬭浇redis stable鏈€鏂扮増
灏嗗帇缂╁寘瑙e帇鍒颁綘鐨勬枃浠跺す涓?/p>
(2) 杩涘叆鍒皉edis鏂囦欢澶圭殑鏍圭洰褰?/p>
# 缂栬瘧娴嬭瘯(璺宠繃涔熷彲浠?
sudo make test
# 缂栬瘧瀹夎
sudo make install
# 瀹夎瀹屾垚浠ュ悗鍚姩
redis-server
(3) 绠€鍗曟祴璇?/p>
鏂板缓涓€涓猼erminal, 杈撳叆
redis-cli # 瀹㈡埛绔?/pre>
瀛樹竴涓畝鍗曠殑kv
Jedis浣跨敤
Redis鍛戒护鍙傝€?nbsp;http://redisdoc.com/list/ltrim.html [鎺ㄨ崘, 寰堝叏]
(1) 杩炴帴鍒癹edis鏈嶅姟
涓嬭浇渚濊禆鐨刯ar鍖?nbsp;https://mvnrepository.com/artifact/redis.clients/jedis/2.9.0
鎴栬€呬娇鐢∕aven鏇存柟渚?/p>
<!-- https://mvnrepository.com/artifact/redis.clients/jedis --> <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>2.9.0</version> </dependency>
鐒跺悗鍦ㄤ唬鐮佷腑杩炲埌jedis
public class JedisTest public static void main(String args[]) //杩炴帴鏈湴鐨?Redis 鏈嶅姟 Jedis jedis = new Jedis("localhost"); System.out.println("杩炴帴鎴愬姛"); //鏌ョ湅鏈嶅姟鏄惁杩愯 System.out.println("鏈嶅姟姝e湪杩愯: "+jedis.ping());
杈撳嚭
杩炴帴鎴愬姛
鏈嶅姟姝e湪杩愯: PONG
杩炴帴鎴愬姛浠ュ悗鍋氫竴浜涘熀鏈搷浣?/p>
(2) jedis鍩烘湰鎿嶄綔
涓€ jedis鏈€鍩烘湰鐨勬搷浣滃氨鏄痵et
jedis.set("yyq", "1995");
System.out.println(jedis.get("yyq"));
浜屻€乯edis杩樺彲浠ュ瓨list
"lpush"
// 浠庡乏杈瑰帇浜嗕袱涓? 浠庡彸杈瑰帇浜嗕竴涓? 鎵€浠ラ『搴忔槸1996, 1995, 1997
jedis.lpush("test", "1995"); jedis.lpush("test", "1996"); jedis.rpush("test","1997");
// -1琛ㄧず鏈€鍚庝竴涓? 杩欐牱鍙互鍏ㄦ嬁鍑烘潵 jedis.lrange("test", 0, -1).forEach(System.out::println);
涔熷彲浠ヨ浆鎴愬瓧鑺傛暟缁勫啀瀛? 杩欐牱鍙互鍖呭惈鏇村淇℃伅
"ltrim"
// 鍙繚鐣欎粠0鍒板€掓暟绗簩涓?澶村熬鍒颁細淇濈暀)
jedis.ltrim("test", 0, -2); jedis.lrange("test", 0, -1).forEach(System.out::println);
// 鍥犳杈撳嚭鍙墿 1996, 1995
"lindex"
鍙栧緱鎸囧畾index鐨勫厓绱?/p>
System.out.println(jedis.lindex("test", 0)); //杈撳嚭绗竴涓厓绱?996
以上是关于Mac涓婄殑redis瀹夎涓巎edis鍏ラ棬的主要内容,如果未能解决你的问题,请参考以下文章