You can try this approach with the help of Groovy language in Apache Nifi:
Download Jedis
JAR file.
NOTE: This a required dependency that you have to add to your Groovy Script class path
Upload the downloaded JAR file on a directory in your running Nifi Instance.
NOTE: If your are using Nifi on Docker, upload the JAR file on a mounted
volume that you can access to it from your Nifi Instance.
Add ExecuteScript
processor to your Nifi Flow. Select the Groovy in Script Engine
Property Then fill the Module Directory
Property with the address of the JAR file directory on you Nifi Instance.
In Order to connect to RedisStack , Select the Script Body
Property in ExecuteScript
processor and write down your desired script. For Example:
// 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()
This is the way you can connect to RedisStack and use RedisJSON commands in Groovy using the Jedis library and all of this is applicable in Apache Nifi.
I hope this will help you out.