The Spring Data Aerospike project aims to provide a familiar and consistent Spring-based programming model for new data stores while retaining store-specific features and capabilities. It provides integration with the Aerospike database. Key functional areas of Spring Data Aerospike are a POJO centric model for interacting with Aerospike DB and easily writing a repository style data access layer.
-
Spring Data Aerospike Documentation Reference
-
Java code documentation on javadoc.io
-
Aerospike Official Documentation
-
If you are new to Spring as well as to Spring Data, look for information about Spring Projects
Compatibility Table
Spring Data Aerospike | Spring Boot | Aerospike Client | Aerospike Reactor Client | Aerospike Server |
---|---|---|---|---|
4.8.x |
3.3.x |
7.2.x |
7.1.x |
5.2.x.x |
4.7.x |
3.2.x |
7.2.x |
7.1.x |
5.2.x.x |
4.6.x |
3.2.x |
7.2.x |
7.1.x |
5.2.x.x |
4.5.x |
3.1.x |
7.1.x |
7.0.x |
5.2.x.x |
4.4.x |
3.1.x |
7.0.x |
7.0.x |
5.2.x.x |
4.3.x |
3.1.x |
6.1.x |
6.1.x |
5.2.x.x |
4.2.x |
3.0.x |
6.1.x |
6.1.x |
5.2.x.x |
4.1.x |
3.0.x |
6.1.x |
6.1.x |
5.2.x.x |
3.5.x |
2.7.x |
6.1.x |
6.1.x |
5.2.x.x |
3.4.x |
2.6.x |
5.1.x |
5.1.x |
5.2.x.x |
3.3.x |
2.5.x |
5.1.x |
5.1.x |
5.2.x.x |
3.2.x |
2.5.x |
5.1.x |
5.0.x |
5.2.x.x |
3.0.x, 3.1.x |
2.5.x |
5.1.x |
5.0.x |
|
2.5.x |
2.5.x |
4.4.x |
4.4.x |
|
2.4.2.RELEASE |
2.3.x |
4.4.x |
4.4.x |
|
2.3.5.RELEASE |
2.2.x |
4.4.x |
4.4.x |
|
2.1.1.RELEASE |
2.1.x, 2.0.x |
4.4.x |
3.2.x |
|
1.2.1.RELEASE |
1.5.x |
4.1.x |
Add the spring-data-aerospike
Maven dependency:
<dependency>
<groupId>com.aerospike</groupId>
<artifactId>spring-data-aerospike</artifactId>
<version>${spring-data-aerospike.version}</version>
</dependency>
Notes:
-
It is recommended to use the latest version. Check out Spring Data Aerospike GitHub releases
-
Spring Data Aerospike uses the Aerospike Java Client (and Aerospike Reactive Java Client) under the hood
AerospikeRepository
is the simplest way to interact with Aerospike using Spring Data Aerospike.
Create your own custom repository that extends AerospikeRepository
which will provide out-of-the-box CRUD operations
and query implementations, so you can easily save, find, delete and query single entities and collections of them.
Implementation will be determined by the method names automatically, no need to write any implementation.
For example, given a Person
class with first and last name properties,
a PersonRepository
interface that can query for Person
by last name
and when the first name matches a like expression is shown below:
public interface PersonRepository extends AerospikeRepository<Person, Long> {
List<Person> findByLastname(String lastname);
List<Person> findByFirstnameLike(String firstname);
}
For non-blocking reactive API use ReactiveAerospikeRepository
.
In order to configure Spring Data Aerospike you will need to create a configuration class that extends
AbstractAerospikeDataConfiguration
and defines the relevant Spring Data Repositories via @EnableAerospikeRepositories
annotation.
To set the connection details you can either override getHosts()
and nameSpace()
methods
of the AbstractAerospikeDataConfiguration
class or define spring.aerospike.hosts
and
spring.data.aerospike.namespace
in application.properties
file.
Note
|
You can further customize your configuration by changing other settings .
|
Here is a simple example of a configuration class that sets up a connection to a local Aerospike DB instance:
@Configuration
@EnableAerospikeRepositories(basePackageClasses = PersonRepository.class)
class ApplicationConfig extends AbstractAerospikeDataConfiguration {
@Override
protected Collection<Host> getHosts() {
return Collections.singleton(new Host("localhost", 3000));
}
@Override
protected String nameSpace() {
return "test";
}
}
Below is an example of a service that uses PersonRepository
operations.
-
deleteAll
andsave
are provided automatically by extendingAerospikeRepository
interface -
findByFirstnameLike
andfindByLastname
methods were defined inPersonRepository
but there was no need to write the actual implementation, it is determined automatically from the method names
@Service
public class PersonService {
private final PersonRepository personRepository;
@Autowired
public PersonService(PersonRepository personRepository) {
this.personRepository = personRepository;
}
public void example() {
// Delete all existing persons
personRepository.deleteAll();
Person person = new Person();
person.setFirstname("John");
person.setLastname("Smith");
// Save the new created person
personRepository.save(person);
// Get all persons whose first name starts with "Jo"
List<Person> firstNameResults = personRepository.findByFirstnameLike("Jo*");
// Get all persons whose last name is equal to "Smith"
List<Person> lastNameResults = personRepository.findByLastname("Smith");
}
}
AerospikeOperations
is the base interface for Aerospike database operations. It is implemented by
AerospikeTemplate
class.
As a lower-level alternative to AerospikeRepository
, AerospikeOperations
supports wider variety of operations and
greater flexibility, but requires a bit more code writing and less out-of-the-box functionality.
Features supported by AerospikeOperations
:
-
Basic support for mapping POJOs to and from Aerospike bins
-
Convenience CRUD (Create, Read, Update and Delete) methods for interacting with Aerospike
-
Rich query API
-
Access to the native Aerospike Java Client (reactive and non-reactive)
-
Translating exceptions into Spring’s technology-agnostic DAO exception hierarchy
For non-blocking reactive API use ReactiveAerospikeOperations
.
-
Ask a specific question using Spring Data Aerospike tag on StackOverflow
Here are some ways you can get involved:
-
Help out on the StackOverflow spring-data-aerospike tag by responding to questions and joining the debate
-
Create a GitHub issue for a feature request or bug fixing, comment and vote on the ones that you are interested in
-
GitHub is for social coding: we encourage contributions through pull requests from forks of this repository. When contributing code, please reference a specific GitHub issue you are addressing
-
Watch for upcoming articles by subscribing to Aerospike Stand-Up