JedisCluster 鏈結redis集群

2022-08-12 14:06:11 字數 1530 閱讀 7275

先貼**:

redis.clients

jedis

2.8.2

jedispoolconfig config = new jedispoolconfig();

config =new jedispoolconfig();

config.setmaxtotal(60000);//設定最大連線數  

config.setmaxidle(1000); //設定最大空閒數 

config.setmaxwaitmillis(3000);//設定超時時間  

config.settestonborrow(true);

// 集群結點

setjedisclusternode = new hashset();

jedisclusternode.add(new hostandport("192.168.246.128", integer.parseint("7001")));

jedisclusternode.add(new hostandport("192.168.246.128", integer.parseint("7002")));

jedisclusternode.add(new hostandport("192.168.246.128", integer.parseint("7003")));

jedisclusternode.add(new hostandport("192.168.246.128", integer.parseint("7004")));

jedisclusternode.add(new hostandport("192.168.246.128", integer.parseint("7005")));

jedisclusternode.add(new hostandport("192.168.246.128", integer.parseint("7006")));

jediscluster jc = new jediscluster(jedisclusternode, config);

//jediscluster jc = new jediscluster(jedisclusternode);

jc.set("name", "zhangsan");

string value = jc.get("name");

system.out.println(value);

注意事項

redis配置檔案中  bind配置注釋掉  或者bind 0.0.0.0  表示所有的伺服器都可以連線

如果配置為  bind  127.0.0.1  會報could not get a resource from the pool 錯誤

建立集群命令為./redis-trib.rb create --replicas 1 45.78.76.17:7001 45.78.76.17:7002 45.78.76.17:7003 45.78.76.17:7004 45.78.76.17:7005 45.78.76.17:7006 45.78.76.17:7007 45.78.76.17:7008

其中  45.78.76.17為本機ip

使用jedisCluster操作Redis集群

第一步 建立乙個jedis物件。需要指定服務端的ip及埠。第二步 使用jedis物件運算元據庫,每個redis命令對應乙個方法。第三步 列印結果。第四步 關閉jedis test public void testjedis throws exception第一步 建立乙個jedispool物件。需要...

jedisCluster中分布式鎖遇到的坑總結篇

不知道大家有沒有遇到過jediscluster.set 方法上鎖時出現上鎖成功但返回結果並不是ok,具體需求如下 1.跑批量訂單,需要對每個訂單進行操作。2.其他地方可能操作這些訂單。3.為了只有乙個地方操作,將所有的訂單逐一上鎖出現問題,之後我對jediscluster進行測試 如下我們做三次測試...

資料探勘R語言鏈結資料庫MYSQL

r語言連線資料庫常用的方法有2種 1 使用r資料庫介面 連線mysql,使用rmysql包,使用前rmysql包要先安裝。library rmysql 連線方式有2種 1 使用dbconnect conn dbconnect mysql dbname rmysql username rmysql p...