Goal: I'm trying to compose&run a Redis query with LSET
Steps: Command - use a raw command, then I'm adding something like "LSET {{ param1 }} {{ param2 }} {{ param3 }}"
Details: param3 contains a JSON encoded object. I have already escaped quotes, new-lines, etc, to make it work according to Redis CLI | Docs. If I inspect the state, the query.rawCommand attribute seems correct (I also can paste and run it successfully in a redis.cli)
Error: I'm getting though "ERR wrong number of arguments for 'lset' command". I have checked with Wireshark and indeed, the command is split weirdly on the wire, at places like escaped quotes in the last parameter (a.i. ")
So my question is: how does this work? I tried also not escaping the JSON encoded string, but of course, that's even worse.
This sounds like an issue with our query builder, which is altering your query's arguments.
You may need to try turning prepared statements off, which will give you greater control over the end formatting of your query at the risk of taking off any guard rails Retool has to prevent SQL injections or malicious queries.
Unfortunately, the Redis Resource Connector doesn't seem to have an option to turn off prepare statements, or I can't see it in the connection configuration.
Unfortunately, I think Discourse was fighting me on raw text that I pasted here. So you can see in a screen-shot image (attached to my initial post) exactly what I was sending.
I tried to follow this Redis CLI | Docs when escaping the JSON encoded string.
We might be able to do this my constructing the string in a JS Query block and then seeing if we can pass this directly into the query's raw input field.
Or maybe I misses something in how to call the Resource-Query? I'm pretty new to it and my JS is also rusty... What I did was that I had the Save action on a table row trigger my funcSaveSIMCard function which returns the query now and then trigger also the redisSaveSIMCard2 function. I feel like I'm doing something wrong there, as the order of the function calls is important, but the UI won't let me reorder the calls...
Yes correct, I was thinking if we have a function return the single entire argument as a string directly into the raw query that would be the closest we can get in the front end to setting the format.
Just tested out the query on a Redis resource and reproduced the error.
This is a bug on our end in the applications backend/Redis DB connector, the query builder can run into parsing issues when grabbing stringified objects. I can pass thing along to our engineering teams and keep you updated on this.
Is your use case involving Redis for saving data for preserve stateful data from the Retool front end?
To your point on the order of function calls, it looks like you are doing it correctly. Running the save func then the redis LSET function. You could try chaining the redis query to the "on success" handler for the save function to have them run synchronously.
Yes, I'm trying to have a basic CRUD to a Redis back-end. I might move to Postgres for this particular UI, but would be cool to have full capabilities with Redis too, since other components will stay on Redis. Those would benefit from being able to edit and delete data.
Cool tip with the chaining on success! That sounds cleaner/better than what I was doing. Thanks!
And of course, thanks for the follow-up and tracking!
Nope, unfortunately I'm getting the same thing - the parameters are not split correctly and the server complains.
I used double-quotes mainly because that's what the Redis documentation indicates for string definitions, so was hopefully the logical choice for a raw query.
I'm switching to PostgreSQL... but there I'm hitting another issue where I issue "ORDER BY" (with server-side pagination), yet the results are always ordered by primary key... I found a thread similar to my problem Sort columns when server side pagination is enabled
Turning off prepared queries helps... but it's dangerous...
Ah yes we have a ticket for that with our engineering team.
Apologies for the workaround needing to have prepared statements turned off, I completely understand the security concerns with that option.
I just added your +1 to that ticket and linked this thread to the ticket as well, so if there is any news on changes made so that 'order by' can work with server-side pagination I will let you know in this thread!
Apologies for the late response but I was able to get some good news on a potential solution to this Redis issue with the number of arguments from the string interpolation.
" The last parameter - the JSON blob - needs to be encoded as a single string.
The way we interpolate multiple template strings into a single string is fairly straightforward as just put the value of the string into the request we are building.
Let me pick this apart and go into a bit more detail:
Let's say we are trying to execute this command against redis:LSET {{ thingOne }} {{ thingTwo }}, where thingOne is two separated strings, and thingTwo is a JSON object.
LSET expects 3 space separated strings as it's parameters.
Our command then causes an issue because it interpolates into something like LSET key index { "a": 2 }, which redis isn't happy with because we are providing 6 space separated strings.
(upload://cVwfR6V9UbQBHuHRw7ELsMrOkZm.json) (10.8 KB)
To fix it we just need to make sure the JSON is interpolated as a single string, which can be done by surrounding it in single quotes, eg. LSET {{ thingOne }} '{{ thingTwo }}'
He shared with me a build out of a demo app where he built out a working solution, which I can attach below for you to clone and test out.
As long as the args are passed into the Redis query as
LSET {{ query3.data }} '{{ query2.data }}'
The query should build a string with three space seperated arguments and work correctly. As we believe the 'too many args' error is coming from empty spaces being addd into the JSON