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

Getting different result when executing FT.SEARCH when using redis/redis-stack:7.0.6-RC8 vs redis/redis-stack-server:7.2.0-v5. (Multi is a Map) #417

Closed
GhenadieCebanu opened this issue Nov 10, 2023 · 6 comments · Fixed by #422
Labels
Milestone

Comments

@GhenadieCebanu
Copy link

GhenadieCebanu commented Nov 10, 2023

Questions

Getting different result when executing FT.SEARCH when using redis/redis-stack:7.0.6-RC8 vs redis/redis-stack-server:7.2.0-v5.

Version

vertx-redis-client 4.4.0

Context

I encountered an exception java.lang.RuntimeException: Multi is a Map while upgrading redis-stack.

Do you have a reproducer?

package com.demo;

import io.vertx.core.*;
import io.vertx.core.json.*;
import io.vertx.junit5.*;
import io.vertx.redis.client.*;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.extension.*;

@ExtendWith(VertxExtension.class)
class DemoRedisTest {

    @Test
    void Should_(Vertx vertx, VertxTestContext testContext) {

        var options = new RedisOptions()
                .setConnectionString("redis://:[email protected]:6379");

        Redis client = Redis.createClient(vertx, options);

        //FT.CREATE idx:item on JSON PREFIX 1 item: SCHEMA $.amount as amount NUMERIC SORTABLE
        Request createIndex = Request
                .cmd(Command.FT_CREATE)
                .arg("idx:item")
                .arg("on")
                .arg("JSON")
                .arg("PREFIX")
                .arg("1")
                .arg("item:")
                .arg("SCHEMA")

                .arg("$.amount")
                .arg("as")
                .arg("amount")
                .arg("NUMERIC")
                .arg("SORTABLE");


        Item item1 = new Item("1", "item1", 100);
        //JSON.SET item:1 $ '{"id":"1","name":"name1","amount":100}'
        Request storeItem = Request
                .cmd(Command.JSON_SET)
                .arg("item:1")
                .arg("$")
                .arg(Json.encode(item1));

        //FT.SEARCH idx:item "@amount:[0 +inf]" RETURN 1 amount SORTBY amount ASC LIMIT 0 100
        Request search = Request
                .cmd(Command.FT_SEARCH)
                .arg("idx:item")
                .arg("@amount:[0 +inf]")

                .arg("RETURN")
                .arg(1)
                .arg("amount")

                .arg("SORTBY")
                .arg("amount")
                .arg("ASC")

                .arg("LIMIT")
                .arg(0)
                .arg(100);


        client
                .send(createIndex)
                .recover(t -> Future.succeededFuture())
                .compose(unused -> client.send(storeItem))
                .compose(unused -> client.send(search))
                .map(response -> {
                    System.out.println(response);
                    return response.toString();
                })
                .onComplete(result -> {

                    if (result.failed()) {
                        System.out.println("Failed: " + result.cause());
                    } else {
                        System.out.println("Success");
                    }
                    testContext.completeNow();
                });
    }

    public static record Item(
            String id,
            String name,
            int amount) {

    }
}

Steps to reproduce

  1. Execute test using redis/redis-stack:7.0.6-RC8
    Expected output for println:
    [1, item:1, [amount, 100]]

  2. Execute test using redis/redis-stack-server:7.2.0-v5
    Expected output for println:
    [1, item:1, [amount, 100]]
    Actual output:
    {format: STRING, attributes: [], error: [], results: [{id: item:1, extra_attributes: {amount: 100}, values: []}], total_results: 1}

Extra

When executing search query from console, output is the same:

> FT.SEARCH idx:item "@amount:[0 +inf]" RETURN 1 amount SORTBY amount ASC LIMIT 0 100
1) "1"
2) "item:1"
3) 1) "amount"
   2) "100"

issue looks similar with: #347

@GhenadieCebanu
Copy link
Author

Solved

It is about Redis serialization protocol specification (https://redis.io/docs/reference/protocol-spec/),
with
redis/redis-stack:7.0.6-RC8 library will use RESP2,
redis/redis-stack-server:7.2.0-v5 library will use RESP3,

if we want to start client with RESP2, then we can set setProtocolNegotiation option to false when creating Redis client :

var options = new RedisOptions()
                .setConnectionString("redis://:[email protected]:6379")
                .setProtocolNegotiation(false);

at this point, not sure if it's a bug,
is there a way to specify using options to use RESP3?

@tsegismont tsegismont added this to the 4.5.1 milestone Nov 30, 2023
@tsegismont
Copy link
Contributor

Can you take care of this one @Ladicek ? Thanks!

@Ladicek
Copy link
Contributor

Ladicek commented Nov 30, 2023

I looked into this briefly a few days ago and it's a bit more involved. I'll look again when I have a bit more time.

@Ladicek
Copy link
Contributor

Ladicek commented Dec 4, 2023

OK, turns out I was misled confused by the notion of "search dialect", this is indeed a difference between RESP2 and 3 (see also https://docs.redis.com/latest/rs/references/compatibility/resp/).

I think the best course of action is to expose a config option for a preferred RESP version.

@Ladicek
Copy link
Contributor

Ladicek commented Dec 4, 2023

@GhenadieCebanu
Copy link
Author

PRs:

* [add configuration option for the preferred protocol version to use during handshake #422](https://github.com/vert-x3/vertx-redis-client/pull/422)

* [[4.x] add configuration option for the preferred protocol version to use during handshake #423](https://github.com/vert-x3/vertx-redis-client/pull/423)

@GhenadieCebanu I believe this fix should be enough for you, but I'd be happy to hear any comments you may have.

yes, this perfect, thank you!
think issue can be closed

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