public class Test{
public static void main(String[] args) {
//单机模式
RedisStandaloneConfiguration rsc = new RedisStandaloneConfiguration();
rsc.setPort(6379);
rsc.setPassword("");
rsc.setHostName("192.168.1.128");
//集群模式
// RedisClusterConfiguration rcc = new RedisClusterConfiguration();
// rcc.setPassword("");
// List<RedisNode> nodes = Collections.singletonList(new RedisNode("192.168.1.128", 6379));
// rcc.setClusterNodes(nodes);
RedisTemplate<String, String> template = new RedisTemplate<String,String>();
//单机模式
LettuceConnectionFactory fac = new LettuceConnectionFactory(rsc);
//集群模式
//LettuceConnectionFactory fac = new LettuceConnectionFactory(rcc);
fac.afterPropertiesSet();
template.setConnectionFactory(fac);
template.setDefaultSerializer(new StringRedisSerializer());
template.afterPropertiesSet();
Map<String,String> map = new HashedMap();
map.put("tagId","tagID2");
map.put("deviceId","deviceId2");
ObjectRecord<String, Object> record = StreamRecords.newRecord()
.in("mq")
.ofObject(map);
RecordId recordId = template.opsForStream().add(record);
System.out.println(recordId);
}
}