////
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you 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.
////

Add the plugin to the `dependencies` block of your `build.gradle`. The version is managed by the Grails BOM, so it does not need to be specified:

[source,groovy]
----
dependencies {
    implementation 'org.apache.grails:grails-redis'
}
----

Out of the box, the plugin expects Redis to be running on `localhost:6379`. The easiest way to run a local instance for development and testing is with Docker:

[source,bash]
----
docker run -d --name redis -p 6379:6379 redis
----

The connection — along with any pool configuration options — can be customized under the `grails.redis` key in `grails-app/conf/application.yml`. A connection requires *either* a `host` and `port` combination *or* a `sentinels` and `masterName` combination:

[source,yaml]
----
grails:
    redis:
        poolConfig:
            # any property exposed by the Jedis `JedisPoolConfig` may be set here, for example:
            # testWhileIdle: true
            # maxTotal: 10
            # maxIdle: 8
        timeout: 2000              # connection timeout in milliseconds (default)
        password: somepassword     # defaults to no password
        useSSL: false              # set to true to connect over SSL

        # --- Option 1: a single Redis server (use only if NOT using a sentinel cluster) ---
        host: localhost
        port: 6379
        database: 5                # selects the Redis database to use

        # --- Option 2: a redis-sentinel cluster (use only if NOT using host/port) ---
        sentinels:                 # list of sentinel instance host/ports
            - host1:6379
            - host2:6379
            - host3:6379
        masterName: mymaster       # the name of the master the sentinel cluster is configured to monitor
----

The `poolConfig` section lets you tweak any of the setter values exposed by Jedis' https://github.com/redis/jedis/blob/master/src/main/java/redis/clients/jedis/JedisPoolConfig.java[`JedisPoolConfig`], which implements the Apache Commons https://commons.apache.org/proper/commons-pool/apidocs/org/apache/commons/pool2/impl/GenericObjectPool.html[`GenericObjectPool`].

NOTE: See the https://redis.io/topics/sentinel[Redis Sentinel documentation] for more information on using redis-sentinel for high availability.
