0

This is about RedisClient, which is a C++ client.

I know that you can't store integers in Redis (that are internally converted).

RedisSyncClient::command itself does not support integers as RedisBuffer can't be initialized with int, so:

redis->command("SET", "mykey", 1);

won't compile (you need to add numbers as string).

However RedisValue can be initialized with int (not sure when it is used) and it contains a public "toInt()" method:

redis->command("SET", "mykey", "1"); result = redis->command("GET", "mykey"); cout << "INT: " << result.toInt() << " , STR: " << result.toString() << endl;

INT: 0 , STR : 1

At first I thought that internally strings were being converted to int, but it always return "0". Testing "RedisValue.isInt()" it seems it fails to recognize numbers as it returns "false".

  • What is the intention of "toInt()" if numbers are only seen (by this library) as strings?
  • Am I using it incorrectly?
  • Is this a work-in-progress feature?
4

1 回答 1

1

现在事情对我来说很有意义......似乎它可以用于redis响应,例如:

result = redis->command("EXISTS", "mykey"); cout << "? " << result.isInt() << endl;

? 1

在这种情况下, toInt() 按预期工作。

我只需要查看 redis 文档并查看哪些命令返回 int。它不是为与“正常”值一起使用而设计的。

(很抱歉回答我自己的问题,如果它们涵盖了我错过的东西,我很乐意接受其他答案)。

于 2015-10-09T07:40:27.900 回答