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.