Redis Java client
We'd like to thank all the contributors who worked on this release!
@sazzad16 and @keeferrourke
This release supports server-assisted, client-side caching, and is currently beta grade.
Client-side caching is available within UnifiedJedis, JedisPooled, JedisCluster, etc classes via implementation of ClientSideCache class, with RESP3 only. It is recommended to use a ClientSideCache implementation with TTL (time-to-live). We have included two implementations based on Google Guava and Caffeine libraries.
import redis.clients.jedis.*;
import redis.clients.jedis.csc.*;
class CacheExample {
public static void main() {
HostAndPort node = HostAndPort.from("localhost:6379");
JedisClientConfig clientConfig = DefaultJedisClientConfig.builder()
.resp3() // RESP3 protocol
//.user("myuser") // Redis server username (optional)
//.password("mypass") // Redis user's password (optional)
.build();
ClientSideCache clientSideCache;
// Uncomment one of the following lines to use the corresponding cache backend
// GuavaClientSideCache clientSideCache = GuavaClientSideCache.builder().maximumSize(1000).ttl(100).build();
// CaffeineClientSideCache clientSideCache = CaffeineClientSideCache.builder().maximumSize(1000).ttl(100).build();
UnifiedJedis client = new UnifiedJedis(node, clientConfig, clientSideCache);
// JedisPooled client = new JedisPooled(node, clientConfig, clientSideCache);
// JedisCluster client = new JedisCluster(Collections.singleton(node), clientConfig, clientSideCache);
client.set("foo", "bar");
client.get("foo");
client.get("foo"); // cache hit
client.del("foo");
client.close();
}
}
It is highly recommended to use a ClientSideCache implementation with TTL.
Both of our provided GuavaClientSideCache and CaffeineClientSideCache have TTL support and use a default value when not set. It is discouraged to use ttl(0)
in these.
It is also a good idea to keep the idle connections busy to get more and updated notifications. It can be done easily using pool config:
GenericObjectPoolConfig<Connection> poolConfig = new ConnectionPoolConfig();
poolConfig.setTestWhileIdle(true); // ConnectionPoolConfig by default does this.
// It is still shown here for better understanding.
This pool config can be used as follows:
JedisPooled client = new JedisPooled(node, clientConfig, clientSideCache, poolConfig);
JedisCluster client = new JedisCluster(Collections.singleton(node), clientConfig, clientSideCache, poolConfig);
We'd like to thank all the contributors who worked on this release!
@sazzad16 and @stillerrr
We'd like to thank all the contributors who worked on this release!
@dependabot, @dependabot[bot], @jongwooo, @sazzad16 and @stillerrr
This release provides support for server-assisted, client-side caching, and is currently alpha grade.
Client-side caching is available within UnifiedJedis, JedisPooled, JedisCluster, etc classes via implementation of ClientSideCache class, with RESP3 only. It is recommended a ClientSideCache implementation with TTL (time-to-live). We have included two implementations based on Google Guava and Caffeine libraries.
class CacheExample {
public static void main() {
HostAndPort hnp = HostAndPort.from("localhost:6379");
JedisClientConfig config = DefaultJedisClientConfig.builder()
.resp3() // RESP3 protocol
.password("foobared")
.build();
ClientSideCache csc;
// ClientSideCache csc = GuavaCSC.builder().maximumSize(1000).ttl(100).build();
// ClientSideCache csc = CaffeineCSC.builder().maximumSize(1000).ttl(100).build();
UnifiedJedis client = new UnifiedJedis(hnp, config, csc);
// JedisPooled client = new JedisPooled(hnp, config, csc);
// JedisCluster client = new JedisCluster(Collections.singleton(hnp), config, csc);
client.set("foo", "bar");
client.get("foo");
client.get("foo"); // cache hit
client.del("foo");
client.close();
}
}
This release provides support for server-assisted, client-side caching, and is currently alpha grade. Currently it is supported on top of the Jedis class, and will be merged to Jedis/UnifiedJedis classes via configuration parameters.
Client-side caching is available through JedisClientSideCache class, with RESP3 only.
Note: The process of ensuring the last invalidation when there is none, is still time consuming; it is suggested to use a smaller socket timeout if this is an issue. We have started with only GET command at this moment.
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisClientConfig;
import redis.clients.jedis.DefaultJedisClientConfig;
import redis.clients.jedis.JedisClientSideCache;
class CacheExample {
public static void main() {
HostAndPort hnp = HostAndPort.from("localhost:6379");
JedisClientConfig config = DefaultJedisClientConfig.builder()
.resp3() // RESP3 protocol
.socketTimeoutMillis(20) // smaller socket timeout
.password("foobared")
.build();
JedisClientSideCache jCache = new JedisClientSideCache(hnp, config);
jCache.set("foo", "bar");
jCache.get("foo");
jCache.get("foo"); // cache hit
jCache.del("foo");
jCache.close();
}
}
Re-released as 5.2.0-alpha2.
We'd like to thank all the contributors who worked on this release!
@bsbodden, @chayim, @dependabot, @dependabot[bot], @ihaohong, @sazzad16, @wormogig and @yangbodong22011