Search in sources :

Example 1 with IRLObject

use of redis.clients.jedis.modules.json.JsonObjects.IRLObject in project jedis by xetorthio.

the class RedisModulesPipelineTest method jsonV1.

@Test
public void jsonV1() {
    Map<String, String> hm1 = new HashMap<>();
    hm1.put("hello", "world");
    hm1.put("oh", "snap");
    Map<String, Object> hm2 = new HashMap<>();
    hm2.put("array", new String[] { "a", "b", "c" });
    hm2.put("boolean", true);
    hm2.put("number", 3);
    Baz baz1 = new Baz("quuz1", "grault1", "waldo1");
    Baz baz2 = new Baz("quuz2", "grault2", "waldo2");
    Baz baz3 = new Baz("quuz3", "grault3", "waldo3");
    Connection c = createConnection();
    Pipeline p = new Pipeline(c);
    Response<String> set1 = p.jsonSet("foo", Path.ROOT_PATH, hm1);
    Response<Object> get = p.jsonGet("foo");
    Response<Map> getObject = p.jsonGet("foo", Map.class);
    Response<Object> getWithPath = p.jsonGet("foo", Path.ROOT_PATH);
    Response<Map> getObjectWithPath = p.jsonGet("foo", Map.class, Path.ROOT_PATH);
    Response<List<JSONArray>> mget = p.jsonMGet("foo");
    p.jsonSet("baz", new JSONObject(gson.toJson(baz1)));
    Response<List<Baz>> mgetClass = p.jsonMGet(Path.ROOT_PATH, Baz.class, "baz");
    Response<Long> strLenPath = p.jsonStrLen("foo", new Path("hello"));
    Response<Long> strAppPath = p.jsonStrAppend("foo", new Path("hello"), "!");
    Response<Long> delPath = p.jsonDel("foo", new Path("hello"));
    Response<Long> delKey = p.jsonDel("foo");
    Response<String> set2 = p.jsonSet("foo", Path.ROOT_PATH, hm2, new JsonSetParams().nx());
    Response<Object> popPath = p.jsonArrPop("foo", new Path("array"));
    Response<Object> indexPop = p.jsonArrPop("foo", new Path("array"), 2);
    Response<Long> append = p.jsonArrAppend("foo", new Path("array"), "b", "c", "d");
    Response<Long> index = p.jsonArrIndex("foo", new Path("array"), "c");
    Response<Long> insert = p.jsonArrInsert("foo", new Path("array"), 0, "x");
    Response<Long> arrLenWithPath = p.jsonArrLen("foo", new Path("array"));
    Response<Long> trim = p.jsonArrTrim("foo", new Path("array"), 1, 4);
    Response<String> toggle = p.jsonToggle("foo", new Path("boolean"));
    Response<Class<?>> type = p.jsonType("foo", new Path("boolean"));
    Response<Class<?>> keyType = p.jsonType("foo");
    Response<Long> clearPath = p.jsonClear("foo", new Path("boolean"));
    Response<Long> clearKey = p.jsonClear("foo");
    Response<String> set3 = p.jsonSet("foo", Path.ROOT_PATH, "newStr");
    Response<Long> strLen = p.jsonStrLen("foo");
    Response<Long> strApp = p.jsonStrAppend("foo", "?");
    Response<String> set4 = p.jsonSetWithEscape("obj", new IRLObject());
    p.jsonSet("arr", ROOT_PATH, new int[] { 0, 1, 2, 3 });
    Response<Object> pop = p.jsonArrPop("arr");
    Response<Long> arrLen = p.jsonArrLen("arr");
    p.jsonSet("baz", ROOT_PATH, new Baz[] { baz1, baz2, baz3 });
    Response<Baz> popClass = p.jsonArrPop("baz", Baz.class);
    Response<Baz> popClassWithPath = p.jsonArrPop("baz", Baz.class, Path.ROOT_PATH);
    Response<Baz> popClassWithIndex = p.jsonArrPop("baz", Baz.class, Path.ROOT_PATH, 0);
    p.sync();
    c.close();
    assertEquals("OK", set1.get());
    assertEquals(hm1, get.get());
    assertEquals(hm1, getObject.get());
    assertEquals(hm1, getWithPath.get());
    assertEquals(hm1, getObjectWithPath.get());
    assertEquals(1, mget.get().size());
    assertEquals(baz1, mgetClass.get().get(0));
    assertEquals(Long.valueOf(5), strLenPath.get());
    assertEquals(Long.valueOf(6), strAppPath.get());
    assertEquals(Long.valueOf(1), delPath.get());
    assertEquals(Long.valueOf(1), delKey.get());
    assertEquals("OK", set2.get());
    assertEquals("c", popPath.get());
    assertEquals("b", indexPop.get());
    assertEquals(Long.valueOf(4), append.get());
    assertEquals(Long.valueOf(2), index.get());
    assertEquals(Long.valueOf(5), insert.get());
    assertEquals(Long.valueOf(5), arrLenWithPath.get());
    assertEquals(Long.valueOf(4), trim.get());
    assertEquals("false", toggle.get());
    assertEquals(boolean.class, type.get());
    assertEquals(Object.class, keyType.get());
    assertEquals(Long.valueOf(0), clearPath.get());
    assertEquals(Long.valueOf(1), clearKey.get());
    assertEquals("OK", set3.get());
    assertEquals(Long.valueOf(6), strLen.get());
    assertEquals(Long.valueOf(7), strApp.get());
    assertEquals("OK", set4.get());
    assertEquals(3.0, pop.get());
    assertEquals(Long.valueOf(3), arrLen.get());
    assertEquals(baz3, popClass.get());
    assertEquals(baz2, popClassWithPath.get());
    assertEquals(baz1, popClassWithIndex.get());
}
Also used : Path(redis.clients.jedis.json.Path) IRLObject(redis.clients.jedis.modules.json.JsonObjects.IRLObject) HashMap(java.util.HashMap) Connection(redis.clients.jedis.Connection) JsonSetParams(redis.clients.jedis.json.JsonSetParams) Pipeline(redis.clients.jedis.Pipeline) JSONObject(org.json.JSONObject) IRLObject(redis.clients.jedis.modules.json.JsonObjects.IRLObject) JSONObject(org.json.JSONObject) Baz(redis.clients.jedis.modules.json.JsonObjects.Baz) List(java.util.List) BeforeClass(org.junit.BeforeClass) HashMap(java.util.HashMap) RediSearchUtil.toStringMap(redis.clients.jedis.search.RediSearchUtil.toStringMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 JSONObject (org.json.JSONObject)1 BeforeClass (org.junit.BeforeClass)1 Test (org.junit.Test)1 Connection (redis.clients.jedis.Connection)1 Pipeline (redis.clients.jedis.Pipeline)1 JsonSetParams (redis.clients.jedis.json.JsonSetParams)1 Path (redis.clients.jedis.json.Path)1 Baz (redis.clients.jedis.modules.json.JsonObjects.Baz)1 IRLObject (redis.clients.jedis.modules.json.JsonObjects.IRLObject)1 RediSearchUtil.toStringMap (redis.clients.jedis.search.RediSearchUtil.toStringMap)1