redismodule-rs icon indicating copy to clipboard operation
redismodule-rs copied to clipboard

Parameters shouldn't be owned by command

Open unrealhoang opened this issue 6 years ago • 4 comments

Should this signature:

fn hello_mul(_: &Context, args: Vec<String>) -> RedisResult {

become:

fn hello_mul(_: &'ae Context, args: &'a [&'a str]) -> RedisResult {

Right now, to convert the params into Rust's String requires to_string() which allocates. Also, it's semantically more correct.

unrealhoang avatar May 06 '19 01:05 unrealhoang

@unrealhoang Thanks for opening the issue. This is indeed something that needs careful consideration; we’ll take a look to see what the best solution would be.

gavrie avatar May 06 '19 12:05 gavrie

The function should probably be generic and accept any type that implements IntoIterator<Item=&str>?

tamird avatar May 06 '19 16:05 tamird

@unrealhoang @tamird I've been looking into this for a bit. We currently use create owned strings from the arguments that Redis handles to us. It might be a good idea to use references instead, and then pass those on to the command functions. This is a bit of a large change; I'll update when there will be progress.

gavrie avatar Sep 04 '19 13:09 gavrie

@gavrie This can be probably closed after #157 has been merged and we use Vec<RedisString> for the args.

matobet avatar Dec 12 '21 00:12 matobet