• 主页
  • 可以检索在redis-cli中手动设置的值,但无法在Spring Boot中通过Redis Reactive设置新的密钥

可以检索在redis-cli中手动设置的值,但无法在Spring Boot中通过Redis Reactive设置新的密钥

我正在使用Spring Webflux + Reactive Redis,我的目标是使用Redis作为文件缓存。

我一开始试着用~100MB的ByteBuffer设置一个密钥,但没有起作用。我与调试器进行了两次检查,以确保文件确实被读取到内存中,而且确实是这样。我想“也许Redis不喜欢”大“字符串?”所以我试着用下面的代码,仍然没有骰子。我认为这可能是ACL相关的问题,但我检查了一下,默认用户可以访问所有内容。“也许Spring不能访问Redis?”没有,我在redis-cli中检查了监视器输出,GET命令接收正常,但没有SET命令的迹象。有什么建议吗?

这是我的控制器:

@RequestMapping(value = "/prime", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public Mono<String> prime() {
    reactiveStringCommands.set(ByteBuffer.wrap("testkey2".getBytes()), ByteBuffer.wrap("test".getBytes()));

    return reactiveStringCommands.get(ByteBuffer.wrap("testkey".getBytes())).map(bb -> new String(bb.array()));
}

Application.properties中的相关设置:

spring.redis.host=localhost
spring.redis.password=<password>
spring.redis.port=6379

redis-cli输出(testkey是在命令行界面中手动设置的,没有testkey2迹象):

127.0.0.1:6379> keys *
1) "testkey"
127.0.0.1:6379> ACL list
1) "user default on #<password> ~* +@all"
127.0.0.1:6379> monitor
OK
1610406175.250768 [0 172.17.0.1:39104] "GET" "testkey"

编辑:忘记提到没有堆栈跟踪,也没有输出到控制台的任何类型的错误。

转载请注明出处:http://www.jxbyjx.net/article/20230429/1713998.html