Versions Compared

Key

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

...

...

...

Features

MC2 works with two types of Redis distributed objects: string and map collection only.

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

In Redis however,  each object is bound to the name that is used as a key. 

On this page

Table of Contents

Map

Redis supports many objects such as  object, map, set, list, or queue. 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 the Redis cache in MC2 rules you can use the GETCACHE element.

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

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

The extracted value is in the outVar variable.

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

For example, to put the value of variable inVar  to a cache with the name mc2cachetest using key=mc2key, 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 are created automatically during getting from the cache.

String

For a simple object such as a String there is no key in Redis.

To map an MC2 cache name and key into the Redis key, use a name and key concatenation, with colon as a separator, as a RedisKey.

For example, to put a String value into a cache with the name stringcache, use the key stringkey, which is bound to the Redis key stringcache:stringkey.

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

For example, for  the string value described above, the elements are:

<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, use the timetolive option in the PUTCACHE element. The time is defined in seconds.

For example, to define time to live in the previous example as 120 seconds, use the following element:

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