Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2012 - 2020 YCSB contributors. All rights reserved.
Copyright (c) 2012 - 2023 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
Expand Down Expand Up @@ -138,7 +138,7 @@ LICENSE file.
<openjpa.jdbc.version>2.1.1</openjpa.jdbc.version>
<orientdb.version>2.2.37</orientdb.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<redis.version>2.9.0</redis.version>
<jedis.version>4.4.5</jedis.version>
<riak.version>2.0.5</riak.version>
<rocksdb.version>6.2.2</rocksdb.version>
<s3.version>1.10.20</s3.version>
Expand Down
4 changes: 2 additions & 2 deletions redis/pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2012 - 2016 YCSB contributors. All rights reserved.
Copyright (c) 2012 - 2023 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
Expand Down Expand Up @@ -33,7 +33,7 @@ LICENSE file.
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>${redis.version}</version>
<version>${jedis.version}</version>
</dependency>
<dependency>
<groupId>site.ycsb</groupId>
Expand Down
53 changes: 33 additions & 20 deletions redis/src/main/java/site/ycsb/db/RedisClient.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2012 YCSB contributors. All rights reserved.
* Copyright (c) 2012 - 2023 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
Expand Down Expand Up @@ -29,15 +29,14 @@
import site.ycsb.DBException;
import site.ycsb.Status;
import site.ycsb.StringByteIterator;
import redis.clients.jedis.BasicCommands;
import redis.clients.jedis.DefaultJedisClientConfig;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.JedisCommands;
import redis.clients.jedis.Protocol;
import redis.clients.jedis.commands.JedisCommands;
import redis.clients.jedis.commands.ServerCommands;

import java.io.Closeable;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.HashSet;
Expand All @@ -47,6 +46,8 @@
import java.util.Set;
import java.util.Vector;

import org.apache.commons.pool2.impl.GenericObjectPoolConfig;

/**
* YCSB binding for <a href="http://redis.io/">Redis</a>.
*
Expand All @@ -61,6 +62,7 @@ public class RedisClient extends DB {
public static final String PASSWORD_PROPERTY = "redis.password";
public static final String CLUSTER_PROPERTY = "redis.cluster";
public static final String TIMEOUT_PROPERTY = "redis.timeout";
public static final String SSL_PROPERTY = "redis.ssl";

public static final String INDEX_KEY = "_indices";

Expand All @@ -75,32 +77,43 @@ public void init() throws DBException {
port = Protocol.DEFAULT_PORT;
}
String host = props.getProperty(HOST_PROPERTY);
String redisTimeout = props.getProperty(TIMEOUT_PROPERTY);
String password = props.getProperty(PASSWORD_PROPERTY);
boolean sslEnabled = Boolean.parseBoolean(props.getProperty(SSL_PROPERTY));

boolean clusterEnabled = Boolean.parseBoolean(props.getProperty(CLUSTER_PROPERTY));
if (clusterEnabled) {
Set<HostAndPort> jedisClusterNodes = new HashSet<>();
Set<HostAndPort> jedisClusterNodes = new HashSet<HostAndPort>();
jedisClusterNodes.add(new HostAndPort(host, port));
jedis = new JedisCluster(jedisClusterNodes);
int redisTimeoutInt;
if (redisTimeout != null) {
redisTimeoutInt = Integer.parseInt(redisTimeout);
} else {
redisTimeoutInt = JedisCluster.DEFAULT_TIMEOUT;
}
DefaultJedisClientConfig.Builder builder = DefaultJedisClientConfig.builder();
builder = builder.timeoutMillis(redisTimeoutInt);
builder = builder.password(password);
builder = builder.ssl(sslEnabled);
jedis = new JedisCluster(jedisClusterNodes, builder.build(), JedisCluster.DEFAULT_MAX_ATTEMPTS,
new GenericObjectPoolConfig());
} else {
String redisTimeout = props.getProperty(TIMEOUT_PROPERTY);
if (redisTimeout != null){
jedis = new Jedis(host, port, Integer.parseInt(redisTimeout));
if (redisTimeout != null) {
jedis = new Jedis(host, port, Integer.parseInt(redisTimeout), sslEnabled);
} else {
jedis = new Jedis(host, port);
jedis = new Jedis(host, port, sslEnabled);
}
((Jedis) jedis).connect();
}

String password = props.getProperty(PASSWORD_PROPERTY);
if (password != null) {
((BasicCommands) jedis).auth(password);
if (password != null) {
((ServerCommands) jedis).auth(password);
}
}
}

public void cleanup() throws DBException {
try {
((Closeable) jedis).close();
} catch (IOException e) {
((AutoCloseable) jedis).close();
} catch (Exception e) {
throw new DBException("Closing connection failed.");
}
}
Expand Down Expand Up @@ -166,8 +179,8 @@ public Status update(String table, String key,
@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);
List<String> keys = jedis.zrangeByScore(INDEX_KEY, hash(startkey),
Double.POSITIVE_INFINITY, 0, recordcount);

HashMap<String, ByteIterator> values;
for (String key : keys) {
Expand Down