Skip to content

Instantly share code, notes, and snippets.

@mp911de
Created January 18, 2018 09:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mp911de/581151f6394607998371d9f0910a7ac8 to your computer and use it in GitHub Desktop.
Save mp911de/581151f6394607998371d9f0910a7ac8 to your computer and use it in GitHub Desktop.
DATAREDIS-748
package com.example;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;
import java.io.Serializable;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.data.annotation.Id;
import org.springframework.data.redis.core.RedisHash;
import org.springframework.data.redis.core.RedisKeyValueAdapter.EnableKeyspaceEvents;
import org.springframework.data.redis.core.index.Indexed;
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories;
import org.springframework.data.repository.CrudRepository;
@SpringBootApplication
@RequiredArgsConstructor
@EnableRedisRepositories(enableKeyspaceEvents = EnableKeyspaceEvents.ON_STARTUP, considerNestedRepositories = true)
public class SpringDataRedisPlaygroundApplication implements CommandLineRunner {
final ApplicationContext context;
final PersonRepository personRepository;
public static void main(String[] args) {
SpringApplication.run(SpringDataRedisPlaygroundApplication.class, args);
}
@Override
public void run(String... strings) throws Exception {
Person v = new Person("foo", "bar", "f", "p");
personRepository.save(v);
}
@AllArgsConstructor
@NoArgsConstructor
@Data
@RedisHash(timeToLive = 10)
static class Person implements Serializable {
@Id String id;
String name, firstname;
@Indexed String prefix;
}
interface PersonRepository extends CrudRepository<Person, String> {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment