Skip to content

DATAREDIS-1034 - Fix dataraces in RedisTemplate. #479

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
* @author Christoph Strobl
* @author David Liu
* @author Mark Paluch
* @author Denis Zavedeev
*/
abstract class AbstractOperations<K, V> {

Expand All @@ -64,7 +65,7 @@ public final V doInRedis(RedisConnection connection) {
protected abstract byte[] inRedis(byte[] rawKey, RedisConnection connection);
}

RedisTemplate<K, V> template;
final RedisTemplate<K, V> template;

AbstractOperations(RedisTemplate<K, V> template) {
this.template = template;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
* @author Ninad Divadkar
* @author Anqing Shao
* @author Mark Paluch
* @author Denis Zavedeev
* @param <K> the Redis key type against which the template works (usually a String)
* @param <V> the Redis value type against which the template works
* @see StringRedisTemplate
Expand All @@ -102,14 +103,14 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation

private @Nullable ScriptExecutor<K> scriptExecutor;

// cache singleton objects (where possible)
private @Nullable ValueOperations<K, V> valueOps;
private @Nullable ListOperations<K, V> listOps;
private @Nullable SetOperations<K, V> setOps;
private @Nullable StreamOperations<K, ?, ?> streamOps;
private @Nullable ZSetOperations<K, V> zSetOps;
private @Nullable GeoOperations<K, V> geoOps;
private @Nullable HyperLogLogOperations<K, V> hllOps;
private final ValueOperations<K, V> valueOps = new DefaultValueOperations<>(this);
private final ListOperations<K, V> listOps = new DefaultListOperations<>(this);
private final SetOperations<K, V> setOps = new DefaultSetOperations<>(this);
private final StreamOperations<K, ?, ?> streamOps = new DefaultStreamOperations<>(this, new ObjectHashMapper());
private final ZSetOperations<K, V> zSetOps = new DefaultZSetOperations<>(this);
private final GeoOperations<K, V> geoOps = new DefaultGeoOperations<>(this);
private final HyperLogLogOperations<K, V> hllOps = new DefaultHyperLogLogOperations<>(this);
private final ClusterOperations<K, V> clusterOps = new DefaultClusterOperations<>(this);

/**
* Constructs a new <code>RedisTemplate</code> instance.
Expand Down Expand Up @@ -1203,7 +1204,7 @@ public void slaveOfNoOne() {
*/
@Override
public ClusterOperations<K, V> opsForCluster() {
return new DefaultClusterOperations<>(this);
return clusterOps;
}

/*
Expand All @@ -1212,10 +1213,6 @@ public ClusterOperations<K, V> opsForCluster() {
*/
@Override
public GeoOperations<K, V> opsForGeo() {

if (geoOps == null) {
geoOps = new DefaultGeoOperations<>(this);
}
return geoOps;
}

Expand Down Expand Up @@ -1252,10 +1249,6 @@ public <HK, HV> HashOperations<K, HK, HV> opsForHash() {
*/
@Override
public HyperLogLogOperations<K, V> opsForHyperLogLog() {

if (hllOps == null) {
hllOps = new DefaultHyperLogLogOperations<>(this);
}
return hllOps;
}

Expand All @@ -1265,10 +1258,6 @@ public HyperLogLogOperations<K, V> opsForHyperLogLog() {
*/
@Override
public ListOperations<K, V> opsForList() {

if (listOps == null) {
listOps = new DefaultListOperations<>(this);
}
return listOps;
}

Expand Down Expand Up @@ -1296,10 +1285,6 @@ public BoundSetOperations<K, V> boundSetOps(K key) {
*/
@Override
public SetOperations<K, V> opsForSet() {

if (setOps == null) {
setOps = new DefaultSetOperations<>(this);
}
return setOps;
}

Expand All @@ -1309,10 +1294,6 @@ public SetOperations<K, V> opsForSet() {
*/
@Override
public <HK, HV> StreamOperations<K, HK, HV> opsForStream() {

if (streamOps == null) {
streamOps = new DefaultStreamOperations<>(this, new ObjectHashMapper());
}
return (StreamOperations<K, HK, HV>) streamOps;
}

Expand Down Expand Up @@ -1350,10 +1331,6 @@ public BoundValueOperations<K, V> boundValueOps(K key) {
*/
@Override
public ValueOperations<K, V> opsForValue() {

if (valueOps == null) {
valueOps = new DefaultValueOperations<>(this);
}
return valueOps;
}

Expand All @@ -1372,10 +1349,6 @@ public BoundZSetOperations<K, V> boundZSetOps(K key) {
*/
@Override
public ZSetOperations<K, V> opsForZSet() {

if (zSetOps == null) {
zSetOps = new DefaultZSetOperations<>(this);
}
return zSetOps;
}

Expand Down