From 2fdf928c33b6462f7452b3014e44eb49b58cc9f7 Mon Sep 17 00:00:00 2001 From: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com> Date: Mon, 11 Nov 2024 23:00:41 +0600 Subject: [PATCH 01/10] COMMAND INFO reply contains subcommand detail (#4022) * COMMAND INFO reply contains subcommand detail * Add 'name' in CommandInfo Fixes #4020 ___ * COMMAND INFO reply contains subcommand detail * Add 'name' in CommandInfo * Safeguard test from future ACL subcommands * Ensure reply size * Move null checking into COMMAND_INFO_BUILDER from inside loop and reduce parsing 'name' multiple times --- .../redis/clients/jedis/BuilderFactory.java | 26 +------- src/main/java/redis/clients/jedis/Jedis.java | 2 +- .../clients/jedis/resps/CommandInfo.java | 64 +++++++++++++++++-- .../commands/jedis/ControlCommandsTest.java | 21 ++++++ 4 files changed, 83 insertions(+), 30 deletions(-) diff --git a/src/main/java/redis/clients/jedis/BuilderFactory.java b/src/main/java/redis/clients/jedis/BuilderFactory.java index adce27f1f4..b1ca7455b9 100644 --- a/src/main/java/redis/clients/jedis/BuilderFactory.java +++ b/src/main/java/redis/clients/jedis/BuilderFactory.java @@ -975,30 +975,8 @@ public Map build(Object data) { } }; - public static final Builder> COMMAND_INFO_RESPONSE = new Builder>() { - @Override - public Map build(Object data) { - if (data == null) { - return null; - } - - List rawList = (List) data; - Map map = new HashMap<>(rawList.size()); - - for (Object rawCommandInfo : rawList) { - if (rawCommandInfo == null) { - continue; - } - - List commandInfo = (List) rawCommandInfo; - String name = STRING.build(commandInfo.get(0)); - CommandInfo info = CommandInfo.COMMAND_INFO_BUILDER.build(commandInfo); - map.put(name, info); - } - - return map; - } - }; + @Deprecated + public static final Builder> COMMAND_INFO_RESPONSE = CommandInfo.COMMAND_INFO_RESPONSE; public static final Builder> LATENCY_LATEST_RESPONSE = new Builder>() { @Override diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index b6148189a8..fb2efd6460 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -8250,7 +8250,7 @@ public List>> commandGetKeysAndFlags(String... com public Map commandInfo(String... commands) { checkIsInMultiOrPipeline(); connection.sendCommand(COMMAND, joinParameters(Keyword.INFO.name(), commands)); - return BuilderFactory.COMMAND_INFO_RESPONSE.build(connection.getOne()); + return CommandInfo.COMMAND_INFO_RESPONSE.build(connection.getOne()); } public List commandList() { diff --git a/src/main/java/redis/clients/jedis/resps/CommandInfo.java b/src/main/java/redis/clients/jedis/resps/CommandInfo.java index 9f3481b5a1..efdf582102 100644 --- a/src/main/java/redis/clients/jedis/resps/CommandInfo.java +++ b/src/main/java/redis/clients/jedis/resps/CommandInfo.java @@ -2,12 +2,17 @@ import redis.clients.jedis.Builder; +import java.util.HashMap; import java.util.List; +import java.util.Map; -import static redis.clients.jedis.BuilderFactory.STRING_LIST; import static redis.clients.jedis.BuilderFactory.LONG; +import static redis.clients.jedis.BuilderFactory.STRING; +import static redis.clients.jedis.BuilderFactory.STRING_LIST; public class CommandInfo { + + private final String name; private final long arity; private final List flags; private final long firstKey; @@ -15,10 +20,22 @@ public class CommandInfo { private final long step; private final List aclCategories; private final List tips; - private final List subcommands; + private final Map subcommands; + /** + * THIS IGNORES 'subcommands' parameter. + * @param subcommands WILL BE IGNORED + * @deprecated + */ + @Deprecated public CommandInfo(long arity, List flags, long firstKey, long lastKey, long step, List aclCategories, List tips, List subcommands) { + this((String) null, arity, flags, firstKey, lastKey, step, aclCategories, tips, (Map) null); + } + + private CommandInfo(String name, long arity, List flags, long firstKey, long lastKey, long step, + List aclCategories, List tips, Map subcommands) { + this.name = name; this.arity = arity; this.flags = flags; this.firstKey = firstKey; @@ -29,6 +46,13 @@ public CommandInfo(long arity, List flags, long firstKey, long lastKey, this.subcommands = subcommands; } + /** + * Command name + */ + public String getName() { + return name; + } + /** * Arity is the number of arguments a command expects. It follows a simple pattern: * A positive integer means a fixed number of arguments. @@ -89,15 +113,23 @@ public List getTips() { /** * All the command's subcommands, if any */ - public List getSubcommands() { + public Map getSubcommands() { return subcommands; } public static final Builder COMMAND_INFO_BUILDER = new Builder() { @Override public CommandInfo build(Object data) { + if (data == null) { + return null; + } + List commandData = (List) data; + if (commandData.isEmpty()) { + return null; + } + String name = STRING.build(commandData.get(0)); long arity = LONG.build(commandData.get(1)); List flags = STRING_LIST.build(commandData.get(2)); long firstKey = LONG.build(commandData.get(3)); @@ -105,9 +137,31 @@ public CommandInfo build(Object data) { long step = LONG.build(commandData.get(5)); List aclCategories = STRING_LIST.build(commandData.get(6)); List tips = STRING_LIST.build(commandData.get(7)); - List subcommands = STRING_LIST.build(commandData.get(9)); + Map subcommands = COMMAND_INFO_RESPONSE.build(commandData.get(9)); + + return new CommandInfo(name, arity, flags, firstKey, lastKey, step, aclCategories, tips, subcommands); + } + }; - return new CommandInfo(arity, flags, firstKey, lastKey, step, aclCategories, tips, subcommands); + public static final Builder> COMMAND_INFO_RESPONSE = new Builder>() { + @Override + public Map build(Object data) { + if (data == null) { + return null; + } + + List rawList = (List) data; + Map map = new HashMap<>(rawList.size()); + + for (Object rawCommandInfo : rawList) { + CommandInfo info = CommandInfo.COMMAND_INFO_BUILDER.build(rawCommandInfo); + if (info != null) { + map.put(info.getName(), info); + } + } + + return map; } }; + } diff --git a/src/test/java/redis/clients/jedis/commands/jedis/ControlCommandsTest.java b/src/test/java/redis/clients/jedis/commands/jedis/ControlCommandsTest.java index 4c9059f8d0..4b67a295c7 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/ControlCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/ControlCommandsTest.java @@ -520,6 +520,27 @@ public void commandInfo() { assertEquals(0, setInfo.getSubcommands().size()); } + @Test // GitHub Issue #4020 + public void commandInfoAcl() { + Map infos = jedis.commandInfo("ACL"); + assertThat(infos, Matchers.aMapWithSize(1)); + + CommandInfo aclInfo = infos.get("acl"); + assertEquals(-2, aclInfo.getArity()); + assertEquals(0, aclInfo.getFlags().size()); + assertEquals(0, aclInfo.getFirstKey()); + assertEquals(0, aclInfo.getLastKey()); + assertEquals(0, aclInfo.getStep()); + assertEquals(1, aclInfo.getAclCategories().size()); + assertEquals(0, aclInfo.getTips().size()); + assertThat(aclInfo.getSubcommands().size(), Matchers.greaterThanOrEqualTo(13)); + aclInfo.getSubcommands().forEach((name, subcommand) -> { + assertThat(name, Matchers.startsWith("acl|")); + assertNotNull(subcommand); + assertEquals(name, subcommand.getName()); + }); + } + @Test public void commandList() { List commands = jedis.commandList(); From 04eac1e0c29492d282ae4ebf30b00cccdf977e55 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 17 Nov 2024 17:12:57 +0600 Subject: [PATCH 02/10] Bump org.apache.maven.plugins:maven-surefire-plugin from 3.5.1 to 3.5.2 (#4008) Bumps [org.apache.maven.plugins:maven-surefire-plugin](https://github.com/apache/maven-surefire) from 3.5.1 to 3.5.2. - [Release notes](https://github.com/apache/maven-surefire/releases) - [Commits](https://github.com/apache/maven-surefire/compare/surefire-3.5.1...surefire-3.5.2) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-surefire-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 4060d175be..b6cdf46ecd 100644 --- a/pom.xml +++ b/pom.xml @@ -50,7 +50,7 @@ 1.7.36 1.7.1 2.18.1 - 3.5.1 + 3.5.2 From f4985134f4e83c254143f9417a98f7c36f7104f2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 18 Nov 2024 14:18:38 +0600 Subject: [PATCH 03/10] Bump org.apache.maven.plugins:maven-javadoc-plugin from 3.10.1 to 3.11.1 (#4007) Bumps [org.apache.maven.plugins:maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.10.1 to 3.11.1. - [Release notes](https://github.com/apache/maven-javadoc-plugin/releases) - [Commits](https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-3.10.1...maven-javadoc-plugin-3.11.1) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-javadoc-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b6cdf46ecd..097e095536 100644 --- a/pom.xml +++ b/pom.xml @@ -247,7 +247,7 @@ maven-javadoc-plugin - 3.10.1 + 3.11.1 8 false From fcdc0d5b6bf1cb793376d39e305d3fad819c71ad Mon Sep 17 00:00:00 2001 From: josh rotenberg Date: Tue, 19 Nov 2024 03:14:31 -0800 Subject: [PATCH 04/10] Add examples and tutorials page (#4024) * add exmples and tutorials page * update wordlist --- .github/wordlist.txt | 33 +++++++++++++++++++++++---------- docs/tutorials_examples.md | 21 +++++++++++++++++++++ mkdocs.yml | 1 + 3 files changed, 45 insertions(+), 10 deletions(-) create mode 100644 docs/tutorials_examples.md diff --git a/.github/wordlist.txt b/.github/wordlist.txt index ee74a49a51..3c522108fd 100644 --- a/.github/wordlist.txt +++ b/.github/wordlist.txt @@ -1,8 +1,8 @@ !!!Spelling check failed!!! APM ARGV -BaseObjectPoolConfig BFCommands +BaseObjectPoolConfig BitOP BitPosParams BuilderFactory @@ -20,10 +20,10 @@ CoreCommands Dockerfile EVAL EVALSHA -Failback -Failover FTCreateParams FTSearchParams +Failback +Failover GSON GenericObjectPool GenericObjectPoolConfig @@ -54,6 +54,7 @@ ListPosition Ludovico Magnocavallo McCurdy +MkDocs NOSCRIPT NUMPAT NUMPT @@ -65,8 +66,10 @@ OpenTracing Otel POJO POJOs +PoolConfig PubSub Queable +README READONLY RediSearch RediSearchCommands @@ -79,9 +82,11 @@ RedisGraph RedisInstrumentor RedisJSON RedisTimeSeries +Redislabs SHA SSLParameters SSLSocketFactory +SafeEncoder SearchCommands SentinelCommands SentinelConnectionPool @@ -126,6 +131,7 @@ bool boolean booleans bysource +cd charset clientId clientKill @@ -135,6 +141,7 @@ clusterKeySlot configs consumerName consumername +csc cumbersome dbIndex dbSize @@ -159,6 +166,7 @@ geoadd georadiusByMemberStore georadiusStore getbit +github gmail groupname hdel @@ -171,6 +179,7 @@ hset hsetnx hstrlen http +https idx iff incr @@ -178,13 +187,17 @@ incrBy incrByFloat ini io +jedis json +kb keyslot keyspace keysvalues +kllayn kwarg lastName lastsave +learningpath linsert linters llen @@ -197,14 +210,13 @@ makeapullrequest maxLen maxdepth maya +md memberCoordinateMap mget microservice microservices millisecondsTimestamp -MkDocs mkdocs -md mset msetnx multikey @@ -222,16 +234,18 @@ pexpire pexpireAt pfadd pfcount +pipelining pmessage png pre +produsage psubscribe pttl pubsub punsubscribe py pypi -PoolConfig +qsrk quickstart readonly readwrite @@ -242,12 +256,10 @@ reinitialization renamenx replicaof repo -README rpush rpushx runtime sadd -SafeEncoder scard scoreMembers sdiffstore @@ -270,7 +282,6 @@ strlen stunnel subcommands sunionstore -pipelining thevalueofmykey timeseries toctree @@ -289,13 +300,16 @@ url virtualenv waitReplicas whenver +wtd www xack xdel xgroupDelConsumer xgroupDestroy xlen +xpx xtrim +yml zadd zcard zcount @@ -322,4 +336,3 @@ zrevrangeByScore zrevrangeByScoreWithScores zrevrangeWithScores zunionstore -yml diff --git a/docs/tutorials_examples.md b/docs/tutorials_examples.md new file mode 100644 index 0000000000..16b90842ba --- /dev/null +++ b/docs/tutorials_examples.md @@ -0,0 +1,21 @@ +# Tutorials and Examples + +## General + +* Redis for Java Developers: +* Jedis Guide: +* Connecting to a Redis server: +* Using Jedis in production: + +## Client-side Caching + +* Client-side Caching: + +## JSON + +* Store, Read and Search JSON: + +## Search + +* Vector Search: +* Spring Boot Search: diff --git a/mkdocs.yml b/mkdocs.yml index 83000d59c1..679393261b 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -30,6 +30,7 @@ nav: - Failover: failover.md - FAQ: faq.md - API Reference: https://www.javadoc.io/doc/redis.clients/jedis/latest/index.html + - Tutorials and Examples: tutorials_examples.md - Jedis Guide: https://redis.io/docs/latest/develop/connect/clients/java/jedis/ - Redis Command Reference: https://redis.io/docs/latest/commands/ From eb6cc47a2782039c87146a5093420b2e3b58b46c Mon Sep 17 00:00:00 2001 From: ggivo Date: Wed, 20 Nov 2024 13:54:56 +0200 Subject: [PATCH 05/10] Implement command (no arg) (#4026) * Implement command (no arg) https://redis.io/docs/latest/commands/command/ Adding it for completeness and as alternative to COMMAND INFO for Redis server prior 7.0.0. COMMAND (no args) is available with Redis 2.x COMMAND INFO is available since REDIS version 7.0.0 Relates to: #2922 Support COMMAND commands (#2922) commit : 35904380a3388721bf27980171e6446b5181c3e8 Closes #793 * Update ControlCommandsTest.java --------- Co-authored-by: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com> --- src/main/java/redis/clients/jedis/Jedis.java | 6 +++++ .../commands/jedis/ControlCommandsTest.java | 22 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index fb2efd6460..04c8945993 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -8253,6 +8253,12 @@ public Map commandInfo(String... commands) { return CommandInfo.COMMAND_INFO_RESPONSE.build(connection.getOne()); } + public Map command() { + checkIsInMultiOrPipeline(); + connection.sendCommand(COMMAND); + return CommandInfo.COMMAND_INFO_RESPONSE.build(connection.getOne()); + } + public List commandList() { checkIsInMultiOrPipeline(); connection.sendCommand(COMMAND, LIST); diff --git a/src/test/java/redis/clients/jedis/commands/jedis/ControlCommandsTest.java b/src/test/java/redis/clients/jedis/commands/jedis/ControlCommandsTest.java index 4b67a295c7..d79eb2086f 100644 --- a/src/test/java/redis/clients/jedis/commands/jedis/ControlCommandsTest.java +++ b/src/test/java/redis/clients/jedis/commands/jedis/ControlCommandsTest.java @@ -501,6 +501,28 @@ public void commandGetKeys() { assertEquals(2, keySandFlags.get(0).getValue().size()); } + + @Test + public void commandNoArgs() { + Map infos = jedis.command(); + + assertThat(infos.size(), greaterThan(0)); + + CommandInfo getInfo = infos.get("get"); + assertEquals(2, getInfo.getArity()); + assertEquals(2, getInfo.getFlags().size()); + assertEquals(1, getInfo.getFirstKey()); + assertEquals(1, getInfo.getLastKey()); + assertEquals(1, getInfo.getStep()); + + assertNull(infos.get("foo")); // non-existing command + + CommandInfo setInfo = infos.get("set"); + assertEquals(3, setInfo.getAclCategories().size()); + assertEquals(0, setInfo.getTips().size()); + assertEquals(0, setInfo.getSubcommands().size()); + } + @Test public void commandInfo() { Map infos = jedis.commandInfo("GET", "foo", "SET"); From 74795cb3229f6d10fabed4ad3aee9ed902e98773 Mon Sep 17 00:00:00 2001 From: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com> Date: Wed, 27 Nov 2024 21:50:55 +0600 Subject: [PATCH 06/10] Make reply of ACL LOG compatible with older Redis versions (#4030) --- .../redis/clients/jedis/resps/AccessControlLogEntry.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/redis/clients/jedis/resps/AccessControlLogEntry.java b/src/main/java/redis/clients/jedis/resps/AccessControlLogEntry.java index 930c9b064d..922d37fd6a 100644 --- a/src/main/java/redis/clients/jedis/resps/AccessControlLogEntry.java +++ b/src/main/java/redis/clients/jedis/resps/AccessControlLogEntry.java @@ -47,9 +47,10 @@ public AccessControlLogEntry(Map map) { ageSeconds = (Double) map.get(AGE_SECONDS); clientInfo = getMapFromRawClientInfo((String) map.get(CLIENT_INFO)); logEntry = map; - entryId = (long) map.get(ENTRY_ID); - timestampCreated = (long) map.get(TIMESTAMP_CREATED); - timestampLastUpdated = (long) map.get(TIMESTAMP_LAST_UPDATED); + // Redis 7.2 + entryId = map.containsKey(ENTRY_ID) ? (long) map.get(ENTRY_ID) : -1L; + timestampCreated = map.containsKey(TIMESTAMP_CREATED) ? (long) map.get(TIMESTAMP_CREATED) : -1L; + timestampLastUpdated = map.containsKey(TIMESTAMP_LAST_UPDATED) ? (long) map.get(TIMESTAMP_LAST_UPDATED) : -1L; } public long getCount() { From d34b36eae20d4482df83330a0551edfe818190fc Mon Sep 17 00:00:00 2001 From: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com> Date: Wed, 27 Nov 2024 22:10:50 +0600 Subject: [PATCH 07/10] Make reply of COMMAND INFO compatible with older Redis versions (#4031) --- src/main/java/redis/clients/jedis/resps/CommandInfo.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/redis/clients/jedis/resps/CommandInfo.java b/src/main/java/redis/clients/jedis/resps/CommandInfo.java index efdf582102..7dd15c8684 100644 --- a/src/main/java/redis/clients/jedis/resps/CommandInfo.java +++ b/src/main/java/redis/clients/jedis/resps/CommandInfo.java @@ -135,9 +135,12 @@ public CommandInfo build(Object data) { long firstKey = LONG.build(commandData.get(3)); long lastKey = LONG.build(commandData.get(4)); long step = LONG.build(commandData.get(5)); - List aclCategories = STRING_LIST.build(commandData.get(6)); - List tips = STRING_LIST.build(commandData.get(7)); - Map subcommands = COMMAND_INFO_RESPONSE.build(commandData.get(9)); + // Redis 6.0 + List aclCategories = commandData.size() >= 7 ? STRING_LIST.build(commandData.get(6)) : null; + // Redis 7.0 + List tips = commandData.size() >= 8 ? STRING_LIST.build(commandData.get(7)) : null; + Map subcommands = commandData.size() >= 10 + ? COMMAND_INFO_RESPONSE.build(commandData.get(9)) : null; return new CommandInfo(name, arity, flags, firstKey, lastKey, step, aclCategories, tips, subcommands); } From ad593ba1590c5756ee118eb686998dd97757aa24 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 2 Dec 2024 18:16:17 +0600 Subject: [PATCH 08/10] Bump jackson.version from 2.18.1 to 2.18.2 (#4034) Bumps `jackson.version` from 2.18.1 to 2.18.2. Updates `com.fasterxml.jackson.core:jackson-databind` from 2.18.1 to 2.18.2 - [Commits](https://github.com/FasterXML/jackson/commits) Updates `com.fasterxml.jackson.datatype:jackson-datatype-jsr310` from 2.18.1 to 2.18.2 --- updated-dependencies: - dependency-name: com.fasterxml.jackson.core:jackson-databind dependency-type: direct:development update-type: version-update:semver-patch - dependency-name: com.fasterxml.jackson.datatype:jackson-datatype-jsr310 dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 097e095536..b73fe4595b 100644 --- a/pom.xml +++ b/pom.xml @@ -49,7 +49,7 @@ redis.clients.jedis 1.7.36 1.7.1 - 2.18.1 + 2.18.2 3.5.2 From 03ce34048b958db3006ceef493f2b2e6924d895a Mon Sep 17 00:00:00 2001 From: andy-stark-redis <164213578+andy-stark-redis@users.noreply.github.com> Date: Sat, 7 Dec 2024 12:48:55 +0000 Subject: [PATCH 09/10] DOC-4560 pipe/transaction examples for docs (#4038) * DOC-4560 pipe/transaction examples for docs * Update src/test/java/io/redis/examples/PipeTransExample.java Co-authored-by: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com> --------- Co-authored-by: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com> --- .../io/redis/examples/PipeTransExample.java | 118 ++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 src/test/java/io/redis/examples/PipeTransExample.java diff --git a/src/test/java/io/redis/examples/PipeTransExample.java b/src/test/java/io/redis/examples/PipeTransExample.java new file mode 100644 index 0000000000..c4d75fa0e2 --- /dev/null +++ b/src/test/java/io/redis/examples/PipeTransExample.java @@ -0,0 +1,118 @@ +// EXAMPLE: pipe_trans_tutorial +// REMOVE_START +package io.redis.examples; + +import org.junit.Assert; +import org.junit.Test; +// REMOVE_END +import java.util.List; + +import redis.clients.jedis.UnifiedJedis; +import redis.clients.jedis.AbstractPipeline; +import redis.clients.jedis.AbstractTransaction; +import redis.clients.jedis.Response; + +public class PipeTransExample { + @Test + public void run() { + UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379"); + // REMOVE_START + for (int i = 0; i < 5; i++) { + jedis.del(String.format("seat:%d", i)); + } + + jedis.del("counter:1", "counter:2", "counter:3", "shellpath"); + // REMOVE_END + + // STEP_START basic_pipe + AbstractPipeline pipe = jedis.pipelined(); + + for (int i = 0; i < 5; i++) { + pipe.set(String.format("seat:%d", i), String.format("#%d", i)); + } + + pipe.sync(); + + pipe = jedis.pipelined(); + + Response resp0 = pipe.get("seat:0"); + Response resp3 = pipe.get("seat:3"); + Response resp4 = pipe.get("seat:4"); + + pipe.sync(); + + // Responses are available after the pipeline has executed. + System.out.println(resp0.get()); // >>> #0 + System.out.println(resp3.get()); // >>> #3 + System.out.println(resp4.get()); // >>> #4 + // STEP_END + // REMOVE_START + Assert.assertEquals("#0", resp0.get()); + Assert.assertEquals("#3", resp3.get()); + Assert.assertEquals("#4", resp4.get()); + // REMOVE_END + + // STEP_START basic_trans + AbstractTransaction trans = jedis.multi(); + + trans.incrBy("counter:1", 1); + trans.incrBy("counter:2", 2); + trans.incrBy("counter:3", 3); + + trans.exec(); + + System.out.println(jedis.get("counter:1")); // >>> 1 + System.out.println(jedis.get("counter:2")); // >>> 2 + System.out.println(jedis.get("counter:3")); // >>> 3 + // STEP_END + // REMOVE_START + Assert.assertEquals("1", jedis.get("counter:1")); + Assert.assertEquals("2", jedis.get("counter:2")); + Assert.assertEquals("3", jedis.get("counter:3")); + // REMOVE_END + + // STEP_START trans_watch + // Set initial value of `shellpath`. + jedis.set("shellpath", "/usr/syscmds/"); + + // Start the transaction and watch the key we are about to update. + trans = jedis.transaction(false); // create a Transaction object without sending MULTI command + trans.watch("shellpath"); // send WATCH command(s) + trans.multi(); // send MULTI command + + String currentPath = jedis.get("shellpath"); + String newPath = currentPath + ":/usr/mycmds/"; + + // Commands added to the `trans` object + // will be buffered until `trans.exec()` is called. + Response setResult = trans.set("shellpath", newPath); + List transResults = trans.exec(); + + // The `exec()` call returns null if the transaction failed. + if (transResults != null) { + // Responses are available if the transaction succeeded. + System.out.println(setResult.get()); // >>> OK + + // You can also get the results from the list returned by + // `trans.exec()`. + for (Object item: transResults) { + System.out.println(item); + } + // >>> OK + + System.out.println(jedis.get("shellpath")); + // >>> /usr/syscmds/:/usr/mycmds/ + } + // STEP_END + // REMOVE_START + Assert.assertEquals("/usr/syscmds/:/usr/mycmds/", jedis.get("shellpath")); + Assert.assertEquals("OK", setResult.get()); + Assert.assertEquals(1, transResults.size()); + Assert.assertEquals("OK", transResults.get(0).toString()); + // REMOVE_END + + // HIDE_START + jedis.close(); + } +} +// HIDE_END \ No newline at end of file From 90583d08a67e287f89a100a3b67907428e877e7f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 12 Dec 2024 01:07:27 +0600 Subject: [PATCH 10/10] Bump org.apache.maven.plugins:maven-javadoc-plugin from 3.11.1 to 3.11.2 (#4039) Bumps [org.apache.maven.plugins:maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.11.1 to 3.11.2. - [Release notes](https://github.com/apache/maven-javadoc-plugin/releases) - [Commits](https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-3.11.1...maven-javadoc-plugin-3.11.2) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-javadoc-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b73fe4595b..5b9cf55500 100644 --- a/pom.xml +++ b/pom.xml @@ -247,7 +247,7 @@ maven-javadoc-plugin - 3.11.1 + 3.11.2 8 false