Skip to content

DATAREDIS-744 - Support Redis hashes with colon in their id. #298

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 2 commits 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
30 changes: 15 additions & 15 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>1.8.10.BUILD-SNAPSHOT</version>
<version>1.8.10.DATAREDIS-744-SNAPSHOT</version>

<name>Spring Data Redis</name>

Expand All @@ -31,26 +31,26 @@

<dependencyManagement>
<dependencies>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
<version>${pool}</version>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava}</version>
</dependency>

</dependencies>
</dependencyManagement>

<dependencies>

<!-- Spring -->

<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-keyvalue</artifactId>
Expand Down Expand Up @@ -78,35 +78,35 @@
</dependency>

<!-- REDIS Drivers -->

<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>${jedis}</version>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.jredis</groupId>
<artifactId>jredis-core-api</artifactId>
<version>${jredis}</version>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.jredis</groupId>
<artifactId>jredis-core-ri</artifactId>
<version>${jredis}</version>
<optional>true</optional>
</dependency>

<dependency>
<groupId>com.github.spullara.redis</groupId>
<artifactId>client</artifactId>
<version>${srp}</version>
<optional>true</optional>
</dependency>

<dependency>
<groupId>biz.paluch.redis</groupId>
<artifactId>lettuce</artifactId>
Expand Down Expand Up @@ -221,7 +221,7 @@

<build>
<plugins>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
Expand All @@ -242,12 +242,12 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>wagon-maven-plugin</artifactId>
</plugin>

<plugin>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
Expand All @@ -261,13 +261,13 @@
<id>release</id>
<build>
<plugins>

<plugin>
<groupId>org.jfrog.buildinfo</groupId>
<artifactId>artifactory-maven-plugin</artifactId>
<inherited>false</inherited>
</plugin>

</plugins>
</build>
</profile>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,13 +18,14 @@
import java.nio.charset.Charset;

import org.springframework.context.ApplicationEvent;
import org.springframework.data.redis.util.ByteUtils;
import org.springframework.data.redis.core.convert.MappingRedisConverter.BinaryKeyspaceIdentifier;

/**
* {@link RedisKeyExpiredEvent} is Redis specific {@link ApplicationEvent} published when a specific key in Redis
* expires. It might but must not hold the expired value itself next to the key.
*
*
* @author Christoph Strobl
* @author Mark Paluch
* @since 1.7
*/
public class RedisKeyExpiredEvent<T> extends RedisKeyspaceEvent {
Expand All @@ -34,12 +35,12 @@ public class RedisKeyExpiredEvent<T> extends RedisKeyspaceEvent {
*/
public static final Charset CHARSET = Charset.forName("UTF-8");

private final byte[][] args;
private final BinaryKeyspaceIdentifier objectId;
private final Object value;

/**
* Creates new {@link RedisKeyExpiredEvent}.
*
*
* @param key
*/
public RedisKeyExpiredEvent(byte[] key) {
Expand Down Expand Up @@ -67,36 +68,36 @@ public RedisKeyExpiredEvent(byte[] key, Object value) {
public RedisKeyExpiredEvent(String channel, byte[] key, Object value) {
super(channel, key);

args = ByteUtils.split(key, ':');
if (BinaryKeyspaceIdentifier.isValid(key)) {
this.objectId = BinaryKeyspaceIdentifier.of(key);
} else {
this.objectId = null;
}

this.value = value;
}

/**
* Gets the keyspace in which the expiration occured.
*
*
* @return {@literal null} if it could not be determined.
*/
public String getKeyspace() {

if (args.length >= 2) {
return new String(args[0], CHARSET);
}

return null;
return objectId != null ? new String(objectId.getKeyspace(), CHARSET) : null;
}

/**
* Get the expired objects id;
*
*
* @return
*/
public byte[] getId() {
return args.length == 2 ? args[1] : args[0];
return objectId != null ? objectId.getId() : getSource();
}

/**
* Get the expired Object
*
*
* @return {@literal null} if not present.
*/
public Object getValue() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
Expand All @@ -52,6 +50,8 @@
import org.springframework.data.redis.core.convert.GeoIndexedPropertyValue;
import org.springframework.data.redis.core.convert.KeyspaceConfiguration;
import org.springframework.data.redis.core.convert.MappingRedisConverter;
import org.springframework.data.redis.core.convert.MappingRedisConverter.BinaryKeyspaceIdentifier;
import org.springframework.data.redis.core.convert.MappingRedisConverter.KeyspaceIdentifier;
import org.springframework.data.redis.core.convert.PathIndexResolver;
import org.springframework.data.redis.core.convert.RedisConverter;
import org.springframework.data.redis.core.convert.RedisData;
Expand All @@ -64,7 +64,6 @@
import org.springframework.data.util.CloseableIterator;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

/**
* Redis specific {@link KeyValueAdapter} implementation. Uses binary codec to read/write data from/to Redis. Objects
Expand Down Expand Up @@ -228,7 +227,7 @@ public Object doInRedis(RedisConnection connection) throws DataAccessException {
connection.expire(objectKey, rdo.getTimeToLive().longValue());

// add phantom key so values can be restored
byte[] phantomKey = ByteUtils.concat(objectKey, toBytes(":phantom"));
byte[] phantomKey = ByteUtils.concat(objectKey, BinaryKeyspaceIdentifier.PHANTOM_SUFFIX);
connection.del(phantomKey);
connection.hMSet(phantomKey, rdo.getBucket().rawMap());
connection.expire(phantomKey, rdo.getTimeToLive().longValue() + 300);
Expand Down Expand Up @@ -484,14 +483,14 @@ public Void doInRedis(RedisConnection connection) throws DataAccessException {
connection.expire(redisKey, rdo.getTimeToLive().longValue());

// add phantom key so values can be restored
byte[] phantomKey = ByteUtils.concat(redisKey, toBytes(":phantom"));
byte[] phantomKey = ByteUtils.concat(redisKey, BinaryKeyspaceIdentifier.PHANTOM_SUFFIX);
connection.hMSet(phantomKey, rdo.getBucket().rawMap());
connection.expire(phantomKey, rdo.getTimeToLive().longValue() + 300);

} else {

connection.persist(redisKey);
connection.persist(ByteUtils.concat(redisKey, toBytes(":phantom")));
connection.persist(ByteUtils.concat(redisKey, BinaryKeyspaceIdentifier.PHANTOM_SUFFIX));
}
}

Expand Down Expand Up @@ -779,7 +778,7 @@ public void onMessage(Message message, byte[] pattern) {
byte[] key = message.getBody();

final byte[] phantomKey = ByteUtils.concat(key,
converter.getConversionService().convert(":phantom", byte[].class));
converter.getConversionService().convert(KeyspaceIdentifier.PHANTOM_SUFFIX, byte[].class));

Map<byte[], byte[]> hash = ops.execute(new RedisCallback<Map<byte[], byte[]>>() {

Expand Down Expand Up @@ -822,12 +821,7 @@ private boolean isKeyExpirationMessage(Message message) {
return false;
}

byte[][] args = ByteUtils.split(message.getBody(), ':');
if (args.length != 2) {
return false;
}

return true;
return BinaryKeyspaceIdentifier.isValid(message.getBody());
}
}

Expand Down
Loading