Created
January 18, 2018 09:23
-
-
Save mp911de/581151f6394607998371d9f0910a7ac8 to your computer and use it in GitHub Desktop.
DATAREDIS-748
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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