hiredis icon indicating copy to clipboard operation
hiredis copied to clipboard

How use %c in format string on redisCommand?

Open FAYWORD opened this issue 2 years ago • 3 comments

If i use %c in format string then command return NULL reply. Example command (SET Test:1 a): reply = redisCommand(conn,"SET Test:1 %s", "a"); // this work (Command OK) reply = redisCommand(conn,"SET Test:1 a"); // this work (Command OK) reply = redisCommand(conn,"SET Test:1 %c", 'a'); // this d'nt work (reply == NULL) reply = redisCommand(conn,"SET T%cst:1 a", 'e'); // this d'nt work (reply == NULL)

This problem also exists in redisAppendCommand, redisvAppendCommand and etc

FAYWORD avatar Jun 16 '22 07:06 FAYWORD

I found another problem (* - d'nt work with format string) reply = redisCommand(conn,"SET Test:1 %.*s", 2, "qwerty"); //this d'nt work (reply == NULL) reply = redisCommand(conn,"SET Test:1 %.2s", "qwerty"); //this d'nt work (reply == NULL) reply = redisCommand(conn,"SET Test:1 %.5d", 1); // this work (Command OK) reply = redisCommand(conn,"SET Test:1 %5d", 1); // this work (Command OK) reply = redisCommand(conn,"SET Test:1 %.*d", 5, 1); //this d'nt work (reply == NULL)

FAYWORD avatar Jun 16 '22 12:06 FAYWORD

Hi, thanks for the report.

I'm honestly not sure if we want/need to add the * style format specifiers as Hiredis doesn't aim to replicate full printf functionally, but just a small subset that is typically useful for communicating with Redis.

michael-grunder avatar Aug 29 '22 16:08 michael-grunder

Well, I needed to insert only part of the string (up to a certain character). Without this functionality, you will need to compose a new string

FAYWORD avatar Sep 14 '22 13:09 FAYWORD