jedis-pojo

Simple self-loading pojo cache service based on Jedis.

License

License

Categories

Categories

Jedis Data Databases
GroupId

GroupId

io.interact
ArtifactId

ArtifactId

jedis-pojo
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

jedis-pojo
Simple self-loading pojo cache service based on Jedis.
Project URL

Project URL

https://github.com/bascan/jedis-pojo
Source Code Management

Source Code Management

https://github.com/bascan/jedis-pojo.git

Download jedis-pojo

How to add to project

<!-- https://jarcasting.com/artifacts/io.interact/jedis-pojo/ -->
<dependency>
    <groupId>io.interact</groupId>
    <artifactId>jedis-pojo</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/io.interact/jedis-pojo/
implementation 'io.interact:jedis-pojo:1.0.0'
// https://jarcasting.com/artifacts/io.interact/jedis-pojo/
implementation ("io.interact:jedis-pojo:1.0.0")
'io.interact:jedis-pojo:jar:1.0.0'
<dependency org="io.interact" name="jedis-pojo" rev="1.0.0">
  <artifact name="jedis-pojo" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.interact', module='jedis-pojo', version='1.0.0')
)
libraryDependencies += "io.interact" % "jedis-pojo" % "1.0.0"
[io.interact/jedis-pojo "1.0.0"]

Dependencies

compile (2)

Group / Artifact Type Version
redis.clients : jedis jar 2.7.3
com.fasterxml.jackson.core : jackson-databind jar 2.6.3

test (2)

Group / Artifact Type Version
junit : junit jar 4.11
org.mockito : mockito-all jar 1.10.8

Project Modules

There are no modules declared in this project.

jedis-pojo

Simple self-loading pojo cache service based on Jedis. You can find the latest release on Maven Central: http://search.maven.org under:

  • Group ID: io.interact
  • Artifact ID: jedis-pojo
Usage:

Here's an example the shows you how to use the self-loading capability of the cache. You basically pass a Supplier with a lambda to the CacheService, which is invoked when the instance was not found.

// Get an instance of MyModelClass from the cache located at endpoint 'localhost' when it was found.
// Otherwise, get it from the MyModelDao and put it in the cache with a TTL of 5 minutes.
CacheService cache = CacheServiceImpl.getInstance("localhost"));
MyModelClass result = cache.get(key, () -> {
                return MyModelDao.get(key);
            } , MyModelClass.class, 300);

Note that you can use a custom port as well:

CacheService cache = CacheServiceImpl.getInstance("localhost:12345"));

Here's an example of the put and evict methods:

CacheService cache = CacheServiceImpl.getInstance("localhost"));
// Put myInstance in the cache for a minute.
cache.put(key, myInstance, 60);

// And evict it
cache.evict(key);

This library also implements redis set capabilities:

CacheService cache = CacheServiceImpl.getInstance("localhost");
// Add instances to my set. 
Set<MyInstance> instances = new HashSet<>(Arrays.asList(myInstance1, myInstance2));
cache.addToSet(key, instances);

// Fetch set content
Set<MyInstance> cachedInstances = cache.getMembers(key, () -> dao.getSet(key), MyInstance.class);

//evict cache
cache.evict(key);

It is also possible to do batch inserts and deletes to the redis sets:

Map<String, Set<Object>> inserts = new HashMap<>();
inserts.put(key, new HashSet<>(Arrays.asList(myInstance)));
inserts.put(key2, new HashSet<>(Arrays.asList(otherInstance)));

Map<String, Set<Object>> deletes = new HashMap<>();
deletes.put(key3, new HashSet<>(Arrays.asList(myInstance2)));

cache.bulkSetInsertAndDelete(deletes, inserts);
Optional:

Exclude jackson-databind to avoid version conflicts, which can typically happen when it is loaded as a transitive dependency by e.g. Dropwizard and Jersey.

<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.6.3</version>

Versions

Version
1.0.0
0.0.2
0.0.1