当前位置:网站首页>Ding Dong, here comes the redis om object mapping framework
Ding Dong, here comes the redis om object mapping framework
2022-07-02 07:17:00 【Software development heart】
Ding Dong ,Redis OM Here comes the object mapping framework !
One 、Redis OM coming
11 month 23 Japan ,redis Announced four new Redis Advanced client preview , These libraries are called Redis OM(Redis Object Mapping)----- Mapping objects .
Its framework with powerful Spring Data Redis (SDR) Framework based , Provide a high-level Abstract toolbox , We are familiar with object-oriented programming to express .
Its purpose is to focus on object mapping and smooth query , That is, use it as easily as possible Redis . It can transparently save domain objects in Redis in , And can use fluent 、 Language centered API Query them .
Redis OM Some of the advanced features of depend on the two available Redis The core function of the module :RediSearch and RedisJSON.
as follows , Launched a pair of .NET、Node.js、Python and Java (Spring) Language support
- Redis OM for .NET
- Redis OM for Node.js
- Redis OM for Python
- Redis OM for Spring

Two 、 understand
Here are Redis OM for Spring For example, by viewing the source code demo:rds-documents Module simulation to further understand Redis OM
Download the official package :redis-om-spring-main
development environment :JDK11
springboot edition :2.6.0-M1
notes :Redis OM The abstraction of is built on spring-data-redis (SDR) above
Code parsing
1、 Mapping objects
Through annotation @Document take Spring Data Object to Redis JSON@Indexable Declarative search @Searchable Full text search index @RequiredArgsConstructor(staticName = "of") Indicates the pass method of() To build objects @NonNull Can't be empty
Add :@Bloom Determine whether a value is in the set very quickly
/** * place */
@Data
@RequiredArgsConstructor(staticName = "of")
@AllArgsConstructor(access = AccessLevel.PROTECTED)
@Document
public class Address {
@Id
private String id;
@NonNull
@Searchable
private String addressName;
@Indexed
private Set<String> addressTags = new HashSet<String>();
@NonNull
private String picUrl;
@NonNull
@Indexed
private Point location;
@NonNull
@Indexed
private Integer yearRegister;
private boolean publiclyListed;
}
2、 Object persistence
By expanding the interface RedisDocumentRepository To carry out CRUD operation , similar JPA Custom query of .
Through inheritance spring data The interface in :PagingAndSortingRepository
/** * By inheritance RedisDocumentRepository To carry out CRUD Operation and similar JPA Custom query of */
public interface AddressRepository extends RedisDocumentRepository<Address, String> {
// find one by property adopt addressName Inquire about
Optional<Address> findOneByAddressName(String name);
// find by tag field, using JRediSearch "native" annotation
@Query("@tags:{$tags}")
Iterable<Address> findByTags(@Param("tags") Set<String> tags);
}
Query definition
- By deriving the query directly from the method name .
- By using @Query or @Aggregation Annotations use manually defined queries .
3、 And spring Integration and use of
Through annotation @EnableRedisDocumentRepositories Scan the specified package with @Document Annotated object , Inject RedisDocumentRepository, You can use CRUD Operate custom query @Document The annotations Bean
/** * Starting entrance */
@SpringBootApplication
@Configuration
@com.redis.om.spring.annotations.EnableRedisDocumentRepositories(basePackages = "com.redis.documents.*")
public class RdsDocumentsApplication {
public static void main(String[] args) {
SpringApplication.run(RdsDocumentsApplication.class, args);
}
...
}
4、 Save the data
@Autowired
private AddressRepository addressRepository;
@Bean
CommandLineRunner loadTestData() {
return args -> {
// Delete data
addressRepository.deleteAll();
//save Save the data
addressRepository.save(Address.of(" Guangzhou vipshop address ", "https://www.vip.com/?wq=1", new Point(113.124500, 23.640160), 2000));
addressRepository.save(Address.of(" Baidu address in Guangzhou ", "https://www.baidu.com/", new Point(113.235614, 23.342545), 2020));
};
}
5、 Interface call
@RestController
@RequestMapping("/api/address")
public class AddressController {
@Autowired
private AddressRepository addressRepository;
@GetMapping("name/{name}")
Optional<Address> byAddressName(@PathVariable("name") String name) {
return addressRepository.findOneByAddressName(name);// Method name derived query
}
@GetMapping("tags")
Iterable<Address> byTags(@RequestParam("tags") Set<String> tags) {
return addressRepository.findByTags(tags);// Method name derived query
}
@GetMapping("all")
Page<Address> all(Pageable pageable) {
return addressRepository.findAll(pageable);//spring data Bring their own
}
@GetMapping("{id}")
Optional<Address> byId(@PathVariable("id") String id) {
return addressRepository.findById(id);//spring data Bring their own
}
}
6、Maven rely on
<dependency>
<groupId>com.redis.om.spring</groupId>
<artifactId>redis-om-spring</artifactId>
<version>${
version}</version>
</dependency>
Reference documents
The official introduction :https://redis.com/blog/introducing-redis-om-client-libraries/
git Source code :https://github.com/redis/redis-om-spring
summary
Redis OM After the preview version is released , It has attracted extensive attention of programmers , They call it Redis Bounded Hibernate
Some people say ,Springboot Redis Already very concise , This object mapping is also equivalent to a Map, Develop a new framework , It's superfluous .
Others say , Can let redis It is easier to use , More in line with the norms of the language , The so-called beauty of language , An important part of it is its standardization , Is a good progress .
Official explanation ,
at present redis The client does already support Redis All kinds of tools , Including the cache 、 Distributed lock 、 Message queuing, etc
The new framework was created because not everyone has time to repackage these tools . Not everyone has time to Redis Hash maps to Java class ( vice versa ). By building Redis OM, So even if you don't have time to use Redis Provide the core data structure and write your own abstraction , Also available Redis Performance of .
My idea is , Generation of each framework , Are a summary of ideas , It can provide more technical options for our development .
And technological progress , It is precisely because these lovely programmers are constantly expanding and improving .
Because I shared with the company before redis Foundation and advanced , I intend to finish the last section Redis Related distributed locks , But see Redis OM The preview , It makes me full of expectation , So share it .
Let's look forward to the release of the official version , Expect more complete functions !
author :yana
边栏推荐
- pm2简单使用和守护进程
- MySQL组合索引加不加ID
- php中通过集合collect的方法来实现把某个值插入到数组中指定的位置
- Ceaspectuss shipping company shipping artificial intelligence products, anytime, anywhere container inspection and reporting to achieve cloud yard, shipping company intelligent digital container contr
- SQLI-LABS通關(less6-less14)
- Oracle EBS DataGuard setup
- Yaml file of ingress controller 0.47.0
- Yolov5 practice: teach object detection by hand
- Oracle rman半自动恢复脚本-restore阶段
- ORACLE EBS中消息队列fnd_msg_pub、fnd_message在PL/SQL中的应用
猜你喜欢

【Ranking】Pre-trained Language Model based Ranking in Baidu Search

Sqli labs customs clearance summary-page2

Ingress Controller 0.47.0的Yaml文件

Pratique et réflexion sur l'entrepôt de données hors ligne et le développement Bi

Alpha Beta Pruning in Adversarial Search

Oracle EBS ADI development steps

在php的开发环境中如何调取WebService?

SQLI-LABS通關(less6-less14)

ORACLE EBS中消息队列fnd_msg_pub、fnd_message在PL/SQL中的应用

oracle apex ajax process + dy 校验
随机推荐
php中的二维数组去重
Network security -- intrusion detection of emergency response
ORACLE APEX 21.2安裝及一鍵部署
离线数仓和bi开发的实践和思考
The first quickapp demo
实现接口 Interface Iterable&lt;T&gt;
php中在二维数组中根据值返回对应的键值
parser.parse_args 布尔值类型将False解析为True
读《敏捷整洁之道:回归本源》后感
JSP智能小区物业管理系统
oracle-外币记账时总账余额表gl_balance变化(上)
MySQL组合索引加不加ID
Oracle APEX 21.2 installation et déploiement en une seule touche
CSRF攻击
【论文介绍】R-Drop: Regularized Dropout for Neural Networks
ORACLE EBS ADI 开发步骤
SSM二手交易网站
ORACLE 11.2.0.3 不停机处理SYSAUX表空间一直增长问题
Oracle RMAN automatic recovery script (migration of production data to test)
ORACLE 11G利用 ORDS+pljson来实现json_table 效果