Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions java/src/main/java/com/genexus/cache/redis/RedisClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import java.util.ArrayList;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import org.apache.commons.lang.StringUtils;

import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down Expand Up @@ -79,7 +79,11 @@ private void initCache(String hostOrRedisURL, String password, String cacheKeyPa
pool = new JedisPool(new JedisPoolConfig(), host, port, redis.clients.jedis.Protocol.DEFAULT_TIMEOUT, password);

objMapper = new ObjectMapper();
objMapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
objMapper
.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY)
.setVisibility(PropertyAccessor.GETTER, JsonAutoDetect.Visibility.NONE)
.setVisibility(PropertyAccessor.SETTER, JsonAutoDetect.Visibility.NONE)
.setVisibility(PropertyAccessor.CREATOR, JsonAutoDetect.Visibility.NONE);
objMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
objMapper.enable(SerializationFeature.INDENT_OUTPUT);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.genexus.cache.redis;

import com.genexus.db.CacheValue;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.genexus.specific.java.Connect;
Expand All @@ -10,6 +11,7 @@
import redis.clients.jedis.JedisPool;

import java.net.URISyntaxException;
import java.util.concurrent.ThreadLocalRandom;

import static org.junit.Assume.assumeTrue;

Expand Down Expand Up @@ -95,16 +97,30 @@ public void testSetRedis()
Assert.assertNotNull("Redis instance could not be created", redis);

String cacheId = "TEST";
String cacheKey = "TEST_KEY";
String cacheKey = "TEST_KEY" + ThreadLocalRandom.current().nextInt();
String cacheValue = "KeyValue";
redis.set(cacheId, cacheKey, cacheValue);

String obtainedValue = redis.get(cacheId, cacheKey, String.class);

Assert.assertEquals(obtainedValue, cacheValue);
}

@Test
public void testSetCacheValueRedis()
{
Connect.init();

RedisClient redis = getRedisClient("", "");
Assert.assertNotNull("Redis instance could not be created", redis);

String cacheId = "TEST"+ ThreadLocalRandom.current().nextInt();
String cacheKey = "TEST_KEY" + ThreadLocalRandom.current().nextInt();
CacheValue c = new CacheValue("SELECT * FROM User;", new Object[] { 1, 2, 3});
c.addItem(123);
redis.set(cacheId, cacheKey, c);
CacheValue obtainedValue = redis.get(cacheId, cacheKey, CacheValue.class);
Assert.assertNotNull(obtainedValue);
}


}