Redis-Template 具有支持 HMGET 命令的方法。 我可以使用 Redis-Template 中的哪种方法来运行此命令“HMGET KEY field1 field2”?
另外我们如何通过Redis-Template运行相同的命令?,所以在不使用预定义方法的情况下,我直接想通过方法运行上述/任何命令,我们对此是否支持。
在 Redis-Template 中,有一个名为
opsForHash()
的方法用于 HASH
数据结构,此类方法是使用 Redis 命令的推荐方法。
但是,如果您确实想要使用“原始”命令,这里有一个示例:
public Object executeCommand(String command, byte[]... parts) {
return redisTemplate.execute(connection ->
connection.execute(command, parts),
true
);
}
调用该方法:
redisDemo.executeCommand(
"HMGET",
"test".getBytes(),
"field1".getBytes(),
"field1".getBytes()
);