Search in sources :

Example 11 with GridRedisGenericException

use of org.apache.ignite.internal.processors.rest.handlers.redis.exception.GridRedisGenericException in project ignite by apache.

the class GridRedisAppendCommandHandler method asRestRequest.

/**
 * {@inheritDoc}
 */
@Override
public GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException {
    assert msg != null;
    if (msg.messageSize() < 3)
        throw new GridRedisGenericException("Wrong syntax");
    GridRestCacheRequest appendReq = new GridRestCacheRequest();
    GridRestCacheRequest getReq = new GridRestCacheRequest();
    String val = msg.aux(VAL_POS);
    appendReq.clientId(msg.clientId());
    appendReq.key(msg.key());
    appendReq.value(val);
    appendReq.command(CACHE_APPEND);
    appendReq.cacheName(msg.cacheName());
    Object resp = hnd.handle(appendReq).getResponse();
    if (resp != null && !(boolean) resp) {
        // append on non-existing key.
        GridRestCacheRequest setReq = new GridRestCacheRequest();
        setReq.clientId(msg.clientId());
        setReq.key(msg.key());
        setReq.value(val);
        setReq.command(CACHE_PUT);
        setReq.cacheName(msg.cacheName());
        hnd.handle(setReq);
    }
    getReq.clientId(msg.clientId());
    getReq.key(msg.key());
    getReq.command(CACHE_GET);
    getReq.cacheName(msg.cacheName());
    return getReq;
}
Also used : GridRestCacheRequest(org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest) GridRedisGenericException(org.apache.ignite.internal.processors.rest.handlers.redis.exception.GridRedisGenericException)

Aggregations

GridRedisGenericException (org.apache.ignite.internal.processors.rest.handlers.redis.exception.GridRedisGenericException)11 GridRestCacheRequest (org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest)11 HashMap (java.util.HashMap)1 IgniteAtomicLong (org.apache.ignite.IgniteAtomicLong)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteException (org.apache.ignite.IgniteException)1 GridRestResponse (org.apache.ignite.internal.processors.rest.GridRestResponse)1 GridRedisTypeException (org.apache.ignite.internal.processors.rest.handlers.redis.exception.GridRedisTypeException)1 DataStructuresRequest (org.apache.ignite.internal.processors.rest.request.DataStructuresRequest)1