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;
}
Aggregations