An open API service indexing awesome lists of open source software.

https://github.com/valkey-io/spring-data-valkey


https://github.com/valkey-io/spring-data-valkey

Last synced: 16 days ago
JSON representation

Awesome Lists containing this project

README

          

# Spring Data Valkey

Spring Data Valkey is a dedicated integration module for the [Valkey](https://valkey.io/)
data store, a high-performance, Redis-compatible in-memory database.
The project is a fork of Spring Data Redis 3.5.1, created to offer first-class support for Valkey and to ensure seamless, optimized access to the Valkey ecosystem.

This module is purpose-built to provide the best possible experience when using Valkey from Spring applications, leveraging the specialized [Valkey-GLIDE](https://github.com/valkey-io/valkey-glide)
client library for high-performance, cross-language connectivity. By aligning API compatibility with Spring Data Redis, Spring Data Valkey enables developers to migrate with minimal friction while benefiting from improved performance, modern driver capabilities, and long-term support for the Valkey platform.

## Features

* Connection package as low-level abstraction across multiple drivers ([Valkey GLIDE](https://github.com/valkey-io/valkey-glide), [Lettuce](https://github.com/lettuce-io/lettuce-core), and [Jedis](https://github.com/redis/jedis)).
* Exception translation to Spring's portable Data Access exception hierarchy for driver exceptions.
* `ValkeyTemplate` that provides a high level abstraction for performing various Valkey operations, exception translation and serialization support.
* Pubsub support (such as a MessageListenerContainer for message-driven POJOs). Available with Jedis and Lettuce, with Valkey GLIDE support WIP for version 1.0.0.
* Valkey Sentinel support is currently available in Jedis and Lettuce, while support in Valkey GLIDE is planned for a future release.
* Reactive API using Lettuce.
* JDK, String, JSON and Spring Object/XML mapping serializers.
* JDK Collection implementations on top of Valkey.
* Atomic counter support classes.
* Sorting and Pipelining functionality.
* Dedicated support for SORT, SORT/GET pattern and returned bulk values.
* Valkey implementation for Spring cache abstraction.
* Automatic implementation of `Repository` interfaces including support for custom finder methods using `@EnableValkeyRepositories`.
* CDI support for repositories.

## Getting Started

Here is a quick teaser of an application using Spring Data Valkey in Java:

```java
public class Example {

// inject the actual template
@Autowired
private StringValkeyTemplate valkeyTemplate;

// inject the template as ListOperations
// can also inject as Value, Set, ZSet, and HashOperations
@Resource(name="valkeyTemplate")
private ListOperations listOps;

public void addLink(String userId, URL url) {
listOps.leftPush(userId, url.toExternalForm());
// or use template directly
valkeyTemplate.boundListOps(userId).leftPush(url.toExternalForm());
}
}

@Configuration
class ApplicationConfig {

@Bean
public ValkeyConnectionFactory valkeyConnectionFactory() {
return new ValkeyGlideConnectionFactory();
}

@Bean
public StringValkeyTemplate valkeyTemplate(ValkeyConnectionFactory factory) {
return new StringValkeyTemplate(factory);
}
}
```

### Maven configuration

Add the Maven dependency:

```xml

io.valkey.springframework.data
spring-data-valkey
${version}

```

Note that a dependency for the underlying driver is also needed. It is recommended to use Valkey GLIDE:

```xml

io.valkey
valkey-glide
${os.detected.classifier}
${version}

```

Valkey GLIDE requires platform-specific native libraries. Add the os-maven-plugin to resolve `${os.detected.classifier}`:

```xml



kr.motd.maven
os-maven-plugin
1.7.1

```

### Examples

For more comprehensive examples covering templates, repositories, caching, and other Spring Data functionality, see the [examples](examples/) directory.

## Building from Source

Spring Data Valkey can be easily built with the [maven wrapper](https://github.com/takari/maven-wrapper). You also need JDK 17 or above and `make`. The local build environment is managed within a `Makefile` to download, build and spin up Valkey in various configurations (Standalone, Sentinel, Cluster, etc.)

```bash
$ make test
```

The preceding command runs a full build. You can use `make start`, `make stop`, and `make clean` commands to control the environment yourself. This is useful if you want to avoid constant server restarts. Once all Valkey instances have been started, you can either run tests in your IDE or the full Maven build:

```bash
$ ./mvnw clean install
```

If you want to build with the regular `mvn` command, you will need [Maven v3.8.0 or above](https://maven.apache.org/run-maven/index.html).

## Migration from Spring Data Redis

If you're migrating from Spring Data Redis, see the [Migration Guide](MIGRATION.md) for detailed instructions on updating package names, class names, and configuration.

## Documentation

For general usage patterns and API documentation, refer to:
* [Spring Data Redis Reference Documentation](https://docs.spring.io/spring-data/redis/reference/) - Most concepts apply to Valkey
* [Valkey Documentation](https://valkey.io/docs/) - For Valkey-specific features and commands

## License

Spring Data Valkey is Open Source software released under the [Apache 2.0 license](https://www.apache.org/licenses/LICENSE-2.0.html).