Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

On This Page:

...

Each cache entry in MC2 bound to separate cache and key in that cache, so to get/put value to cache we should specify cache name and key.

But in Redis, each object is bound to the name that is used as a key. 

Map

Redis supports plenty of many objects such as  object, map, set, list, or even queue. So we Therefore you can use a java map object as a value in Redis.

As a result, the MC2 cache name is bound to the Redis key, and the MC2 key is bound to the Map object key.

To get a value from redis the Redis cache in MC2 rules we you can use  use the GETCACHE element.

For instance example, to get the value for key="mc2key " from a cache with the name " mc2cachetest" we should , use the following GETCACHE element:

<GETCACHE CACHETYPE="'rediscache'" CACHENAME="'mc2cachetest'" KEY="'mc2key'" RESULTVAR="outVar" />

The extracted value will be is in the outVar variable.

To put a value to redis into the Redis cache in MC2 rules we can use  , use the PUTCACHE element.

E.g. to put For example, to put the value of variable inVar  to a cache with the name " mc2cachetest " using key="mc2key" we should , use the following PUTCACHE element:

<PUTCACHE CACHETYPE="'rediscache'" CACHENAME="'mc2cachetest'" KEY="'mc2key'" VALUEEXPR=":inVar:"/>

Also It is possible to put/get a few variables at once:

<PUTCACHE CACHETYPE="'rediscache'" CACHENAME="'mc2cachetest'" KEY="'mc2varskey'" VARIABLESEXPR="'inVar1,inVar2,inVar3'" />

<GETCACHE CACHETYPE="'rediscache'" CACHENAME="'mc2cachetest'" KEY="'mc2varskey'" />

The variables will be are created automatically during getting from the cache.

String

For a simple object like String we have such as a String there is no key in Redis,

So to To map an MC2 cache name and key into the Redis key we , use name and key concatenation(using , with colon as a separator) , as a RedisKey.

For example we would like , to put a String value to into a cache with the name " stringcache" using , use the key "stringkey". it will be stringkey, which is bound to the Redis key " stringcache:stringkey".

To deal with a string cache value we , you can also can use PUTCACHE and GETCACHE elements.

E.g. for  For example, for  the string value described earlier described above, the elements will beare:

<PUTCACHE CACHETYPE="'rediscache'" CACHENAME="'stringcache'" KEY="'stringkey'" OPTIONS="'type=string'" VALUEEXPR=":inVar:"/>

<GETCACHE CACHETYPE="'rediscache'" CACHENAME="'stringcache'" KEY="'stringkey'" OPTIONS="'type=string'" RESULTVAR="outVar"/>

Moreover, the MC2 string object supports eviction. Redis allows you to define time to live for each Redis Key. 

To define time to live we are able to , use the timetolive option in the PUTCACHE element. The time is defined in seconds.

E.g. For example, to define time to live in the previous example to 120 second we should as 120 seconds, use the following element:

<PUTCACHE CACHETYPE="'rediscache'" CACHENAME="'stringcache'" KEY="'stringkey'" OPTIONS="'type=string,timetolive=120'" VALUEEXPR=":inVar:"/>