https://github.com/aleksandarskrbic/rocks4j
KV Store for Java backed by RocksDB
https://github.com/aleksandarskrbic/rocks4j
java kv-database kv-storage kv-store kvstore rocksdb rocksdb-4j rocksdb-java
Last synced: 2 months ago
JSON representation
KV Store for Java backed by RocksDB
- Host: GitHub
- URL: https://github.com/aleksandarskrbic/rocks4j
- Owner: aleksandarskrbic
- License: gpl-3.0
- Created: 2020-03-04T16:42:44.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-11-16T08:28:18.000Z (almost 3 years ago)
- Last Synced: 2025-04-01T12:50:48.133Z (7 months ago)
- Topics: java, kv-database, kv-storage, kv-store, kvstore, rocksdb, rocksdb-4j, rocksdb-java
- Language: Java
- Homepage:
- Size: 4.21 MB
- Stars: 16
- Watchers: 2
- Forks: 6
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rocks4j
KV Store for Java backed by RocksDB.
## Getting Started
### Maven
```javacom.github.aleksandarskrbic
rocks4j
1.0.0```
### Gradle
```java
compile "com.github.aleksandarskrbic:rocks4j:1.0.0"
```## Introduction
The goal of this project is to provide KV store backed by RocksDB with simple Java API.
Allow developers to quickly integrate RocksDB into the existing Java/Scala project.
It can be used as a local caching mechanism in microservices or just to replace huge in-memory data structures.## API
There are five available operations against KV repository:
* `save(K key, V value)`
* `findByKey(K key)`
* `findAll()`
* `deleteByKey(K key)`
* `deleteAll()`## Examples
Suppose you have a Java class:
```java
public class Item {
private Long id;
private String desc;
// constructors, getters and setters
}
```To create KV repository for Item class, firstly you need to create a configuration class that accepts a path to file (where RocksDB files will be) and the name of the repository:
```java
final RocksDBConfiguration configuration = new RocksDBConfiguration("/path/to/rocksdb", "item");
```
After configuration class is created, you are able to instantiate the Item Repository:```java
public class ItemRepository extends RocksDBKeyValueRepository {public ItemRepository(final RocksDBConfiguration configuration) {
super(configuration);
}
}
``````java
final ItemRepository itemRepository = new ItemRepository(configuration);
``````java
final Item item = new Item(1L, "Desc")
``````java
itemRepository.save(item.getId(), item);
final Optional itemOptional = itemRepository.findByKey(item.getId());
final Collection all = itemRepository.findAll();
itemRepository.deleteByKey(item.getId());
itemRepository.deleteAll();
```## Note
In order to maintain flexibility, when exception related to `RocksDB` or `Serialization/Deserialization` in `RocksDBKeyValueRepository`,
exceptions are just propagated, so it's a client's responsibility to deal with it.
Best practice would be to override methods from `RocksDBKeyValueRepository` and
handle those exceptions and handle those exceptions into your repository class.
Another solution would be to handle
it every time you invoke methods provided by `RocksDBKeyValueRepository` which is not recommended.### Example
```java
public static class ItemRepository extends RocksDBKeyValueRepository {public ItemRepository(final RocksDBConfiguration configuration) {
super(configuration);
}@Override
public void save(final Long key, final Item value) {
try {
super.save(key, value);
} catch (final SerializationException e) {
// log or handle
} catch (final SaveFailedException e) {
// log or handle
}
}// other methods
}
```
## CreditsSpecial thanks to [@jovicaandric](https://github.com/jovicaandric) and [@vajda](https://github.com/vajda).