-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
client-side caching with a new client impl and connection wrapper
simplify cache impls; some javadocs and tests more javadocs; invalidation handler on client basic support for max age in default impls initial PR feedback; naming consistencies checkpoint on wrapped connection push tracking status down to actual conn impl simplify cache impls to just LRU backed by LinkedHashMap cleanup client wrapper; test simple operation docs update
- Loading branch information
Showing
18 changed files
with
1,338 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
src/main/generated/io/vertx/redis/client/CachingRedisOptionsConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package io.vertx.redis.client; | ||
|
||
import io.vertx.core.json.JsonObject; | ||
import io.vertx.core.json.JsonArray; | ||
import io.vertx.core.json.impl.JsonUtil; | ||
import java.time.Instant; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.Base64; | ||
|
||
/** | ||
* Converter and mapper for {@link io.vertx.redis.client.CachingRedisOptions}. | ||
* NOTE: This class has been automatically generated from the {@link io.vertx.redis.client.CachingRedisOptions} original class using Vert.x codegen. | ||
*/ | ||
public class CachingRedisOptionsConverter { | ||
|
||
|
||
private static final Base64.Decoder BASE64_DECODER = JsonUtil.BASE64_DECODER; | ||
private static final Base64.Encoder BASE64_ENCODER = JsonUtil.BASE64_ENCODER; | ||
|
||
public static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json, CachingRedisOptions obj) { | ||
for (java.util.Map.Entry<String, Object> member : json) { | ||
switch (member.getKey()) { | ||
case "maxAge": | ||
if (member.getValue() instanceof Number) { | ||
obj.setMaxAge(((Number)member.getValue()).longValue()); | ||
} | ||
break; | ||
case "maxAgeUnit": | ||
if (member.getValue() instanceof String) { | ||
obj.setMaxAgeUnit(java.util.concurrent.TimeUnit.valueOf((String)member.getValue())); | ||
} | ||
break; | ||
case "maxCacheSize": | ||
if (member.getValue() instanceof Number) { | ||
obj.setMaxCacheSize(((Number)member.getValue()).intValue()); | ||
} | ||
break; | ||
case "mode": | ||
if (member.getValue() instanceof String) { | ||
obj.setMode(io.vertx.redis.client.ClientSideCacheMode.valueOf((String)member.getValue())); | ||
} | ||
break; | ||
case "prefix": | ||
if (member.getValue() instanceof String) { | ||
obj.setPrefix((String)member.getValue()); | ||
} | ||
break; | ||
case "prefixes": | ||
if (member.getValue() instanceof JsonArray) { | ||
java.util.ArrayList<java.lang.String> list = new java.util.ArrayList<>(); | ||
((Iterable<Object>)member.getValue()).forEach( item -> { | ||
if (item instanceof String) | ||
list.add((String)item); | ||
}); | ||
obj.setPrefixes(list); | ||
} | ||
break; | ||
case "prefixs": | ||
if (member.getValue() instanceof JsonArray) { | ||
((Iterable<Object>)member.getValue()).forEach( item -> { | ||
if (item instanceof String) | ||
obj.addPrefix((String)item); | ||
}); | ||
} | ||
break; | ||
} | ||
} | ||
} | ||
|
||
public static void toJson(CachingRedisOptions obj, JsonObject json) { | ||
toJson(obj, json.getMap()); | ||
} | ||
|
||
public static void toJson(CachingRedisOptions obj, java.util.Map<String, Object> json) { | ||
json.put("maxAge", obj.getMaxAge()); | ||
if (obj.getMaxAgeUnit() != null) { | ||
json.put("maxAgeUnit", obj.getMaxAgeUnit().name()); | ||
} | ||
json.put("maxCacheSize", obj.getMaxCacheSize()); | ||
if (obj.getMode() != null) { | ||
json.put("mode", obj.getMode().name()); | ||
} | ||
if (obj.getPrefixes() != null) { | ||
JsonArray array = new JsonArray(); | ||
obj.getPrefixes().forEach(item -> array.add(item)); | ||
json.put("prefixes", array); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/* | ||
* Copyright 2019 Red Hat, Inc. | ||
* <p> | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* and Apache License v2.0 which accompanies this distribution. | ||
* <p> | ||
* The Eclipse Public License is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* <p> | ||
* The Apache License v2.0 is available at | ||
* http://www.opensource.org/licenses/apache2.0.php | ||
* <p> | ||
* You may elect to redistribute this code under either of these licenses. | ||
*/ | ||
package io.vertx.redis.client; | ||
|
||
import io.vertx.core.Future; | ||
import io.vertx.core.Handler; | ||
import io.vertx.core.Vertx; | ||
import io.vertx.redis.client.impl.CachingRedisClient; | ||
import io.vertx.redis.client.impl.cache.CacheKey; | ||
|
||
import java.util.Collection; | ||
|
||
/** | ||
* A {@link Redis} client wrapper that implements client-side caching. | ||
* | ||
* @see <a href="https://redis.io/docs/manual/client-side-caching/">Client-side caching in Redis</a> | ||
*/ | ||
public interface CachingRedis extends Redis { | ||
|
||
/** | ||
* Create a new caching client using default client and cache options. | ||
* | ||
* @param vertx the vertx instance | ||
* @return the caching client | ||
*/ | ||
static CachingRedis create(Vertx vertx) { | ||
return create(vertx, Redis.createClient(vertx)); | ||
} | ||
|
||
/** | ||
* Create a new caching client wrapping an existing redis client with default caching options. | ||
* | ||
* @param vertx the vertx instance | ||
* @param redis the redis client to wrap | ||
* @return the caching client | ||
*/ | ||
static CachingRedis create(Vertx vertx, Redis redis) { | ||
return create(vertx, redis, RedisClientCache.lru(new CachingRedisOptions())); | ||
} | ||
|
||
/** | ||
* Create a new caching client using default client and cache options, backed by a given cache. | ||
* | ||
* @param vertx the vertx instance | ||
* @param cache the backing cache | ||
* @return the caching client | ||
*/ | ||
static CachingRedis create(Vertx vertx, RedisClientCache cache) { | ||
return create(vertx, Redis.createClient(vertx), cache); | ||
} | ||
|
||
/** | ||
* Create a new caching client wrapping an existing redis client and backed by a given cache. | ||
* | ||
* @param vertx the vertx instance | ||
* @param redis the redis client to wrap | ||
* @param cache the backing cache | ||
* @return the caching client | ||
*/ | ||
static CachingRedis create(Vertx vertx, Redis redis, RedisClientCache cache) { | ||
return create(vertx, redis, cache, new CachingRedisOptions()); | ||
} | ||
|
||
/** | ||
* Create a new caching client wrapping an existing redis client and using the given cache options. | ||
* | ||
* @param vertx the vertx instance | ||
* @param redis the redis client to wrap | ||
* @param options the cache options | ||
* @return the caching client | ||
*/ | ||
static CachingRedis create(Vertx vertx, Redis redis, CachingRedisOptions options) { | ||
return create(vertx, redis, RedisClientCache.lru(options), options); | ||
} | ||
|
||
/** | ||
* Create a new caching client wrapping an existing redis client, using the given cache and cache options. | ||
* | ||
* @param vertx the vertx instance | ||
* @param redis the redis client to wrap | ||
* @param cache the backing cache | ||
* @param options the cache options | ||
* @return the caching client | ||
*/ | ||
static CachingRedis create(Vertx vertx, Redis redis, RedisClientCache cache, CachingRedisOptions options) { | ||
return new CachingRedisClient(vertx, redis, cache, options); | ||
} | ||
|
||
/** | ||
* Flush the local cache. | ||
* | ||
* <p> | ||
* This operation only clears the local cache and has no interaction with the server. | ||
* | ||
* @return a future indicating the status of the operation | ||
*/ | ||
Future<Void> flush(); | ||
|
||
/** | ||
* Set a handler to be called when invalidation is performed. | ||
* | ||
* <p> | ||
* The client will clear the keys before this handler is invoked. It is not recommended to modify | ||
* the cache as a part of this handler. The primary function is for instrumentation. | ||
* | ||
* @param handler a handler that accepts the keys which were invalidated | ||
* @return fluent self | ||
*/ | ||
CachingRedis invalidationHandler(Handler<Collection<CacheKey>> handler); | ||
} |
Oops, something went wrong.