xmlns:redis="http://www.mulesoft.org/schema/mule/redis"
Redis Examples - Mule 4
XML Save a Key Value
-
Add the Redis namespace to the Mule element:
-
Add the location of the Redis schema referred to by the Redis namespace:
http://www.mulesoft.org/schema/mule/redis http://www.mulesoft.org/schema/mule/sfdc-composite/current/mule-redis.xsd -
Add the HTTP namespace to the Mule element:
xmlns:http="http://www.mulesoft.org/schema/mule/http"
-
Add the location of the HTTP schema referred to by the HTTP namespace:
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd -
Add a
redis:configelement to your project, then configure its attributes:<redis:config name="Redis__Configuration" host="${config.host}" connectionTimeout="${config.connectionTimeout}" port="${config.port}" doc:name="Redis: Configuration"/> -
Add an
http:listener-configelement to your project, and configure its attributes:<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/> -
Add an empty flow element to your project:
<flow name="set-flow"> </flow> -
Within the flow element, add an
http:listenerelement:<http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="Set value HTTP endpoint"/> -
Within the flow element, add
redis:setafter thehttp:listener:<redis:set config-ref="Redis__Configuration" key="#[payload.key]" value="#[payload.value]" doc:name="Set value for key into Redis"/> -
Within the flow element, add a
set-payloadelement afterredis:set:<set-payload value="Value successfully set" doc:name="Set value response"/> -
When you’re done, the XML file should look like:
<?xml version="1.0" encoding="UTF-8"?> <mule xmlns:redis="http://www.mulesoft.org/schema/mule/redis" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd http://www.mulesoft.org/schema/mule/redis http://www.mulesoft.org/schema/mule/redis/current/mule-redis.xsd"> <redis:config name="Redis__Configuration" host="${config.host}" connectionTimeout="${config.connectionTimeout}" port="${config.port}" doc:name="Redis: Configuration"/> <http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/> <flow name="set-flow"> <http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="Set value HTTP endpoint"/> <redis:set config-ref="Redis__Configuration" key="#[payload.key]" value="#[payload.value]" doc:name="Set value for key into Redis"/> <set-payload value="Successfully set value: #[payload.value] to key: #[payload.key]" doc:name="Set value response"/> </flow> </mule>
XML Custom Object Store
This use case describes how to use the Redis Connector as a custom object store in a Mule app.
-
Add the Redis namespace to the Mule element:
xmlns:redis="http://www.mulesoft.org/schema/mule/redis" -
Add the location of the Redis schema referred to by the Redis namespace:
http://www.mulesoft.org/schema/mule/redis http://www.mulesoft.org/schema/mule/sfdc-composite/current/mule-redis.xsd -
Add the HTTP namespace to the Mule element:
xmlns:http="http://www.mulesoft.org/schema/mule/http" -
Add the location of the HTTP schema referred to by the HTTP namespace:
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd -
Add the object store namespace to the Mule element:
xmlns:os="http://www.mulesoft.org/schema/mule/os" -
Add the location of the object store schema referred to by the object store’s namespace:
http://www.mulesoft.org/schema/mule/os http://www.mulesoft.org/schema/mule/os/current/mule-os.xsd -
Add an
os:configelement to your project, then configure it to contain a Redis connection type (clustered or non-clustered). This is only possible in Studio and must be configured through XML (there is no support using the Studio graphic configuration).<os:config name="ObjectStore_Config"> <redis:nonclustered-connection host="${redis.host}"/> </os:config> -
Add an
os:object-storeelement to your project and configure it to reference the previously created config.<os:object-store name="Object_store" config-ref="ObjectStore_Config" maxEntries="1" entryTtl="60" expirationInterval="10" expirationIntervalUnit="SECONDS"/> -
Add n
http:listener-configelement to your project, and configure its attributes:<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/> -
Add an empty flow element to your project:
<flow name="set-flow"> </flow> -
Within the flow element, add an
http:listenerelement:<http:listener config-ref="HTTP_Listener_Configuration" path="/" /> -
Within the flow element, add an
os:storeafter thehttp:listener, and configure it to use the previously created object store:<os:store key="#[attributes.queryParams.key]" objectStore="Object_store" failIfPresent="true" failOnNullValue="false"> <os:value ><![CDATA[#[attributes.queryParams.value]]]></os:value> </os:store> -
When you’re done, the XML file should look like:
<?xml version="1.0" encoding="UTF-8"?> <mule xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:os="http://www.mulesoft.org/schema/mule/os" xmlns:redis="http://www.mulesoft.org/schema/mule/redis" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd http://www.mulesoft.org/schema/mule/redis http://www.mulesoft.org/schema/mule/redis/current/mule-redis.xsd http://www.mulesoft.org/schema/mule/os http://www.mulesoft.org/schema/mule/os/current/mule-os.xsd http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd"> <http:listener-config name="HTTP_Listener_config"> <http:listener-connection host="0.0.0.0" port="8081" /> </http:listener-config> <os:object-store name="Object_store" config-ref="ObjectStore_Config" maxEntries="1" entryTtl="60" expirationInterval="10" expirationIntervalUnit="SECONDS"/> <os:config name="ObjectStore_Config"> <redis:nonclustered-connection host="${redis.host}"/> </os:config> <flow name="StoreFlow" > <http:listener doc:name="Listener" config-ref="HTTP_Listener_config" path="/store"/> <os:store doc:name="Store" key="#[attributes.queryParams.key]" objectStore="Object_store" failIfPresent="true" failOnNullValue="false"> <os:value ><![CDATA[#[attributes.queryParams.value]]]></os:value> </os:store> </flow> </mule>



