From 5d12e20c6dfb72576df6dbccf0dafe7d837ba423 Mon Sep 17 00:00:00 2001 From: Jennifer Hickey Date: Mon, 5 Aug 2013 13:53:14 -0700 Subject: [PATCH] Update pipeline and tx documentation --- .../docbook/reference/pipelining.xml | 43 +++++++++++++++++++ .../docbook/reference/redis-transactions.xml | 28 +++++++++--- .../src/reference/docbook/reference/redis.xml | 4 +- 3 files changed, 68 insertions(+), 7 deletions(-) create mode 100644 docs/src/reference/docbook/reference/pipelining.xml diff --git a/docs/src/reference/docbook/reference/pipelining.xml b/docs/src/reference/docbook/reference/pipelining.xml new file mode 100644 index 000000000..0bfe900da --- /dev/null +++ b/docs/src/reference/docbook/reference/pipelining.xml @@ -0,0 +1,43 @@ + +
+ Pipelining + Redis provides support for pipelining, which involves sending multiple + commands to the server without waiting for the replies and then reading the replies in a single step. Pipelining can improve performance + when you need to send several commands in a row, such as adding many elements to the same List. + + Spring Data Redis provides several RedisTemplate methods for executing commands in a pipeline. If you don't + care about the results of the pipelined operations, you can use the standard execute method, passing true + for the pipeline argument. The executePipelined methods will execute the provided RedisCallback or + SessionCallback in a pipeline and return the results. For example: + + + results = stringRedisTemplate.executePipelined(new RedisCallback() { + public Object doInRedis(RedisConnection connection) throws DataAccessException { + StringRedisConnection stringRedisConn = (StringRedisConnection)connection; + for(int i=0; i< batchSize; i++) { + stringRedisConn.rPop("myqueue"); + } + return null; + } +});]]> + + The example above executes a bulk right pop of items from a queue in a pipeline. The results List contains all of the popped items. + RedisTemplate uses its value, hash key, and hash value serializers to deserialize all results before returning, so the returned items in + the above example will be Strings. There are additional executePipelined methods that allow you to pass a custom serializer for pipelined results. + + + + Note that the value returned from the RedisCallback is required to be null, as this value is discarded in favor + of returning the results of the pipelined commands. + + + An important change has been made to the closePipeline method of RedisConnection in version 1.1. + Previously this method returned the results of pipelined operations directly from the connectors. This means that the data types often differed from those + returned by the methods of RedisConnection. For example, zAdd returns a boolean indicating + that the element has been added to the sorted set. Most connectors return this value as a long and Spring Data Redis performs the conversion. Another common + difference is that most connectors return a status reply (usually the String "OK") for operations like set. These replies are typically discarded by Spring Data Redis. + Prior to 1.1, these conversions were not performed on the results of closePipeline. If this change breaks your application, you can + set convertPipelineAndTxResults to false on your RedisConnectionFactory to disable this behavior. + + \ No newline at end of file diff --git a/docs/src/reference/docbook/reference/redis-transactions.xml b/docs/src/reference/docbook/reference/redis-transactions.xml index b0f381bf3..2eef5abc0 100644 --- a/docs/src/reference/docbook/reference/redis-transactions.xml +++ b/docs/src/reference/docbook/reference/redis-transactions.xml @@ -11,12 +11,28 @@ () { - public Object execute(RedisOperations operations) throws DataAccessException { +List txResults = redisTemplate.execute(new SessionCallback>() { + public List execute(RedisOperations operations) throws DataAccessException { operations.multi(); - operations.opsForValue().set("key", "value"); - List results = operations.exec(); - return null; + operations.opsForSet().add("key", "value1"); + // This will contain the results of all ops in the transaction + return operations.exec(); } -});]]> +}); +System.out.println("Number of items added to set: " + txResults.get(0)); +]]> + + RedisTemplate will use its value, hash key, and hash value serializers to deserialize all results of exec + before returning. There is an additional exec method that allows you to pass a custom serializer for transaction results. + + + An important change has been made to the exec methods of RedisConnection and RedisTemplate + in version 1.1. Previously these methods returned the results of transactions directly from the connectors. This means that the data types often differed from those + returned from the methods of RedisConnection. For example, zAdd returns a boolean indicating + that the element has been added to the sorted set. Most connectors return this value as a long and Spring Data Redis performs the conversion. Another common + difference is that most connectors return a status reply (usually the String "OK") for operations like set. These replies are typically discarded by Spring Data Redis. + Prior to 1.1, these conversions were not performed on the results of exec. Also, results were not deserialized in RedisTemplate, so they + often included raw byte arrays. If this change breaks your application, you can + set convertPipelineAndTxResults to false on your RedisConnectionFactory to disable this behavior. + \ No newline at end of file diff --git a/docs/src/reference/docbook/reference/redis.xml b/docs/src/reference/docbook/reference/redis.xml index f07465214..def31fdad 100644 --- a/docs/src/reference/docbook/reference/redis.xml +++ b/docs/src/reference/docbook/reference/redis.xml @@ -16,7 +16,7 @@
Redis Requirements - Spring Redis requires Redis 2.2 or above and Java SE 6.0 or above . + Spring Redis requires Redis 2.4 or above and Java SE 6.0 or above . In terms of language bindings (or connectors), Spring Redis integrates with Jedis, JRedis, SRP and @@ -399,6 +399,8 @@ + +