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
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader)
TypeReference.of(RedisKeyCommands.class), TypeReference.of(RedisStringCommands.class),
TypeReference.of(RedisListCommands.class), TypeReference.of(RedisSetCommands.class),
TypeReference.of(RedisZSetCommands.class), TypeReference.of(RedisHashCommands.class),
TypeReference.of(RedisJsonCommands.class),
TypeReference.of(RedisTxCommands.class), TypeReference.of(RedisPubSubCommands.class),
TypeReference.of(RedisConnectionCommands.class), TypeReference.of(RedisServerCommands.class),
TypeReference.of(RedisStreamCommands.class), TypeReference.of(RedisScriptingCommands.class),
Expand Down Expand Up @@ -132,6 +133,7 @@ public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader)
TypeReference.of("org.springframework.data.redis.core.DefaultStreamOperations"),
TypeReference.of("org.springframework.data.redis.core.DefaultValueOperations"),
TypeReference.of("org.springframework.data.redis.core.DefaultZSetOperations"),
TypeReference.of("org.springframework.data.redis.core.DefaultJsonOperations"),

TypeReference.of(RedisKeyValueAdapter.class), TypeReference.of(RedisKeyValueTemplate.class),

Expand Down Expand Up @@ -175,6 +177,7 @@ public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader)
registerRedisConnectionProxy(TypeReference.of(RedisStreamCommands.class), hints);
registerRedisConnectionProxy(TypeReference.of(RedisStringCommands.class), hints);
registerRedisConnectionProxy(TypeReference.of(RedisZSetCommands.class), hints);
registerRedisConnectionProxy(TypeReference.of(RedisJsonCommands.class), hints);
}

static void boundOperationsProxy(Class<?> type, @Nullable ClassLoader classLoader, RuntimeHints hints) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ public enum DataType {
/**
* @since 2.2
*/
STREAM("stream");
STREAM("stream"),
/**
* @since 4.2
*/
JSON("json");

private static final Map<String, DataType> codeLookup = new ConcurrentHashMap<>(7);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,11 @@ public RedisZSetCommands zSetCommands() {
return this;
}

@Override
public RedisJsonCommands jsonCommands() {
return delegate.jsonCommands();
}

@Override
public Long append(byte[] key, byte[] value) {
return convertAndReturn(delegate.append(key, value), Converters.identityConverter());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import org.springframework.data.geo.GeoResults;
import org.springframework.data.geo.Metric;
import org.springframework.data.geo.Point;
import org.springframework.data.redis.connection.json.JsonPath;
import org.springframework.data.redis.connection.json.JsonValue;
import org.springframework.data.redis.connection.stream.ByteRecord;
import org.springframework.data.redis.connection.stream.Consumer;
import org.springframework.data.redis.connection.stream.MapRecord;
Expand Down Expand Up @@ -2071,4 +2073,111 @@ default Long zRangeStoreRevByScore(byte[] dstKey, byte[] srcKey,
return zSetCommands().zRangeStoreRevByScore(dstKey, srcKey, range, limit);
}

// JSON COMMANDS

/** @deprecated in favor of {@link RedisConnection#jsonCommands()}. */
@Override
@Deprecated
default List<Long> jsonArrAppend(byte @NonNull [] key, @NonNull JsonPath path, JsonValue @NonNull... values) {
return jsonCommands().jsonArrAppend(key, path, values);
}

/** @deprecated in favor of {@link RedisConnection#jsonCommands()}. */
@Override
@Deprecated
default List<Long> jsonArrIndex(byte @NonNull [] key, @NonNull JsonPath path, @NonNull JsonValue value) {
return jsonCommands().jsonArrIndex(key, path, value);
}

/** @deprecated in favor of {@link RedisConnection#jsonCommands()}. */
@Override
@Deprecated
default List<Long> jsonArrInsert(byte @NonNull [] key, @NonNull JsonPath path, int index, JsonValue @NonNull... values) {
return jsonCommands().jsonArrInsert(key, path, index, values);
}

/** @deprecated in favor of {@link RedisConnection#jsonCommands()}. */
@Override
@Deprecated
default List<Long> jsonArrLen(byte @NonNull [] key, @NonNull JsonPath path) {
return jsonCommands().jsonArrLen(key, path);
}

/** @deprecated in favor of {@link RedisConnection#jsonCommands()}. */
@Override
@Deprecated
default List<Long> jsonArrTrim(byte @NonNull [] key, @NonNull JsonPath path, int start, int stop) {
return jsonCommands().jsonArrTrim(key, path, start, stop);
}

/** @deprecated in favor of {@link RedisConnection#jsonCommands()}. */
@Override
@Deprecated
default Long jsonClear(byte @NonNull [] key, @NonNull JsonPath path) {
return jsonCommands().jsonClear(key, path);
}

/** @deprecated in favor of {@link RedisConnection#jsonCommands()}. */
@Override
@Deprecated
default Long jsonDel(byte @NonNull [] key, @NonNull JsonPath path) {
return jsonCommands().jsonDel(key, path);
}

/** @deprecated in favor of {@link RedisConnection#jsonCommands()}. */
@Override
@Deprecated
default String jsonGet(byte @NonNull [] key, @NonNull JsonPath @NonNull... paths) {
return jsonCommands().jsonGet(key, paths);
}

/** @deprecated in favor of {@link RedisConnection#jsonCommands()}. */
@Override
@Deprecated
default Boolean jsonMerge(byte @NonNull [] key, @NonNull JsonPath path, @NonNull JsonValue value) {
return jsonCommands().jsonMerge(key, path, value);
}

/** @deprecated in favor of {@link RedisConnection#jsonCommands()}. */
@Override
@Deprecated
default List<String> jsonMGet(@NonNull JsonPath path, byte @NonNull []... keys) {
return jsonCommands().jsonMGet(path, keys);
}

/** @deprecated in favor of {@link RedisConnection#jsonCommands()}. */
@Override
@Deprecated
default Boolean jsonSet(byte @NonNull [] key, @NonNull JsonPath path, @NonNull JsonValue value, @NonNull JsonSetCondition condition) {
return jsonCommands().jsonSet(key, path, value, condition);
}

/** @deprecated in favor of {@link RedisConnection#jsonCommands()}. */
@Override
@Deprecated
default List<Long> jsonStrAppend(byte @NonNull [] key, @NonNull JsonPath path, @NonNull String value) {
return jsonCommands().jsonStrAppend(key, path, value);
}

/** @deprecated in favor of {@link RedisConnection#jsonCommands()}. */
@Override
@Deprecated
default List<Long> jsonStrLen(byte @NonNull [] key, @NonNull JsonPath path) {
return jsonCommands().jsonStrLen(key, path);
}

/** @deprecated in favor of {@link RedisConnection#jsonCommands()}. */
@Override
@Deprecated
default List<Boolean> jsonToggle(byte @NonNull [] key, @NonNull JsonPath path) {
return jsonCommands().jsonToggle(key, path);
}

/** @deprecated in favor of {@link RedisConnection#jsonCommands()}. */
@Override
@Deprecated
default List<JsonType> jsonType(byte @NonNull [] key, @NonNull JsonPath path) {
return jsonCommands().jsonType(key, path);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Copyright 2026-present 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.
* You may obtain a copy of the License at
*
* https://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.
*/
package org.springframework.data.redis.connection;

/**
* Condition for {@code JSON.SET} command.
*
* @author Yordan Tsintsov
* @since 4.2
*/
public class JsonSetCondition {

private static final JsonSetCondition UPSERT = new JsonSetCondition(PathCondition.UPSERT);
private static final JsonSetCondition IF_PATH_NOT_EXISTS = new JsonSetCondition(PathCondition.IF_PATH_NOT_EXISTS);
private static final JsonSetCondition IF_PATH_EXISTS = new JsonSetCondition(PathCondition.IF_PATH_EXISTS);

private final PathCondition pathCondition;

private JsonSetCondition(PathCondition pathCondition) {
this.pathCondition = pathCondition;
}

/**
* Do not set any additional command argument.
*
* @return {@link JsonSetCondition#UPSERT}
*/
public static JsonSetCondition upsert() {
return UPSERT;
}

/**
* Perform the {@code JSON.SET} operation only if the path does not exist.
*
* @return {@link JsonSetCondition#IF_PATH_NOT_EXISTS}
*/
public static JsonSetCondition ifPathNotExists() {
return IF_PATH_NOT_EXISTS;
}

/**
* Perform the {@code JSON.SET} operation only if the path exists.
*
* @return {@link JsonSetCondition#IF_PATH_EXISTS}
*/
public static JsonSetCondition ifPathExists() {
return IF_PATH_EXISTS;
}

/**
* Get the path condition.
*
* @return the path condition.
*/
public PathCondition getPathCondition() {
return pathCondition;
}

/**
* Condition for {@code JSON.SET} command path presence.
*/
public enum PathCondition {

/**
* Do not set any additional command argument.
*/
UPSERT,

/**
* {@code NX}
*/
IF_PATH_NOT_EXISTS,

/**
* {@code XX}
*/
IF_PATH_EXISTS

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
@NullUnmarked
public interface RedisCommands extends RedisKeyCommands, RedisStringCommands, RedisListCommands, RedisSetCommands,
RedisZSetCommands, RedisHashCommands, RedisTxCommands, RedisPubSubCommands, RedisConnectionCommands,
RedisServerCommands, RedisStreamCommands, RedisScriptingCommands, RedisGeoCommands, RedisHyperLogLogCommands {
RedisServerCommands, RedisStreamCommands, RedisScriptingCommands, RedisGeoCommands, RedisHyperLogLogCommands,
RedisJsonCommands {

/**
* {@literal Native} or {@literal raw} execution of the given Redis command along with the given arguments.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,13 @@ public interface RedisCommandsProvider {
* @since 2.0
*/
RedisZSetCommands zSetCommands();

/**
* Get {@link RedisJsonCommands}.
*
* @return never {@literal null}.
* @since 4.2
*/
RedisJsonCommands jsonCommands();

}
Loading
Loading