Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISPN-14659 STRLEN command #10932

Merged
merged 2 commits into from
May 16, 2023
Merged

ISPN-14659 STRLEN command #10932

merged 2 commits into from
May 16, 2023

Conversation

rigazilla
Copy link
Contributor

byte[] keyBytes = arguments.get(0);

CompletableFuture<Long> strLenAsync = handler.cache().getAsync(keyBytes)
.thenCompose(buff -> CompletableFuture.completedFuture(Long.valueOf(buff!=null ? buff.length : 0)));
Copy link
Member

@wburns wburns May 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use thenCompose for synchronous invocations, just use thenApply.

Suggested change
.thenCompose(buff -> CompletableFuture.completedFuture(Long.valueOf(buff!=null ? buff.length : 0)));
.thenApply(buff -> buff!=null ? buff.length : 0L);

RedisCommands<String, String> redis = redisConnection.sync();
String key = "strlen";
String val = "Hello";
String app = " World";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test needs to test non ASCII characters as well, and verify the behavior with REDIS server. Unfortunately, https://redis.io/commands/strlen/ doesn't state what it does for non UTF-8 characters if it counts the bytes or the characters. (I have a feeling it may be the latter).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added test. Redis strings are sequence of bytes, so it counts bytes:

127.0.0.1:6379> set euro "€"
OK
127.0.0.1:6379> strlen euro
(integer) 3

@wburns wburns merged commit 6242465 into infinispan:main May 16, 2023
3 of 4 checks passed
@wburns
Copy link
Member

wburns commented May 16, 2023

Integrated into main, thanks @rigazilla !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants