[英]Grails cache-redis version 1.1.0 plugin compile error
我在我的Grails 2.5.1應用程序中添加了cache-redis插件,並且編譯失敗。 GrailsRedisCache類未實現接口org.springframework.cache.Cache中的方法Cache.ValueWrapper putIfAbsent(Object var1,Object var2)。 是否有針對Grails 2.5.1和Cache 1.1.8的新Redis緩存插件?
BuildConfig.groovy編譯':cache:1.1.8'編譯“ org.grails.plugins:cache-redis:1.1.0”
.../plugins/cache-redis-1.1.0/src/java/grails/plugin/cache/redis/GrailsRedisCache.java:39: error: GrailsRedisCache is not abstract and does not override abstract method putIfAbsent(Object,Object) in Cache
putIfAbsent方法的可能實現。
@Override
public ValueWrapper putIfAbsent(Object o, Object o1) {
ValueWrapper val = get(o);
if (null != val) {
return val;
}
put(o, o1);
return get(o);
}
在GitHub上實現了putIfAbsent()方法。 不知道為什么該插件尚未在Grails.org上發布 。
@SuppressWarnings("unchecked")
@Override
public ValueWrapper putIfAbsent(final Object key, final Object value) {
final byte[] k = computeKey(key);
return (ValueWrapper) template.execute(new RedisCallback<ValueWrapper>() {
public ValueWrapper doInRedis(RedisConnection connection) throws DataAccessException {
waitForLock(connection);
byte[] bs = connection.get(computeKey(key));
if (bs == null) {
connection.multi();
connection.set(k, template.getValueSerializer().serialize(value));
connection.zAdd(setName, 0, k);
// Set key time to live when expiration has been configured.
if (ttl > NEVER_EXPIRE) {
connection.expire(k, ttl);
connection.expire(setName, ttl);
}
connection.exec();
}
bs = connection.get(computeKey(key));
return (bs == null ? null : newValueWrapper(template.getValueSerializer().deserialize(bs)));
}
}, true);
}
已發布cache-redis版本1.1.2-SNAPSHOT並解決了此問題。
compile ':cache-redis:1.1.2-SNAPSHOT'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.