为什么在我的项目中找不到 "RedisStreamCommands" 接口?
Why is the "RedisStreamCommands" interface not found in my project?
我正在尝试导入 RedisStreamCommands
。我可以导入它,但我可以导入 RedisCommands。我认为它需要依赖。我不知道那是什么,请帮助我。
RedisCommands<String, String> syncCommands = connection.sync();
RedisStreamCommands<String, String> streamCommands = connection.sync();
syncCommands.set("key_1", "Hello, Redis!");
Map<String, String> body = Collections.singletonMap("key", "value");
String messageId = streamCommands.xadd("my-stream", body);
我试过这样:在 RedisStreamCommands 上显示错误。
import java.util.Collections;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import io.lettuce.core.RedisClient;
import io.lettuce.core.RedisURI;
import io.lettuce.core.api.StatefulRedisConnection;
import io.lettuce.core.api.sync.*;
import io.lettuce.core.api.sync.RedisCommands;
import io.lettuce.core.cluster.RedisClusterClient;
import io.lettuce.core.cluster.api.StatefulRedisClusterConnection;
import io.lettuce.core.cluster.api.sync.RedisAdvancedClusterCommands;
public class LettuceDemo {
public static void main(String[] args) {
RedisClient redisClient = RedisClient.create("redis://15m4madm4bd6ypfqtc353wfq4q292brk@expeditious-ironwood-6027.redisgreen.net:11042/0");
StatefulRedisConnection<String, String> connection = redisClient.connect();
RedisCommands<String, String> syncCommands = connection.sync();
RedisStreamCommands<String, String> streamCommands = connection.sync();
syncCommands.set("key_1", "Hello, Redis!");
Map<String, String> body = Collections.singletonMap("key", "value");
String messageId = streamCommands.xadd("my-stream", body);
connection.close();
redisClient.shutdown();
}
}
接口io.lettuce.core.api.sync.RedisStreamCommands
是在Redis 5.1版本中引入的;很可能您使用的是不包含它的早期版本。
因此,基本上,您应该检查您的类路径和 Redis 的版本,并在必要时将其调整为版本 5.1+。您可以从此处获取它:https://lettuce.io/docs 或查看文档以获取更多详细信息。
希望对您有所帮助。
我正在尝试导入 RedisStreamCommands
。我可以导入它,但我可以导入 RedisCommands。我认为它需要依赖。我不知道那是什么,请帮助我。
RedisCommands<String, String> syncCommands = connection.sync();
RedisStreamCommands<String, String> streamCommands = connection.sync();
syncCommands.set("key_1", "Hello, Redis!");
Map<String, String> body = Collections.singletonMap("key", "value");
String messageId = streamCommands.xadd("my-stream", body);
我试过这样:在 RedisStreamCommands 上显示错误。
import java.util.Collections;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import io.lettuce.core.RedisClient;
import io.lettuce.core.RedisURI;
import io.lettuce.core.api.StatefulRedisConnection;
import io.lettuce.core.api.sync.*;
import io.lettuce.core.api.sync.RedisCommands;
import io.lettuce.core.cluster.RedisClusterClient;
import io.lettuce.core.cluster.api.StatefulRedisClusterConnection;
import io.lettuce.core.cluster.api.sync.RedisAdvancedClusterCommands;
public class LettuceDemo {
public static void main(String[] args) {
RedisClient redisClient = RedisClient.create("redis://15m4madm4bd6ypfqtc353wfq4q292brk@expeditious-ironwood-6027.redisgreen.net:11042/0");
StatefulRedisConnection<String, String> connection = redisClient.connect();
RedisCommands<String, String> syncCommands = connection.sync();
RedisStreamCommands<String, String> streamCommands = connection.sync();
syncCommands.set("key_1", "Hello, Redis!");
Map<String, String> body = Collections.singletonMap("key", "value");
String messageId = streamCommands.xadd("my-stream", body);
connection.close();
redisClient.shutdown();
}
}
接口io.lettuce.core.api.sync.RedisStreamCommands
是在Redis 5.1版本中引入的;很可能您使用的是不包含它的早期版本。
因此,基本上,您应该检查您的类路径和 Redis 的版本,并在必要时将其调整为版本 5.1+。您可以从此处获取它:https://lettuce.io/docs 或查看文档以获取更多详细信息。
希望对您有所帮助。