forked from grails/grails-redis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRedisGrailsPlugin.groovy
113 lines (96 loc) · 4.04 KB
/
RedisGrailsPlugin.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/* Copyright (C) 2011 SpringSource
*
* 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
*
* http://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.
*/
import grails.plugin.redis.RedisService
import redis.clients.jedis.JedisPool
import redis.clients.jedis.JedisPoolConfig
import redis.clients.jedis.JedisSentinelPool
import redis.clients.jedis.Protocol
class RedisGrailsPlugin {
def version = "1.4.1"
def grailsVersion = "2.0.0 > *"
def author = "Ted Naleid"
def authorEmail = "[email protected]"
def title = "Redis Plugin"
def description = '''The Redis plugin provides integration with a Redis datastore. Redis is a lightning fast 'data structure server'. The plugin enables a number of memoization techniques to cache results from complex operations in Redis.
'''
def issueManagement = [system: 'github', url: 'https://github.com/grails-plugins/grails-redis/issues']
def license = "APACHE"
def developers = [
[name: "Burt Beckwith"],
[name: "Brian Coles"],
[name: "Michael Cameron"],
[name: "Christian Oestreich"],
[name: "John Engelman"],
[name: "David Seiler"],
[name: "Jordon Saardchit"],
[name: "Florian Langenhahn"]
]
def pluginExcludes = [
"codenarc.properties",
"grails-app/conf/DataSource.groovy",
"grails-app/conf/redis-codenarc.groovy",
"grails-app/views/**",
"grails-app/domain/**",
"grails-app/services/test/**",
"test/**"
]
def scm = [url: "https://github.com/grails-plugins/grails-redis"]
def documentation = "http://grails.org/plugin/redis"
def doWithSpring = {
def redisConfigMap = application.config.grails.redis ?: [:]
configureService.delegate = delegate
configureService(redisConfigMap, "")
redisConfigMap?.connections?.each { connection ->
configureService(connection.value, connection?.key?.capitalize())
}
}
/**
* delegate to wire up the required beans.
*/
def configureService = {redisConfigMap, key ->
def poolBean = "redisPoolConfig${key}"
"${poolBean}"(JedisPoolConfig) {
// used to set arbitrary config values without calling all of them out here or requiring any of them
// any property that can be set on RedisPoolConfig can be set here
redisConfigMap.poolConfig.each { configkey, value ->
delegate.setProperty(configkey, value)
}
}
def host = redisConfigMap?.host ?: 'localhost'
def port = redisConfigMap?.port ?: Protocol.DEFAULT_PORT
def timeout = redisConfigMap?.timeout ?: Protocol.DEFAULT_TIMEOUT
def password = redisConfigMap?.password ?: null
def database = redisConfigMap?.database ?: Protocol.DEFAULT_DATABASE
def sentinels = redisConfigMap?.sentinels ?: null
def masterName = redisConfigMap?.masterName ?: null
// If sentinels and a masterName is present, using different pool implementation
if (sentinels && masterName) {
"redisPool${key}"(JedisSentinelPool, masterName, sentinels as Set, ref(poolBean), timeout, password, database) { bean ->
bean.destroyMethod = 'destroy'
}
}
else {
"redisPool${key}"(JedisPool, ref(poolBean), host, port, timeout, password, database) { bean ->
bean.destroyMethod = 'destroy'
}
}
//only wire up additional services when key provided for multiple connection support
if(key) {
"redisService${key}"(RedisService) {
redisPool = ref("redisPool${key}")
}
}
}
}