Skip to content

eclipse-ecsp/cache-enabler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

33 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Cache-Enabler

Build And Sonar scan License Compliance Deployment

The cache-enabler project provides Redis Server-backed caching capabilities to the services. It uses rich API objects support provided by a Redisson library and implements the execution of both synchronous and asynchronous commands on the Redis Server. Synchronous methods bear asynchronous variants.

Following are the supported Redis connection configurations:

  1. Single node (default)
  2. Clustered nodes
  3. Sentinel nodes

cache-enabler supports CRUD operations into the Redis server for these objects:

  • Any entity type object along with the capability to add a score.
  • Any String object along with its score.

cache-enabler also provides the capability to perform CRUD operations on a Map of entities.

Each object has a mutationId which is meant to be returned in asynchronous operations

NOTE: Support for pipelined batch executions are provided through the .*Async() methods. Clients of redis-cache are encouraged to use Async methods to improve throughput. For typical store and forget or store and retrieve slightly later use cases, Async methods will bring about quite a bit of throughput improvement.

Table of Contents

Getting Started

To build the project in the local working directory after the project has been cloned/forked, run:

mvn clean install

from the command line interface.

Prerequisites

  1. Maven
  2. Java 17
  3. Copy pre-compiled binary of redis server and pdb into src/test/resources

Installation

How to set up maven

Install Java

Download pre-compiled Redis

Running the tests

mvn test

Or run a specific test

mvn test -Dtest="TheFirstUnitTest"

To run a method from within a test

mvn test -Dtest="TheSecondUnitTest#whenTestCase2_thenPrintTest2_1"

Deployment

The redis-cache project serves as a library for the services. It is not meant to be deployed as a service in a Cloud environment.

Usage

Add the following dependency in the target project

<dependency>
  <groupId>org.eclipse.ecsp</groupId>
  <artifactId>cache-enabler</artifactId>
  <version>1.X.X</version>
</dependency>

Cache Operations

Operation Parameter Required Parameter Type Parameter Description Output Type
getString key String Key in redis for a String value String
getString request GetStringRequest Object with key and boolean parameter for namespace enabled String
putString putRequest PutStringRequest Object with new value for a String key in redis and other additional information void
getEntity key String Key in redis for an IgniteEntity IgniteEntity
getEntity request GetEntityRequest Object with key and boolean parameter for namespace enabled IgniteEntity
putEntity putRequest PutEntityRequest Object representation with IgniteEntity as value to put into cache along with other information void
addStringToScoredSortedSet request AddScoredStringRequest Object with score, key and value for adding a String to a scored sorted set void
getStringsFromScoredSortedSet request GetScoredStringsRequest Object with key, start, end, namespaceEnabled and reversed boolean parameter for getting a range of String from a scored sorted set List<String>
getEntitiesFromScoredSortedSet request GetScoredEntitiesRequest Object with key, start, end, namespaceEnabled and reversed boolean parameter for getting a range of IgniteEntity from a scored sorted set List<IgniteEntity>
addEntityToScoredSortedSet request AddScoredEntityRequest Object with key, entity, score, mutation Id and boolean parameter namespace enabled for adding an IgniteEntity to a scored sorted set void
putStringAsync putRequest PutStringRequest Object with value and additional information to put a String in redis in asynchronous mode void
putEntityAsync putRequest PutEntityRequest Object representation with IgniteEntity as value to put into cache in asynchronous mode along with other information void
addStringToScoredSortedSetAsync request AddScoredStringRequest Object with key, value, score, mutation Id and boolean parameter namespaceEnabled for adding a String to a scored sorted set in asynchronous mode void
addEntityToScoredSortedSetAsync request AddScoredEntityRequest Object with key, entity, score, mutation Id and boolean parameter namespaceEnabled for adding an IgniteEntity to a scored sorted set in asynchronous mode void
delete key String Key in redis to delete void
delete request DeleteEntryRequest Object with key and boolean parameter for namespace enabled to delete a key void
deleteAsync request DeleteEntryRequest Object with key and boolean parameter for namespace enabled to delete a key in asynchronous mode void
putMapOfEntities mapRequest PutMapOfEntitiesRequest Object for putting a map of IgniteEntity into cache for a key void
getMapOfEntities mapRequest GetMapOfEntitiesRequest Object for getting a map of specific IgniteEntity specified by fields in the object for a key in the cache Map<String, IgniteEntity>
deleteMapOfEntities request DeleteMapOfEntitiesRequest Object for deleting a map of IgniteEntity specified by fields in the object for a key in the cache void

Redis connection configuration

All the redis related configuration needs to be specified on the environment, which can be referred here

Some configuration which decide the kind of connection to be made:

  1. For running the library as a client of Redis with sentinels, the services need to set the below property: redis.sentinels=<redis-sentinel-list>

  2. For running the library as a client of Redis clustered nodes, the services need to set the below property: redis.cluster.masters=<xxxxx>

  3. If the above two configurations are not specified, the default configuration will be applied to run the application as a client for a single Redis server instance, the host of which is specified by: redis.address=<xxxxxxx>

Health Check

IgniteCacheRedisImpl also serves as a health monitor for health monitoring provided by the ignite-utils dependency. If there are any exceptions raised in performing any operation with Redis, the health monitor is marked as Unhealthy.

Batch Operations

cache-enabler provides the capability to execute batch operations with Redis in a reliable way. If a thread was performing a batch operation and another thread performed RBatch.execute() at the same time, then first thread fails with IllegalStateException("Batch already has been executed").

Built With Dependencies

Dependency Purpose
Ignite Utils Provides logging support and health monitor for cache service
Ignite Transformers Provides serialization and deserialization
Test Containers Test Container support for testing in dockerized environment
Docker Java Java API client for docker
Redisson Redis Java Client with features of In-Memory Data Grid
Junit Testing framework
Mockito Test Mocking framework
Embedded Redis Redis embedded server for Java integration testing
Commons IO Library to assist with IO functionality

How to contribute

Please read CONTRIBUTING.md for details on our contribution guidelines, and the process for submitting pull requests to us.

Code of Conduct

Please read CODE_OF_CONDUCT.md for details on our code of conduct.

Authors

Kaushal Arora
Kaushal Arora

๐Ÿ“– ๐Ÿ‘€

See also the list of contributors who participated in this project.

Security Contact Information

Please read SECURITY.md to raise any security related issues.

Support

Please write to us at csp@harman.com

Troubleshooting

Please read CONTRIBUTING.md for details on how to raise an issue and submit a pull request to us.

License

This project is licensed under the Apache-2.0 License - see the LICENSE file for details.

Announcements

All updates to this library are documented in our Release Notes and releases. For the versions available, see the tags on this repository.

About

Enabler for caching functionality

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages