我正在研究redis。我使用三個主節點構建了我的Redis集羣,並且還有另一個運行ycsb的節點。我遇到了與 To start YCSB load with cluster enabled option for REDIS中所述相同的問題。 我試着根據給出的答案編輯RedisClient.java。不過,我得到的錯誤: import redis.clients.jedis.HostAndPort; import redis.clients.jedis.JedisCluster; ,因爲這些軟件包不存在。所以我的問題是在哪裏可以找到像redis.clients.jedis.JedisCluster這樣的軟件包?有沒有人成功編輯RedisClient.java來測試Redis集羣,還是我們有其他解決方案?謝謝!由於我們沒有redis集羣的綁定,所以如何運行ycsb來測試redis集羣?
0
A
回答
1
來自ycsb的默認redis客戶端不支持redis集羣。因此,要使用ycsb對redis集羣進行基準測試,我們必須對redis客戶端(RedisClient.java)進行調整,並使用maven重新編譯代碼。下面的代碼爲我工作:
/**
* Copyright (c) 2012 YCSB contributors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You
* may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License. See accompanying
* LICENSE file.
*/
/**
* Redis client binding for YCSB.
*
* All YCSB records are mapped to a Redis *hash field*. For scanning
* operations, all keys are saved (by an arbitrary hash) in a sorted set.
*/
package com.yahoo.ycsb.db;
import com.yahoo.ycsb.ByteIterator;
import com.yahoo.ycsb.DB;
import com.yahoo.ycsb.DBException;
import com.yahoo.ycsb.Status;
import com.yahoo.ycsb.StringByteIterator;
import redis.clients.jedis.Protocol;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import java.util.Set;
import java.util.Vector;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;
import java.util.HashSet;
/**
* YCSB binding for <a href="http://redis.io/">Redis</a>.
*
* See {@code redis/README.md} for details.
*/
public class RedisClient extends DB {
private JedisCluster jedis;
public static final String HOST_PROPERTY = "redis.host";
public static final String PORT_PROPERTY = "redis.port";
public static final String PASSWORD_PROPERTY = "redis.password";
public static final String INDEX_KEY = "_indices";
public void init() throws DBException {
Properties props = getProperties();
int port;
Set<HostAndPort> jedisClusterNodes = new HashSet<HostAndPort>();
String portString = props.getProperty(PORT_PROPERTY);
if (portString != null) {
port = Integer.parseInt(portString);
} else {
port = Protocol.DEFAULT_PORT;
}
String host = props.getProperty(HOST_PROPERTY);
jedisClusterNodes.add(new HostAndPort(host, port));
jedis = new JedisCluster(jedisClusterNodes);
String password = props.getProperty(PASSWORD_PROPERTY);
if (password != null) {
jedis.auth(password);
}
}
public void cleanup() throws DBException {
}
/*
* Calculate a hash for a key to store it in an index. The actual return value
* of this function is not interesting -- it primarily needs to be fast and
* scattered along the whole space of doubles. In a real world scenario one
* would probably use the ASCII values of the keys.
*/
private double hash(String key) {
return key.hashCode();
}
// XXX jedis.select(int index) to switch to `table`
@Override
public Status read(String table, String key, Set<String> fields,
HashMap<String, ByteIterator> result) {
if (fields == null) {
StringByteIterator.putAllAsByteIterators(result, jedis.hgetAll(key));
} else {
String[] fieldArray =
(String[]) fields.toArray(new String[fields.size()]);
List<String> values = jedis.hmget(key, fieldArray);
Iterator<String> fieldIterator = fields.iterator();
Iterator<String> valueIterator = values.iterator();
while (fieldIterator.hasNext() && valueIterator.hasNext()) {
result.put(fieldIterator.next(),
new StringByteIterator(valueIterator.next()));
}
assert !fieldIterator.hasNext() && !valueIterator.hasNext();
}
return result.isEmpty() ? Status.ERROR : Status.OK;
}
@Override
public Status insert(String table, String key,
HashMap<String, ByteIterator> values) {
if (jedis.hmset(key, StringByteIterator.getStringMap(values))
.equals("OK")) {
jedis.zadd(INDEX_KEY, hash(key), key);
return Status.OK;
}
return Status.ERROR;
}
@Override
public Status delete(String table, String key) {
return jedis.del(key) == 0 && jedis.zrem(INDEX_KEY, key) == 0 ? Status.ERROR
: Status.OK;
}
@Override
public Status update(String table, String key,
HashMap<String, ByteIterator> values) {
return jedis.hmset(key, StringByteIterator.getStringMap(values))
.equals("OK") ? Status.OK : Status.ERROR;
}
@Override
public Status scan(String table, String startkey, int recordcount,
Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
Set<String> keys = jedis.zrangeByScore(INDEX_KEY, hash(startkey),
Double.POSITIVE_INFINITY, 0, recordcount);
HashMap<String, ByteIterator> values;
for (String key : keys) {
values = new HashMap<String, ByteIterator>();
read(table, key, fields, values);
result.add(values);
}
return Status.OK;
}
}
我認爲可能對他人有所幫助:)
相關問題
- 1. Redis HA沒有集羣
- 2. 如何使用Sentinel運行Redis集羣
- 3. 如何保護Redis集羣?
- 4. Redis集羣和zsets
- 5. Redis中的Redis集羣支持2.8.19
- 6. kubernetes上的Redis集羣
- 7. 應在Redis的集羣
- 8. Redis的羣集錯誤
- 9. Redis命令獲取Redis集羣上的所有可用密鑰?
- 10. spring-data-redis是否支持redis集羣?
- 11. socket.io-redis是否支持redis集羣?
- 12. Kubernetes Redis集羣問題
- 13. Redis集羣通過HAProxy
- 14. Ignite Vs Redis Websession集羣
- 15. Raise Redis集羣授權
- 16. Redis羣集 - 從站不FAILOVER
- 17. 如何解決的Redis集羣「等待集羣加盟」的問題
- 18. 啓用羣集模式的Redis鎖
- 19. 負載平衡器上的Redis集羣
- 20. Spring引導的Redis集羣配置
- 21. Akka集羣感知路由器 - 共享redis實例到所有路由器
- 22. Redis羣集需要AOF還是RDB?
- 23. 將Redis數據遷移到羣集
- 24. 通過Sentinel連接到Redis集羣
- 25. 從Peered VPC連接到Elasticache Redis羣集
- 26. AwsElastiCache創建Redis集羣:CreateCacheCluster()與CreateReplicationGroup()
- 27. spring data redis集羣管道支持
- 28. Redis集羣就緒客戶端
- 29. 無法啓動Redis集羣服務器
- 30. 我需要一個用於redis集羣的scala客戶端庫