Skip to content

exists command not properly finding keys with special characters #3255

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

Closed
xbcratos opened this issue Apr 10, 2025 · 4 comments
Closed

exists command not properly finding keys with special characters #3255

xbcratos opened this issue Apr 10, 2025 · 4 comments
Labels
status: waiting-for-feedback We need additional information before we can continue

Comments

@xbcratos
Copy link

xbcratos commented Apr 10, 2025

Bug Report

Current Behavior

When calling exists method for keys with special characters which are already stored in Redis, exists returns 0 instead of 1.

Failing test
fun test_rare_key() {
        val key = "première"
        val value = listOf(1.0F, 2.0F, 3.0F)
        cache.set(key, value)
        assertEquals(value, cache.get(key))
        assertEquals(1, cache.exists(key))
    }
Working test
fun test_key_simple() {
        val key = "key"
        val value = listOf(1.0F)
        cache.set(key, value)
        assertEquals(1, cache.exists(key))
    }

Input Code

Exists Code
 override fun exists(vararg keys: String): Long {
        var count: Long = 0L
        keys.forEach { key ->
            if (syncCommands.exists(ns.ensureNs(key)) > 0) {
                ++count
            }
        }
        return count
    }

Note that the syncCommands are retrieved from a Redis connection calling connect this way:

conn.connect(RedisCodec.of(StringCodec.UTF8, ByteArrayCodec.INSTANCE))

Expected behavior/code

Since the key already exists in Redis, exists should return 1 instead of 0.

Environment

  • Lettuce version(s): 6.2.7.RELEASE
  • Redis version: 7.1

Additional context

syncCommands above is an implementation of io.lettuce.core.dynamic.Commands provided by io.lettuce.core.dynamic.RedisCommandFactory getCommands(Class<T> commandInterface) method.

@tishun
Copy link
Collaborator

tishun commented Apr 10, 2025

Hey @xbcratos ,

can you test again with the 6.5.4 release?

We've changed the way characters are being encoded and this may have fixed the problem.

Is upgrading an option for you?

@tishun tishun added the status: waiting-for-feedback We need additional information before we can continue label Apr 10, 2025
@xbcratos
Copy link
Author

Hi @tishun ,

I'll need to double check if we can upgrade the client library version but in the mean time I have tested with 6.5.4 release and it seems it worked as expected.

Thanks for your help!

@tishun
Copy link
Collaborator

tishun commented Apr 10, 2025

Happy to help!

Let me know if upgrading is not an option for you. Can't make promises we will cross-port the change to 6.2.x but we may put it up for discussion.

@xbcratos
Copy link
Author

Thanks!

Upgrading actually will work for me :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-feedback We need additional information before we can continue
Projects
None yet
Development

No branches or pull requests

2 participants