diff --git a/src/main/asciidoc/introduction/getting-started.adoc b/src/main/asciidoc/introduction/getting-started.adoc index 17aa10ad9..7ef85cfe1 100644 --- a/src/main/asciidoc/introduction/getting-started.adoc +++ b/src/main/asciidoc/introduction/getting-started.adoc @@ -11,7 +11,7 @@ As explained in <>, Spring Data Redis (SDR) provides integrati [[get-started:first-steps:spring]] === Knowing Spring -Spring Data uses heavily Spring framework's http://docs.spring.io/spring/docs/current/spring-framework-reference/html/spring-core.html[core] functionality, such as the http://docs.spring.io/spring/docs/current/spring-framework-reference/html/beans.html[IoC] container, http://docs.spring.io/spring/docs/current/spring-framework-reference/html/resources.html[resource] abstract or http://docs.spring.io/spring/docs/current/spring-framework-reference/html/aop.html[AOP] infrastructure. While it is not important to know the Spring APIs, understanding the concepts behind them is. At a minimum, the idea behind IoC should be familiar. That being said, the more knowledge one has about the Spring, the faster she will pick up Spring Data Redis. Besides the very comprehensive (and sometimes disarming) documentation that explains in detail the Spring Framework, there are a lot of articles, blog entries and books on the matter - take a look at the Spring Guides http://spring.io/guides[home page] for more information. In general, this should be the starting point for developers wanting to try Spring DR. +Spring Data uses heavily Spring framework's http://docs.spring.io/spring/docs/{springVersion}/spring-framework-reference/core.html[core] functionality, such as the http://docs.spring.io/spring/docs/{springVersion}/spring-framework-reference/core.html[IoC] container, http://docs.spring.io/spring/docs/{springVersion}/spring-framework-reference/core.html#resources[resource] abstract or http://docs.spring.io/spring/docs/{springVersion}/spring-framework-reference/core.html#aop[AOP] infrastructure. While it is not important to know the Spring APIs, understanding the concepts behind them is. At a minimum, the idea behind IoC should be familiar. That being said, the more knowledge one has about the Spring, the faster she will pick up Spring Data Redis. Besides the very comprehensive (and sometimes disarming) documentation that explains in detail the Spring Framework, there are a lot of articles, blog entries and books on the matter - take a look at the Spring Guides http://spring.io/guides[home page] for more information. In general, this should be the starting point for developers wanting to try Spring DR. [[get-started:first-steps:nosql]] === Knowing NoSQL and Key Value stores @@ -36,7 +36,7 @@ The Spring Data tag on http://stackoverflow.com/questions/tagged/spring-data[Sta [[get-started:help:professional]] === Professional Support -Professional, from-the-source support, with guaranteed response time, is available from http://www.gopivotal.com/[Pivotal Software, Inc.], the company behind Spring Data and Spring. +Professional, from-the-source support, with guaranteed response time, is available from http://www.pivotal.io/[Pivotal Software, Inc.], the company behind Spring Data and Spring. [[get-started:up-to-date]] == Following Development @@ -50,5 +50,5 @@ If you encounter a bug or want to suggest an improvement, please create a ticket To stay up to date with the latest news and announcements in the Spring eco system, subscribe to the Spring Community http://spring.io/[Portal]. -Lastly, you can follow the Spring http://spring.io/blog/[blog] or the project team (http://twitter.com/thomasdarimont[Thomas] and http://twitter.com/stroblchristoph[Christoph]) on Twitter. +Lastly, you can follow the Spring http://spring.io/blog/[blog] or the project team (http://twitter.com/SpringData[@SpringData]) on Twitter. diff --git a/src/main/asciidoc/new-features.adoc b/src/main/asciidoc/new-features.adoc index 2a62d6f05..4df7939e4 100644 --- a/src/main/asciidoc/new-features.adoc +++ b/src/main/asciidoc/new-features.adoc @@ -7,14 +7,14 @@ New and noteworthy in the latest releases. == New in Spring Data Redis 2.0 * Upgrade to Java 8. +* Upgrade to Lettuce 5.0. * Removed support for SRP and JRedis drivers. -* Upgrade to `Lettuce` 5.0. -* Reactive connection support using https://github.com/lettuce-io/lettuce-core[lettuce-io/lettuce-core]. +* <>. * Introduce Redis feature-specific interfaces for `RedisConnection`. +* Improved `RedisConnectionFactory` configuration via `JedisClientConfiguration` and `LettuceClientConfiguration`. * Revised `RedisCache` implementation. * Add `SPOP` with count command for Redis 3.2. - [[new-in-1.8.0]] == New in Spring Data Redis 1.8 diff --git a/src/main/asciidoc/reference/redis-cluster.adoc b/src/main/asciidoc/reference/redis-cluster.adoc index 5e32b18b5..d74792528 100644 --- a/src/main/asciidoc/reference/redis-cluster.adoc +++ b/src/main/asciidoc/reference/redis-cluster.adoc @@ -3,8 +3,6 @@ Working with http://redis.io/topics/cluster-spec[Redis Cluster] requires a Redis Server version 3.0+ and provides a very own set of features and capabilities. Please refer to the http://redis.io/topics/cluster-tutorial[Cluster Tutorial] for more information. -TIP: Redis Cluster is only supported by <> and <>. - == Enabling Redis Cluster Cluster support is based on the very same building blocks as non clustered communication. `RedisClusterConnection` an extension to `RedisConnection` handles the communication with the Redis Cluster and translates errors into the Spring DAO exception hierarchy. @@ -65,7 +63,7 @@ public class AppConfig { - `spring.redis.cluster.max-redirects`: Number of allowed cluster redirections. ==== -NOTE: The initial configuration points driver libraries to an initial set of cluster nodes. Changes resulting from live cluster reconfiguration will only be kept in the native driver and not be written back to the configuration. +NOTE: The initial configuration points driver libraries to an initial set of cluster nodes. Changes resulting from live cluster reconfiguration will only be kept in the native driver and not be written back to the configuration. == Working With Redis Cluster Connection @@ -146,13 +144,13 @@ connection.mGet("foo", "bar"); < -> 127.0.0.1:7381 GET foo ==== -TIP: The above provided simple examples to demonstrate the general strategy followed by Spring Data Redis. Be aware that some operations might require loading huge amounts of data into memory in order to compute the desired command. Additionally not all cross slot requests can safely be ported to multiple single slot requests and will error if misused (eg. `PFCOUNT` ). +TIP: The above provided simple examples to demonstrate the general strategy followed by Spring Data Redis. Be aware that some operations might require loading huge amounts of data into memory in order to compute the desired command. Additionally not all cross slot requests can safely be ported to multiple single slot requests and will error if misused (eg. ``PFCOUNT``). == Working With RedisTemplate and ClusterOperations Please refer to the section <> to read about general purpose, configuration and usage of `RedisTemplate`. -WARNING: Please be careful when setting up `RedisTemplate#keySerializer` using any of the Json `RedisSerializers` as changing json structure has immediate influence on hash slot calculation. +WARNING: Please be careful when setting up `RedisTemplate#keySerializer` using any of the JSON `RedisSerializers` as changing json structure has immediate influence on hash slot calculation. `RedisTemplate` provides access to cluster specific operations via the `ClusterOperations` interface that can be obtained via `RedisTemplate.opsForCluster()`. This allows to execute commands explicitly on a single node within the cluster while retaining de-/serialization features configured for the template and provides administrative commands such as `CLUSTER MEET` or more high level operations for eg. resharding. diff --git a/src/main/asciidoc/reference/redis-messaging.adoc b/src/main/asciidoc/reference/redis-messaging.adoc index e659e1f62..0d93e4db8 100644 --- a/src/main/asciidoc/reference/redis-messaging.adoc +++ b/src/main/asciidoc/reference/redis-messaging.adoc @@ -18,7 +18,7 @@ To publish a message, one can use, as with the other operations, either the low- byte[] msg = ... byte[] channel = ... con.publish(msg, channel); // send message through RedisTemplate -RedisTemplate template = ... +RedisTemplate template = ... template.convertAndSend("hello!", "world"); ---- @@ -29,7 +29,7 @@ On the receiving side, one can subscribe to one or multiple channels either by n At the low-level, `RedisConnection` offers `subscribe` and `pSubscribe` methods that map the Redis commands for subscribing by channel respectively by pattern. Note that multiple channels or patterns can be used as arguments. To change the subscription of a connection or simply query whether it is listening or not, `RedisConnection` provides `getSubscription` and `isSubscribed` method. -NOTE: Subscription commands in Spring Data Redis are blocking. That is, calling subscribe on a connection will cause the current thread to block as it will start waiting for messages - the thread will be released only if the subscription is canceled, that is an additional thread invokes `unsubscribe` or `pUnsubscribe` on the *same* connection. See <> below for a solution to this problem. +NOTE: Subscription commands in Spring Data Redis are blocking. That is, calling subscribe on a connection will cause the current thread to block as it will start waiting for messages - the thread will be released only if the subscription is canceled, that is an additional thread invokes `unsubscribe` or `pUnsubscribe` on the *same* connection. See <> below for a solution to this problem. As mentioned above, once subscribed a connection starts waiting for messages. No other commands can be invoked on it except for adding new subscriptions or modifying/canceling the existing ones. That is, invoking anything other then `subscribe`, `pSubscribe`, `unsubscribe`, or `pUnsubscribe` is illegal and will throw an exception. @@ -55,18 +55,18 @@ Consider the following interface definition. Notice that although the interface [source,java] ---- -public interface MessageDelegate { +public interface MessageDelegate { void handleMessage(String message); - void handleMessage(Map message); void handleMessage(byte[] message); + void handleMessage(Map message); void handleMessage(byte[] message); void handleMessage(Serializable message); - // pass the channel/pattern as well - void handleMessage(Serializable message, String channel); + // pass the channel/pattern as well + void handleMessage(Serializable message, String channel); } ---- [source,java] ---- -public class DefaultMessageDelegate implements MessageDelegate { +public class DefaultMessageDelegate implements MessageDelegate { // implementation elided for clarity... } ---- @@ -76,20 +76,20 @@ In particular, note how the above implementation of the `MessageDelegate` interf [source,xml] ---- - - + - + - ... + ... ---- @@ -99,23 +99,23 @@ The example above uses the Redis namespace to declare the message listener conta [source,xml] ---- - + - + - + - + ---- diff --git a/src/main/asciidoc/reference/redis.adoc b/src/main/asciidoc/reference/redis.adoc index 4fa246c29..cdeeb539e 100644 --- a/src/main/asciidoc/reference/redis.adoc +++ b/src/main/asciidoc/reference/redis.adoc @@ -12,7 +12,7 @@ Spring Data Redis provides easy configuration and access to Redis from Spring ap [[redis:requirements]] == Redis Requirements -Spring Redis requires Redis 2.6 or above and Java SE 6.0 or above . In terms of language bindings (or connectors), Spring Redis integrates with http://github.com/xetorthio/jedis[Jedis] and http://github.com/mp911de/lettuce[Lettuce], four popular open source Java libraries for Redis. If you are aware of any other connector that we should be integrating with please send us feedback. +Spring Redis requires Redis 2.6 or above and Java SE 8.0 or above. In terms of language bindings (or connectors), Spring Redis integrates with http://github.com/xetorthio/jedis[Jedis] and http://github.com/lettuce-io/lettuce-core[Lettuce], two popular open source Java libraries for Redis. [[redis:architecture]] == Redis Support High Level View @@ -29,11 +29,11 @@ One of the first tasks when using Redis and Spring is to connect to the store th [[redis:connectors:connection]] === RedisConnection and RedisConnectionFactory -`RedisConnection` provides the building block for Redis communication as it handles the communication with the Redis back-end. It also automatically translates the underlying connecting library exceptions to Spring's consistent DAO exception http://docs.spring.io/spring/docs/current/spring-framework-reference/html/dao.html#dao-exceptions[hierarchy] so one can switch the connectors without any code changes as the operation semantics remain the same. +`RedisConnection` provides the building block for Redis communication as it handles the communication with the Redis back-end. It also automatically translates the underlying connecting library exceptions to Spring's consistent DAO exception http://docs.spring.io/spring/docs/{springVersion}/spring-framework-reference/data-access.html#dao-exceptions[hierarchy] so one can switch the connectors without any code changes as the operation semantics remain the same. NOTE: For the corner cases where the native library API is required, `RedisConnection` provides a dedicated method `getNativeConnection` which returns the raw, underlying object used for communication. -Active `RedisConnection` s are created through `RedisConnectionFactory`. In addition, the factories act as `PersistenceExceptionTranslator` s, meaning once declared, they allow one to do transparent exception translation. For example, exception translation through the use of the `@Repository` annotation and AOP. For more information see the dedicated http://docs.spring.io/spring/docs/current/spring-framework-reference/html/orm.html#orm-exception-translation[section] in Spring Framework documentation. +Active `RedisConnection` s are created through `RedisConnectionFactory`. In addition, the factories act as `PersistenceExceptionTranslator` s, meaning once declared, they allow one to do transparent exception translation. For example, exception translation through the use of the `@Repository` annotation and AOP. For more information see the dedicated http://docs.spring.io/spring/docs/{springVersion}/spring-framework-reference/data-access.html#orm-exception-translation[section] in Spring Framework documentation. NOTE: Depending on the underlying configuration, the factory can return a new connection or an existing connection (in case a pool or shared native connection is used). @@ -78,7 +78,7 @@ For production use however, one might want to tweak the settings such as the hos [[redis:connectors:lettuce]] === Configuring Lettuce connector -https://github.com/mp911de/lettuce[Lettuce] is the fourth open-source connector supported by Spring Data Redis through the `org.springframework.data.redis.connection.lettuce` package. +https://github.com/mp911de/lettuce[Lettuce] is a http://netty.io/[netty]-based open-source connector supported by Spring Data Redis through the `org.springframework.data.redis.connection.lettuce` package. Its configuration is probably easy to guess: @@ -102,8 +102,6 @@ There are also a few Lettuce-specific connection parameters that can be tweaked. For dealing with high available Redis there is support for http://redis.io/topics/sentinel[Redis Sentinel] using `RedisSentinelConfiguration`. -NOTE: Please note that currently only http://github.com/xetorthio/jedis[Jedis] and lettuce http://github.com/mp911de/lettuce[Lettuce] support Redis Sentinel. - [source,java] ---- /** @@ -111,18 +109,22 @@ NOTE: Please note that currently only http://github.com/xetorthio/jedis[Jedis] a */ @Bean public RedisConnectionFactory jedisConnectionFactory() { - RedisSentinelConfiguration sentinelConfig = new RedisSentinelConfiguration() .master("mymaster") - .sentinel("127.0.0.1", 26379) .sentinel("127.0.0.1", 26380); + RedisSentinelConfiguration sentinelConfig = new RedisSentinelConfiguration() + .master("mymaster") + .sentinel("127.0.0.1", 26379) + .sentinel("127.0.0.1", 26380); return new JedisConnectionFactory(sentinelConfig); } /** - * lettuce + * Lettuce */ @Bean public RedisConnectionFactory lettuceConnectionFactory() { - RedisSentinelConfiguration sentinelConfig = new RedisSentinelConfiguration().master("mymaster") - .sentinel("127.0.0.1", 26379) .sentinel("127.0.0.1", 26380); + RedisSentinelConfiguration sentinelConfig = new RedisSentinelConfiguration() + .master("mymaster") + .sentinel("127.0.0.1", 26379) + .sentinel("127.0.0.1", 26380); return new LettuceConnectionFactory(sentinelConfig); } ---- @@ -138,11 +140,10 @@ public RedisConnectionFactory lettuceConnectionFactory() { Sometimes direct interaction with the one of the Sentinels is required. Using `RedisConnectionFactory.getSentinelConnection()` or `RedisConnection.getSentinelCommands()` gives you access to the first active Sentinel configured. - [[redis:template]] == Working with Objects through RedisTemplate -Most users are likely to use `RedisTemplate` and its coresponding package `org.springframework.data.redis.core` - the template is in fact the central class of the Redis module due to its rich feature set. The template offers a high-level abstraction for Redis interactions. While `RedisConnection` offers low level methods that accept and return binary values (`byte` arrays), the template takes care of serialization and connection management, freeing the user from dealing with such details. +Most users are likely to use `RedisTemplate` and its corresponding package `org.springframework.data.redis.core` - the template is in fact the central class of the Redis module due to its rich feature set. The template offers a high-level abstraction for Redis interactions. While `RedisConnection` offers low level methods that accept and return binary values (`byte` arrays), the template takes care of serialization and connection management, freeing the user from dealing with such details. Moreover, the template provides operations views (following the grouping from Redis command http://redis.io/commands[reference]) that offer rich, generified interfaces for working against a certain type or certain key (through the `KeyBound` interfaces) as described below: @@ -154,8 +155,14 @@ Moreover, the template provides operations views (following the grouping from Re 2+^|_Key Type Operations_ -|ValueOperations -|Redis string (or value) operations +|GeoOperations +|Redis geospatial operations like `GEOADD`, `GEORADIUS`,...) + +|HashOperations +|Redis hash operations + +|HyperLogLogOperations +|Redis HyperLogLog operations like (`PFADD`, `PFCOUNT`,...) |ListOperations |Redis list operations @@ -163,22 +170,22 @@ Moreover, the template provides operations views (following the grouping from Re |SetOperations |Redis set operations +|ValueOperations +|Redis string (or value) operations + |ZSetOperations |Redis zset (or sorted set) operations -|HashOperations -|Redis hash operations - -|HyperLogLogOperations -|Redis HyperLogLog operations like (pfadd, pfcount,...) - -|GeoOperations -|Redis geospatial operations like `GEOADD`, `GEORADIUS`,...) - 2+^|_Key Bound Operations_ -|BoundValueOperations -|Redis string (or value) key bound operations +|BoundGeoOperations +|Redis key bound geospatial operations. + +|BoundHashOperations +|Redis hash key bound operations + +|BoundKeyOperations +|Redis key bound operations |BoundListOperations |Redis list key bound operations @@ -186,14 +193,12 @@ Moreover, the template provides operations views (following the grouping from Re |BoundSetOperations |Redis set key bound operations +|BoundValueOperations +|Redis string (or value) key bound operations + |BoundZSetOperations |Redis zset (or sorted set) key bound operations -|BoundHashOperations -|Redis hash key bound operations - -|BoundGeoOperations -|Redis key bound geospatial operations. |==== Once configured, the template is thread-safe and can be reused across multiple instances. @@ -290,9 +295,21 @@ public void useCallback() { From the framework perspective, the data stored in Redis is just bytes. While Redis itself supports various types, for the most part these refer to the way the data is stored rather than what it represents. It is up to the user to decide whether the information gets translated into Strings or any other objects. -The conversion between the user (custom) types and raw data (and vice-versa) is handled in Spring Data Redis through the `RedisSerializer` interface (package `org.springframework.data.redis.serializer`) which as the name implies, takes care of the serialization process. +The conversion between the user (custom) types and raw data (and vice-versa) is handled in Spring Data Redis in the `org.springframework.data.redis.serializer` package. -Multiple implementations are available out of the box, two of which have been already mentioned before in this documentation: the `StringRedisSerializer` and the `JdkSerializationRedisSerializer`. However one can use `OxmSerializer` for Object/XML mapping through Spring 3 http://docs.spring.io/spring/docs/current/spring-framework-reference/html/oxm.html[OXM] support or either `Jackson2JsonRedisSerializer` or `GenericJackson2JsonRedisSerializer` for storing data in http://en.wikipedia.org/wiki/JSON[JSON] format. +This package contains two types of serializers which as the name implies, takes care of the serialization process: + +* Two-way serializers based on`RedisSerializer`. +* Element readers and writers using `RedisElementReader` and `RedisElementWriter`. + +The main difference between these variants is that `RedisSerializer` primarily serializes to `byte[]` while readers and writers use `ByteBuffer`. + +Multiple implementations are available out of the box, two of which have been already mentioned before in this documentation: + +* the `StringRedisSerializer` +* `JdkSerializationRedisSerializer` + +However one can use `OxmSerializer` for Object/XML mapping through Spring http://docs.spring.io/spring/docs/{springVersion}/spring-framework-reference/data-access.html#oxm[OXM] support or either `Jackson2JsonRedisSerializer` or `GenericJackson2JsonRedisSerializer` for storing data in http://en.wikipedia.org/wiki/JSON[JSON] format. Do note that the storage format is not limited only to values - it can be used for keys, values or hashes without any restrictions. @@ -313,7 +330,7 @@ Hash mappers are converters to map objects to a `Map` and back. `HashMappe Multiple implementations are available out of the box: -1. `BeanUtilsHashMapper` using Spring's http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/beans/BeanUtils.html[BeanUtils]. +1. `BeanUtilsHashMapper` using Spring's http://docs.spring.io/spring/docs/{springVersion}/javadoc-api/org/springframework/beans/BeanUtils.html[BeanUtils]. 2. `ObjectHashMapper` using <>. 3. <> using https://github.com/FasterXML/jackson[FasterXML Jackson]. @@ -423,8 +440,8 @@ include::{referenceDir}/redis-scripting.adoc[] == Support Classes Package `org.springframework.data.redis.support` offers various reusable components that rely on Redis as a backing store. Currently the package contains various JDK-based -interface implementations on top of Redis such as http://download.oracle.com/javase/6/docs/api/java/util/concurrent/atomic/package-summary.html[atomic] counters and JDK -http://download.oracle.com/javase/6/docs/api/java/util/Collection.html[Collections]. +interface implementations on top of Redis such as http://download.oracle.com/javase/8/docs/api/java/util/concurrent/atomic/package-summary.html[atomic] counters and JDK +http://download.oracle.com/javase/8/docs/api/java/util/Collection.html[Collections]. The atomic counters make it easy to wrap Redis key incrementation while the collections allow easy management of Redis keys with minimal storage exposure or API leakage: in particular the `RedisSet` and `RedisZSet` interfaces offer easy access to the *set* operations supported by Redis such as `intersection` and `union` @@ -467,7 +484,7 @@ As shown in the example above, the consuming code is decoupled from the actual s NOTE: Changed in 2.0 -Spring Redis provides an implementation for Spring http://docs.spring.io/spring/docs/current/spring-framework-reference/html/cache.html[cache abstraction] through the `org.springframework.data.redis.cache` package. To use Redis as a backing implementation, simply add `RedisCacheManager` to your configuration: +Spring Redis provides an implementation for Spring http://docs.spring.io/spring/docs/{springVersion}/spring-framework-reference/integration.html#cache[cache abstraction] through the `org.springframework.data.redis.cache` package. To use Redis as a backing implementation, simply add `RedisCacheManager` to your configuration: [source,java] ---- diff --git a/src/main/java/org/springframework/data/redis/core/ReactiveRedisOperations.java b/src/main/java/org/springframework/data/redis/core/ReactiveRedisOperations.java index 4ff0da234..e89263f57 100644 --- a/src/main/java/org/springframework/data/redis/core/ReactiveRedisOperations.java +++ b/src/main/java/org/springframework/data/redis/core/ReactiveRedisOperations.java @@ -239,20 +239,53 @@ public interface ReactiveRedisOperations { // operation types /** - * Returns the operations performed on simple values (or Strings in Redis terminology). + * Returns geospatial specific operations interface. * - * @return value operations + * @return geospatial specific operations. */ - ReactiveValueOperations opsForValue(); + ReactiveGeoOperations opsForGeo(); /** - * Returns the operations performed on simple values (or Strings in Redis terminology) given a - * {@link RedisSerializationContext}. + * Returns geospatial specific operations interface. * * @param serializationContext serializers to be used with the returned operations, must not be {@literal null}. - * @return value operations. + * @return geospatial specific operations. */ - ReactiveValueOperations opsForValue(RedisSerializationContext serializationContext); + ReactiveGeoOperations opsForGeo(RedisSerializationContext serializationContext); + + /** + * Returns the operations performed on hash values. + * + * @param hash key (or field) type. + * @param hash value type. + * @return hash operations. + */ + ReactiveHashOperations opsForHash(); + + /** + * Returns the operations performed on hash values given a {@link RedisSerializationContext}. + * + * @param serializationContext serializers to be used with the returned operations, must not be {@literal null}. + * @param hash key (or field) type. + * @param hash value type. + * @return hash operations. + */ + ReactiveHashOperations opsForHash(RedisSerializationContext serializationContext); + + /** + * Returns the operations performed on multisets using HyperLogLog. + * + * @return never {@literal null}. + */ + ReactiveHyperLogLogOperations opsForHyperLogLog(); + + /** + * Returns the operations performed on multisets using HyperLogLog given a {@link RedisSerializationContext}. + * + * @param serializationContext serializers to be used with the returned operations, must not be {@literal null}. + * @return never {@literal null}. + */ + ReactiveHyperLogLogOperations opsForHyperLogLog(RedisSerializationContext serializationContext); /** * Returns the operations performed on list values. @@ -284,6 +317,22 @@ public interface ReactiveRedisOperations { */ ReactiveSetOperations opsForSet(RedisSerializationContext serializationContext); + /** + * Returns the operations performed on simple values (or Strings in Redis terminology). + * + * @return value operations + */ + ReactiveValueOperations opsForValue(); + + /** + * Returns the operations performed on simple values (or Strings in Redis terminology) given a + * {@link RedisSerializationContext}. + * + * @param serializationContext serializers to be used with the returned operations, must not be {@literal null}. + * @return value operations. + */ + ReactiveValueOperations opsForValue(RedisSerializationContext serializationContext); + /** * Returns the operations performed on zset values (also known as sorted sets). * @@ -300,55 +349,6 @@ public interface ReactiveRedisOperations { */ ReactiveZSetOperations opsForZSet(RedisSerializationContext serializationContext); - /** - * Returns the operations performed on multisets using HyperLogLog. - * - * @return never {@literal null}. - */ - ReactiveHyperLogLogOperations opsForHyperLogLog(); - - /** - * Returns the operations performed on multisets using HyperLogLog given a {@link RedisSerializationContext}. - * - * @param serializationContext serializers to be used with the returned operations, must not be {@literal null}. - * @return never {@literal null}. - */ - ReactiveHyperLogLogOperations opsForHyperLogLog(RedisSerializationContext serializationContext); - - /** - * Returns the operations performed on hash values. - * - * @param hash key (or field) type. - * @param hash value type. - * @return hash operations. - */ - ReactiveHashOperations opsForHash(); - - /** - * Returns the operations performed on hash values given a {@link RedisSerializationContext}. - * - * @param serializationContext serializers to be used with the returned operations, must not be {@literal null}. - * @param hash key (or field) type. - * @param hash value type. - * @return hash operations. - */ - ReactiveHashOperations opsForHash(RedisSerializationContext serializationContext); - - /** - * Returns geospatial specific operations interface. - * - * @return geospatial specific operations. - */ - ReactiveGeoOperations opsForGeo(); - - /** - * Returns geospatial specific operations interface. - * - * @param serializationContext serializers to be used with the returned operations, must not be {@literal null}. - * @return geospatial specific operations. - */ - ReactiveGeoOperations opsForGeo(RedisSerializationContext serializationContext); - /** * @return the {@link RedisSerializationContext}. */ diff --git a/src/main/java/org/springframework/data/redis/core/ReactiveRedisTemplate.java b/src/main/java/org/springframework/data/redis/core/ReactiveRedisTemplate.java index eee921392..1b4d168e0 100644 --- a/src/main/java/org/springframework/data/redis/core/ReactiveRedisTemplate.java +++ b/src/main/java/org/springframework/data/redis/core/ReactiveRedisTemplate.java @@ -102,119 +102,6 @@ public class ReactiveRedisTemplate implements ReactiveRedisOperations opsForValue() { - return opsForValue(serializationContext); - } - - /* (non-Javadoc) - * @see org.springframework.data.redis.core.ReactiveRedisOperations#opsForValue(org.springframework.data.redis.serializer.RedisSerializationContext) - */ - @Override - public ReactiveValueOperations opsForValue(RedisSerializationContext serializationContext) { - return new DefaultReactiveValueOperations<>(this, serializationContext); - } - - /* (non-Javadoc) - * @see org.springframework.data.redis.core.ReactiveRedisOperations#opsForList() - */ - @Override - public ReactiveListOperations opsForList() { - return opsForList(serializationContext); - } - - /* (non-Javadoc) - * @see org.springframework.data.redis.core.ReactiveRedisOperations#opsForList(org.springframework.data.redis.serializer.RedisSerializationContext) - */ - @Override - public ReactiveListOperations opsForList(RedisSerializationContext serializationContext) { - return new DefaultReactiveListOperations<>(this, serializationContext); - } - - /* (non-Javadoc) - * @see org.springframework.data.redis.core.ReactiveRedisOperations#opsForSet() - */ - @Override - public ReactiveSetOperations opsForSet() { - return opsForSet(serializationContext); - } - - /* (non-Javadoc) - * @see org.springframework.data.redis.core.ReactiveRedisOperations#opsForSet(org.springframework.data.redis.serializer.RedisSerializationContext) - */ - @Override - public ReactiveSetOperations opsForSet(RedisSerializationContext serializationContext) { - return new DefaultReactiveSetOperations<>(this, serializationContext); - } - - /* (non-Javadoc) - * @see org.springframework.data.redis.core.ReactiveRedisOperations#opsForZSet() - */ - @Override - public ReactiveZSetOperations opsForZSet() { - return opsForZSet(serializationContext); - } - - /* (non-Javadoc) - * @see org.springframework.data.redis.core.ReactiveRedisOperations#opsForZSet(org.springframework.data.redis.serializer.RedisSerializationContext) - */ - @Override - public ReactiveZSetOperations opsForZSet(RedisSerializationContext serializationContext) { - return new DefaultReactiveZSetOperations<>(this, serializationContext); - } - - /* (non-Javadoc) - * @see org.springframework.data.redis.core.ReactiveRedisOperations#opsForHyperLogLog() - */ - @Override - public ReactiveHyperLogLogOperations opsForHyperLogLog() { - return opsForHyperLogLog(serializationContext); - } - - /* (non-Javadoc) - * @see org.springframework.data.redis.core.ReactiveRedisOperations#opsForHyperLogLog(org.springframework.data.redis.serializer.RedisSerializationContext) - */ - @Override - public ReactiveHyperLogLogOperations opsForHyperLogLog( - RedisSerializationContext serializationContext) { - return new DefaultReactiveHyperLogLogOperations<>(this, serializationContext); - } - - /* (non-Javadoc) - * @see org.springframework.data.redis.core.ReactiveRedisOperations#opsForHash() - */ - @Override - public ReactiveHashOperations opsForHash() { - return opsForHash(serializationContext); - } - - /* (non-Javadoc) - * @see org.springframework.data.redis.core.ReactiveRedisOperations#opsForHash(org.springframework.data.redis.serializer.RedisSerializationContext) - */ - @Override - public ReactiveHashOperations opsForHash( - RedisSerializationContext serializationContext) { - return new DefaultReactiveHashOperations<>(this, serializationContext); - } - - /* (non-Javadoc) - * @see org.springframework.data.redis.core.ReactiveRedisOperations#opsForGeo() - */ - @Override - public ReactiveGeoOperations opsForGeo() { - return opsForGeo(serializationContext); - } - - /* (non-Javadoc) - * @see org.springframework.data.redis.core.ReactiveRedisOperations#opsForGeo(org.springframework.data.redis.serializer.RedisSerializationContext) - */ - @Override - public ReactiveGeoOperations opsForGeo(RedisSerializationContext serializationContext) { - return new DefaultReactiveGeoOperations<>(this, serializationContext); - } // ------------------------------------------------------------------------- // Execution methods @@ -548,6 +435,120 @@ public class ReactiveRedisTemplate implements ReactiveRedisOperations opsForGeo() { + return opsForGeo(serializationContext); + } + + /* (non-Javadoc) + * @see org.springframework.data.redis.core.ReactiveRedisOperations#opsForGeo(org.springframework.data.redis.serializer.RedisSerializationContext) + */ + @Override + public ReactiveGeoOperations opsForGeo(RedisSerializationContext serializationContext) { + return new DefaultReactiveGeoOperations<>(this, serializationContext); + } + + /* (non-Javadoc) + * @see org.springframework.data.redis.core.ReactiveRedisOperations#opsForHash() + */ + @Override + public ReactiveHashOperations opsForHash() { + return opsForHash(serializationContext); + } + + /* (non-Javadoc) + * @see org.springframework.data.redis.core.ReactiveRedisOperations#opsForHash(org.springframework.data.redis.serializer.RedisSerializationContext) + */ + @Override + public ReactiveHashOperations opsForHash( + RedisSerializationContext serializationContext) { + return new DefaultReactiveHashOperations<>(this, serializationContext); + } + + /* (non-Javadoc) + * @see org.springframework.data.redis.core.ReactiveRedisOperations#opsForHyperLogLog() + */ + @Override + public ReactiveHyperLogLogOperations opsForHyperLogLog() { + return opsForHyperLogLog(serializationContext); + } + + /* (non-Javadoc) + * @see org.springframework.data.redis.core.ReactiveRedisOperations#opsForHyperLogLog(org.springframework.data.redis.serializer.RedisSerializationContext) + */ + @Override + public ReactiveHyperLogLogOperations opsForHyperLogLog( + RedisSerializationContext serializationContext) { + return new DefaultReactiveHyperLogLogOperations<>(this, serializationContext); + } + + /* (non-Javadoc) + * @see org.springframework.data.redis.core.ReactiveRedisOperations#opsForList() + */ + @Override + public ReactiveListOperations opsForList() { + return opsForList(serializationContext); + } + + /* (non-Javadoc) + * @see org.springframework.data.redis.core.ReactiveRedisOperations#opsForList(org.springframework.data.redis.serializer.RedisSerializationContext) + */ + @Override + public ReactiveListOperations opsForList(RedisSerializationContext serializationContext) { + return new DefaultReactiveListOperations<>(this, serializationContext); + } + + /* (non-Javadoc) + * @see org.springframework.data.redis.core.ReactiveRedisOperations#opsForSet() + */ + @Override + public ReactiveSetOperations opsForSet() { + return opsForSet(serializationContext); + } + + /* (non-Javadoc) + * @see org.springframework.data.redis.core.ReactiveRedisOperations#opsForSet(org.springframework.data.redis.serializer.RedisSerializationContext) + */ + @Override + public ReactiveSetOperations opsForSet(RedisSerializationContext serializationContext) { + return new DefaultReactiveSetOperations<>(this, serializationContext); + } + + /* (non-Javadoc) + * @see org.springframework.data.redis.core.ReactiveRedisOperations#opsForValue() + */ + @Override + public ReactiveValueOperations opsForValue() { + return opsForValue(serializationContext); + } + + /* (non-Javadoc) + * @see org.springframework.data.redis.core.ReactiveRedisOperations#opsForValue(org.springframework.data.redis.serializer.RedisSerializationContext) + */ + @Override + public ReactiveValueOperations opsForValue(RedisSerializationContext serializationContext) { + return new DefaultReactiveValueOperations<>(this, serializationContext); + } + + /* (non-Javadoc) + * @see org.springframework.data.redis.core.ReactiveRedisOperations#opsForZSet() + */ + @Override + public ReactiveZSetOperations opsForZSet() { + return opsForZSet(serializationContext); + } + + /* (non-Javadoc) + * @see org.springframework.data.redis.core.ReactiveRedisOperations#opsForZSet(org.springframework.data.redis.serializer.RedisSerializationContext) + */ + @Override + public ReactiveZSetOperations opsForZSet(RedisSerializationContext serializationContext) { + return new DefaultReactiveZSetOperations<>(this, serializationContext); + } + /* (non-Javadoc) * @see org.springframework.data.redis.core.ReactiveRedisOperations#serialization() */ diff --git a/src/main/java/org/springframework/data/redis/core/RedisOperations.java b/src/main/java/org/springframework/data/redis/core/RedisOperations.java index 2f0f11a97..2c48ee1ab 100644 --- a/src/main/java/org/springframework/data/redis/core/RedisOperations.java +++ b/src/main/java/org/springframework/data/redis/core/RedisOperations.java @@ -496,20 +496,55 @@ public interface RedisOperations { // ------------------------------------------------------------------------- // operation types - /** - * Returns the operations performed on simple values (or Strings in Redis terminology). - * - * @return value operations - */ - ValueOperations opsForValue(); /** - * Returns the operations performed on simple values (or Strings in Redis terminology) bound to the given key. + * Returns the cluster specific operations interface. * - * @param key Redis key - * @return value operations bound to the given key + * @return never {@literal null}. + * @since 1.7 */ - BoundValueOperations boundValueOps(K key); + ClusterOperations opsForCluster(); + + /** + * Returns geospatial specific operations interface. + * + * @return never {@literal null}. + * @since 1.8 + */ + GeoOperations opsForGeo(); + + /** + * Returns geospatial specific operations interface bound to the given key. + * + * @param key must not be {@literal null}. + * @return never {@literal null}. + * @since 1.8 + */ + BoundGeoOperations boundGeoOps(K key); + + /** + *Returns the operations performed on hash values. + * + * @param hash key (or field) type + * @param hash value type + * @return hash operations + */ + HashOperations opsForHash(); + + /** + * Returns the operations performed on hash values bound to the given key. + * * @param hash key (or field) type + * @param hash value type + * @param key Redis key + * @return hash operations bound to the given key. + */ + BoundHashOperations boundHashOps(K key); + + /** + * @return + * @since 1.5 + */ + HyperLogLogOperations opsForHyperLogLog(); /** * Returns the operations performed on list values. @@ -541,6 +576,21 @@ public interface RedisOperations { */ BoundSetOperations boundSetOps(K key); + /** + * Returns the operations performed on simple values (or Strings in Redis terminology). + * + * @return value operations + */ + ValueOperations opsForValue(); + + /** + * Returns the operations performed on simple values (or Strings in Redis terminology) bound to the given key. + * + * @param key Redis key + * @return value operations bound to the given key + */ + BoundValueOperations boundValueOps(K key); + /** * Returns the operations performed on zset values (also known as sorted sets). * @@ -548,12 +598,6 @@ public interface RedisOperations { */ ZSetOperations opsForZSet(); - /** - * @return - * @since 1.5 - */ - HyperLogLogOperations opsForHyperLogLog(); - /** * Returns the operations performed on zset values (also known as sorted sets) bound to the given key. * @@ -562,50 +606,6 @@ public interface RedisOperations { */ BoundZSetOperations boundZSetOps(K key); - /** - * Returns the operations performed on hash values. - * - * @param hash key (or field) type - * @param hash value type - * @return hash operations - */ - HashOperations opsForHash(); - - /** - * Returns the operations performed on hash values bound to the given key. - * - * @param hash key (or field) type - * @param hash value type - * @param key Redis key - * @return hash operations bound to the given key. - */ - BoundHashOperations boundHashOps(K key); - - /** - * Returns geospatial specific operations interface. - * - * @return never {@literal null}. - * @since 1.8 - */ - GeoOperations opsForGeo(); - - /** - * Returns geospatial specific operations interface bound to the given key. - * - * @param key must not be {@literal null}. - * @return never {@literal null}. - * @since 1.8 - */ - BoundGeoOperations boundGeoOps(K key); - - /** - * Returns the cluster specific operations interface. - * - * @return never {@literal null}. - * @since 1.7 - */ - ClusterOperations opsForCluster(); - /** * @return the key {@link RedisSerializer}. */ diff --git a/src/main/java/org/springframework/data/redis/core/RedisTemplate.java b/src/main/java/org/springframework/data/redis/core/RedisTemplate.java index 4d867774f..9bc04b176 100644 --- a/src/main/java/org/springframework/data/redis/core/RedisTemplate.java +++ b/src/main/java/org/springframework/data/redis/core/RedisTemplate.java @@ -1116,24 +1116,112 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation /* * (non-Javadoc) - * @see org.springframework.data.redis.core.RedisOperations#boundValueOps(java.lang.Object) + * @see org.springframework.data.redis.core.RedisOperations#killClient(java.lang.Object) */ @Override - public BoundValueOperations boundValueOps(K key) { - return new DefaultBoundValueOperations<>(key, this); + public void killClient(final String host, final int port) { + + execute((RedisCallback) connection -> { + connection.killClient(host, port); + return null; + }); } /* * (non-Javadoc) - * @see org.springframework.data.redis.core.RedisOperations#opsForValue() + * @see org.springframework.data.redis.core.RedisOperations#getClientList() */ @Override - public ValueOperations opsForValue() { + public List getClientList() { + return execute(RedisServerCommands::getClientList); + } - if (valueOps == null) { - valueOps = new DefaultValueOperations<>(this); + /* + * @see org.springframework.data.redis.core.RedisOperations#slaveOf(java.lang.String, int) + */ + @Override + public void slaveOf(final String host, final int port) { + + execute((RedisCallback) connection -> { + + connection.slaveOf(host, port); + return null; + }); + } + + /* + * (non-Javadoc) + * @see org.springframework.data.redis.core.RedisOperations#slaveOfNoOne() + */ + @Override + public void slaveOfNoOne() { + + execute((RedisCallback) connection -> { + connection.slaveOfNoOne(); + return null; + }); + } + + /* + * (non-Javadoc) + * @see org.springframework.data.redis.core.RedisOperations#opsForCluster() + */ + @Override + public ClusterOperations opsForCluster() { + return new DefaultClusterOperations<>(this); + } + + /* + * (non-Javadoc) + * @see org.springframework.data.redis.core.RedisOperations#opsForGeo() + */ + @Override + public GeoOperations opsForGeo() { + + if (geoOps == null) { + geoOps = new DefaultGeoOperations<>(this); } - return valueOps; + return geoOps; + } + + /* + * (non-Javadoc) + * @see org.springframework.data.redis.core.RedisOperations#boundGeoOps(java.lang.Object) + */ + @Override + public BoundGeoOperations boundGeoOps(K key) { + return new DefaultBoundGeoOperations<>(key, this); + } + + /* + * (non-Javadoc) + * @see org.springframework.data.redis.core.RedisOperations#boundHashOps(java.lang.Object) + */ + @Override + public BoundHashOperations boundHashOps(K key) { + return new DefaultBoundHashOperations<>(key, this); + } + + /* + * (non-Javadoc) + * @see org.springframework.data.redis.core.RedisOperations#opsForHash() + */ + @Override + public HashOperations opsForHash() { + return new DefaultHashOperations<>(this); + } + + /* + * (non-Javadoc) + * @see org.springframework.data.redis.core.RedisOperations#opsForHyperLogLog() + */ + @Override + public HyperLogLogOperations opsForHyperLogLog() { + + if (hllOps == null) { + hllOps = new DefaultHyperLogLogOperations<>(this); + } + return hllOps; } /* @@ -1180,6 +1268,28 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation return setOps; } + /* + * (non-Javadoc) + * @see org.springframework.data.redis.core.RedisOperations#boundValueOps(java.lang.Object) + */ + @Override + public BoundValueOperations boundValueOps(K key) { + return new DefaultBoundValueOperations<>(key, this); + } + + /* + * (non-Javadoc) + * @see org.springframework.data.redis.core.RedisOperations#opsForValue() + */ + @Override + public ValueOperations opsForValue() { + + if (valueOps == null) { + valueOps = new DefaultValueOperations<>(this); + } + return valueOps; + } + /* * (non-Javadoc) * @see org.springframework.data.redis.core.RedisOperations#boundZSetOps(java.lang.Object) @@ -1202,116 +1312,6 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation return zSetOps; } - /* - * (non-Javadoc) - * @see org.springframework.data.redis.core.RedisOperations#opsForGeo() - */ - @Override - public GeoOperations opsForGeo() { - - if (geoOps == null) { - geoOps = new DefaultGeoOperations<>(this); - } - return geoOps; - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.core.RedisOperations#boundGeoOps(java.lang.Object) - */ - @Override - public BoundGeoOperations boundGeoOps(K key) { - return new DefaultBoundGeoOperations<>(key, this); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.core.RedisOperations#opsForHyperLogLog() - */ - @Override - public HyperLogLogOperations opsForHyperLogLog() { - - if (hllOps == null) { - hllOps = new DefaultHyperLogLogOperations<>(this); - } - return hllOps; - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.core.RedisOperations#boundHashOps(java.lang.Object) - */ - @Override - public BoundHashOperations boundHashOps(K key) { - return new DefaultBoundHashOperations<>(key, this); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.core.RedisOperations#opsForHash() - */ - @Override - public HashOperations opsForHash() { - return new DefaultHashOperations<>(this); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.core.RedisOperations#opsForCluster() - */ - @Override - public ClusterOperations opsForCluster() { - return new DefaultClusterOperations<>(this); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.core.RedisOperations#killClient(java.lang.Object) - */ - @Override - public void killClient(final String host, final int port) { - - execute((RedisCallback) connection -> { - connection.killClient(host, port); - return null; - }); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.core.RedisOperations#getClientList() - */ - @Override - public List getClientList() { - return execute(RedisServerCommands::getClientList); - } - - /* - * @see org.springframework.data.redis.core.RedisOperations#slaveOf(java.lang.String, int) - */ - @Override - public void slaveOf(final String host, final int port) { - - execute((RedisCallback) connection -> { - - connection.slaveOf(host, port); - return null; - }); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.redis.core.RedisOperations#slaveOfNoOne() - */ - @Override - public void slaveOfNoOne() { - - execute((RedisCallback) connection -> { - connection.slaveOfNoOne(); - return null; - }); - } - /** * If set to {@code true} {@link RedisTemplate} will use {@literal MULTI...EXEC|DISCARD} to keep track of operations. *