Spring Data Redis CRUD Operations example with Spring Boot
springboot
138
springdata
10
CRUD
39
Redis
16
Male avatar

loveprogramming viết ngày 19/04/2021

https://grokonez.com/spring-framework/spring-data/spring-data-redis-example-spring-boot-redis-example

Spring Data Redis CRUD Operations example with Spring Boot

Redis is an open-source, in-memory key-value data store, used as a database, cache, and message broker. In this tutorial, we're gonna look at how to do Redis CRUD Operations with Spring Boot using Spring Data Redis.

Related Post: Spring Data Redis Messaging – PubSub example | Spring Boot

I. Technology

  • Java 1.8
  • Maven 3.3.9
  • Spring Tool Suite – Version 3.9.0.RELEASE
  • Spring Boot: 1.5.9.RELEASE

    II. Spring Data Redis

    1. Maven Dependency

    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-redis</artifactId>
    </dependency>

    2. Redis Configuration

    We use Jedis as a Redis client to define and establish the connection between our Spring Boot application and the Redis server instance.
    @Bean
    JedisConnectionFactory jedisConnectionFactory() {
    return new JedisConnectionFactory();
    }

@Bean
public RedisTemplate<String, Object> redisTemplate() {
final RedisTemplate<String, Object> template = new RedisTemplate<String, Object>();
template.setConnectionFactory(jedisConnectionFactory());
template.setValueSerializer(new GenericToStringSerializer<Object>(Object.class));
return template;
}
If we wanna configure connection details, just modify the jedisConnectionFactory configuration:


@Bean
JedisConnectionFactory jedisConnectionFactory() {
    JedisConnectionFactory jedisConFactory = new JedisConnectionFactory();
    jedisConFactory.setHostName("localhost");
    jedisConFactory.setPort(6379);
    return jedisConFactory;
}

3. Redis CRUD Operations with RedisTemplate

RedisTemplate provides DefaultHashOperations instance that can do hash-related operations for data manipulation.
To get DefaultHashOperations instance, we call RedisTemplate.opsForHash():

More at:

https://grokonez.com/spring-framework/spring-data/spring-data-redis-example-spring-boot-redis-example

Spring Data Redis CRUD Operations example with Spring Boot

Bình luận


White
{{ comment.user.name }}
Bỏ hay Hay
{{comment.like_count}}
Male avatar
{{ comment_error }}
Hủy
   

Hiển thị thử

Chỉnh sửa

Male avatar

loveprogramming

451 bài viết.
79 người follow
Kipalog
{{userFollowed ? 'Following' : 'Follow'}}
Cùng một tác giả
Male avatar
1 0
Tutorial Link: (Link) (Ảnh) Django is a Pythonbased free and opensource web framework that follows the modeltemplateview architectural pattern. A...
loveprogramming viết 6 tháng trước
1 0
Male avatar
1 0
https://loizenai.com/angular11nodejspostgresqlcrudexample/ Angular 11 Node.js PostgreSQL Crud Example (Ảnh) Tutorial: “Angular 11 Node.js Postg...
loveprogramming viết 5 tháng trước
1 0
Male avatar
1 0
Angular Spring Boot jwt Authentication Example Github https://loizenai.com/angularspringbootjwt/ (Ảnh) Tutorial: ” Angular Spring Boot jwt Authe...
loveprogramming viết 5 tháng trước
1 0
Bài viết liên quan
Male avatar
0 0
https://grokonez.com/frontend/angular/angular6/kotlinspringbootangular6crudhttpclientmysqlexamplespringdatajparestapisexample Kotlin Spring Boot +...
loveprogramming viết 1 tháng trước
0 0
{{like_count}}

kipalog

{{ comment_count }}

bình luận

{{liked ? "Đã kipalog" : "Kipalog"}}


Male avatar
{{userFollowed ? 'Following' : 'Follow'}}
451 bài viết.
79 người follow

 Đầu mục bài viết

Vẫn còn nữa! x

Kipalog vẫn còn rất nhiều bài viết hay và chủ đề thú vị chờ bạn khám phá!