Redis用于使用Java Jedis客户端进行本地测试,无需REDIS服务器。

huangapple go评论67阅读模式
英文:

Redis for Local Testing using Java Jedis Client without a REDIS Server

问题

我对 Redis 缓存相当新,并试图找出一种在本地测试我的更改(存储库)分发的方法。我的想法是我本地没有运行 Redis 服务器,但我在开发环境中有它,但我打算在本地运行我的 Redis 代码,并在保存数据时将其保存到内存数据库或其他地方,而不是 Redis 数据库,这样我就可以测试我的逻辑更改。
问题是,由于我本地没有 Redis(而且不可能在我的本地机器上有它),所以我的存储库代码无法运行。

例如:

// 功能逻辑
// userRepository.save(data) --> 这不起作用,因为存储库本身未构建为 Redis 配置不起作用

我尝试过搜索,但我只找到如何在集成测试中使用 Redis 的方法。我正在寻找类似于 H2 数据库的东西,可以将数据存储在本地。

英文:

I am pretty new to redis cache and trying to figure out a way to test my changes (Repositories) for redistribution locally. The idea is I do not have a redis server running locally, I do have it in my dev env but what I intend to have is the ability to run my redis code locally and when I save the data it gets saved to some in-memory db or somewhere else instead of redis DB which would let me test my logical changes.
The issue is since I do not have redis locally (also it is not possible for me to have it on my local machine) my repository code doesn't work.

eg :

// Functional Logic
// userRepository.save(data) --> This would not work because repository itself isn't built as redis configurations don't work

I tried googling but I only find how to use redis for integration test . What I'm looking for is something similar to H2 DB that stores data locally.

答案1

得分: 1

以下是要翻译的内容:

有几个选项可供您尝试在本地运行Redis服务器:

  1. 安装Docker并运行从DockerHub获取的Redis预构建映像。
  2. 如果您使用的是MacOS或基于Linux的本地计算机,您可以轻松安装Redis服务器分发版。

此外,您还可以在主应用程序内运行嵌入式Redis服务器,类似于您提到的H2数据库。
请参考链接https://www.baeldung.com/spring-embedded-redis了解如何根据您的本地测试环境配置和自定义嵌入式Redis服务器的详细信息。

英文:

There are a couple of options that you can try to run Redis Server locally:

  1. Install Docker and run the Redis pre-built image obtained from DockerHub
  2. If you have MacOS or Linux based local machine, you can easily install Redis Server distribution on it.

Also, you can have a embedded Redis server running inside your main application similar to H2 DB that you are referring to.
Please follow the link https://www.baeldung.com/spring-embedded-redis for the details about how to configure and customize embedded Redis server as per your local testing environment.

huangapple
  • 本文由 发表于 2023年5月26日 16:51:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/76339181.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定