1.将ExecuteScript处理器添加到Nifi Flow。选择Groovy in Script Engine属性,然后在Module Directory属性中填充Nifi示例上JAR文件目录的地址。 1.要连接到RedisStack,请选择ExecuteScript处理器中的Script Body属性,并写下您需要的脚本。例如:
// Import the necessary Jedis classes
import redis.clients.jedis.Jedis
import redis.clients.jedis.JedisPool
import redis.clients.jedis.JedisPoolConfig
// Set up a connection to RedisStack using Jedis
// Replace [REDIS_IP_ADDRESS] and [REDIS_PORT] with your actual running Redis IP address and port number.
def redisHost = "[REDIS_IP_ADDRESS]"
def redisPort = [REDIS_PORT]
def jedis = new Jedis(redisHost, redisPort)
// Connect to the RedisJSON module using the Jedis MODULE LOAD command
//This loads the RedisJSON module into RedisStack, allowing you to use RedisJSON commands
jedis.sendCommand("MODULE", "LOAD", "redisjson")
//Use RedisJSON commands with Jedis to interact with RedisJSON
// Set a JSON object
jedis.sendCommand("JSON.SET", "myjson", ".", '{"name":"John","age":30}')
// Get a JSON object
def result = jedis.sendCommand("JSON.GET", "myjson")
println(result)
// Query a JSON path
def query = ".name"
def value = jedis.sendCommand("JSON.GET", "myjson", query)
println(value)
//Do not forget to close your Jedis connection when you done
jedis.close()
1条答案
按热度按时间to94eoyn1#
你可以在Apache Nifi中的Groovy语言的帮助下尝试这种方法:
1.下载
Jedis
JAR文件。**注意:**这是一个必需的依赖项,您必须将其添加到Groovy Script类路径
1.将下载的JAR文件上传到正在运行的Nifi示例的目录中。
**注意:**如果您在Docker上使用Nifi,请将JAR文件上传到您可以从Nifi示例访问的已挂载卷上。
1.将
ExecuteScript
处理器添加到Nifi Flow。选择Groovy inScript Engine
属性,然后在Module Directory
属性中填充Nifi示例上JAR文件目录的地址。1.要连接到RedisStack,请选择
ExecuteScript
处理器中的Script Body
属性,并写下您需要的脚本。例如:字符串
这就是你可以连接到RedisStack并使用Jedis库在Groovy中使用RedisJSON命令的方式,所有这些都适用于Apache Nifi。
希望这能帮到你。