redis / hiredis

Minimalistic C client for Redis >= 1.2
BSD 3-Clause "New" or "Revised" License
6.24k stars 1.81k forks source link

How use %c in format string on redisCommand? #1069

Open FAYWORD opened 2 years ago

FAYWORD commented 2 years ago

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 commented 2 years ago

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)

michael-grunder commented 2 years ago

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.

FAYWORD commented 2 years ago

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