use of redis.clients.jedis.json.JsonSetParams in project jedis by xetorthio.
the class RedisModulesPipelineTest method jsonV2.
@Test
public void jsonV2() {
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);
Connection c = createConnection();
Pipeline p = new Pipeline(c);
Response<String> setWithEscape = p.jsonSetWithEscape("foo", Path2.ROOT_PATH, hm1);
Response<Object> get = p.jsonGet("foo", Path2.ROOT_PATH);
Response<List<JSONArray>> mget = p.jsonMGet(Path2.ROOT_PATH, "foo");
Response<List<Long>> strLen = p.jsonStrLen("foo", new Path2("hello"));
Response<List<Long>> strApp = p.jsonStrAppend("foo", new Path2("hello"), "!");
Response<Long> del = p.jsonDel("foo", new Path2("hello"));
Response<String> set = p.jsonSet("bar", Path2.ROOT_PATH, gson.toJson("strung"));
Response<String> setWithParams = p.jsonSet("foo", Path2.ROOT_PATH, gson.toJson(hm2), new JsonSetParams().xx());
Response<String> setWithEscapeWithParams = p.jsonSetWithEscape("foo", Path2.ROOT_PATH, hm2, new JsonSetParams().xx());
Response<List<Object>> pop = p.jsonArrPop("foo", new Path2("array"));
Response<List<Object>> popWithIndex = p.jsonArrPop("foo", new Path2("array"), 2);
Response<List<Long>> append = p.jsonArrAppend("foo", Path2.of("$.array"), gson.toJson("b"), gson.toJson("d"));
Response<List<Long>> appendWithEscape = p.jsonArrAppendWithEscape("foo", Path2.of("$.array"), "e");
Response<List<Long>> index = p.jsonArrIndex("foo", Path2.of("$.array"), gson.toJson("b"));
Response<List<Long>> indexWithEscape = p.jsonArrIndexWithEscape("foo", Path2.of("$.array"), "b");
Response<List<Long>> insert = p.jsonArrInsert("foo", new Path2("array"), 0, gson.toJson("x"));
Response<List<Long>> insertWithEscape = p.jsonArrInsertWithEscape("foo", new Path2("array"), 0, "x");
Response<List<Long>> arrLen = p.jsonArrLen("foo", new Path2("array"));
Response<List<Long>> trim = p.jsonArrTrim("foo", new Path2("array"), 1, 2);
Response<List<Boolean>> toggle = p.jsonToggle("foo", new Path2("boolean"));
Response<List<Class<?>>> type = p.jsonType("foo", new Path2("boolean"));
Response<Long> clear = p.jsonClear("foo", new Path2("array"));
p.sync();
c.close();
assertEquals("OK", setWithEscape.get());
assertNotNull(get.get());
assertEquals(1, mget.get().size());
assertEquals(Long.valueOf(5), strLen.get().get(0));
assertEquals(1, strApp.get().size());
assertEquals(Long.valueOf(1), del.get());
assertEquals("OK", set.get());
assertEquals("OK", setWithParams.get());
assertEquals("OK", setWithEscapeWithParams.get());
assertEquals("c", pop.get().get(0));
assertEquals("b", popWithIndex.get().get(0));
assertEquals(Long.valueOf(3), append.get().get(0));
assertEquals(Long.valueOf(4), appendWithEscape.get().get(0));
assertEquals(Long.valueOf(1), index.get().get(0));
assertEquals(Long.valueOf(1), indexWithEscape.get().get(0));
assertEquals(Long.valueOf(5), insert.get().get(0));
assertEquals(Long.valueOf(6), insertWithEscape.get().get(0));
assertEquals(Long.valueOf(6), arrLen.get().get(0));
assertEquals(Long.valueOf(2), trim.get().get(0));
assertEquals(false, toggle.get().get(0));
assertEquals(boolean.class, type.get().get(0));
assertEquals(Long.valueOf(1), clear.get());
}
use of redis.clients.jedis.json.JsonSetParams 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());
}
Aggregations