Closed erf closed 3 years ago
This is logic I don't want in this package. Redis always returns a string as the result of a get
command and it is not the responsibility of this package to interpret this string. And what if you use a Date
or bool
as type parameter?
I suggest to write an extension for you specific use case.
I understand if you don't want to do this, but you already do this with e.g. Command.dbsize (you have helper functions to parse spesific types ) ? Could you not have a similar generic function for getting a any key with a given type and then just throw an exception if the type wasn't supported?
I just made a test with a bool
and a Date
now, and i think it should be fine to parse them from a string to their correct type.
Future<void> testBoolean() async {
final server = await connectSocket('localhost');
final client = RespClient(server);
final commands = RespCommands(client);
final result = await commands.set('someBool', true);
final value = await commands.get('someBool');
print(value);
final boolValue = value == 'true';
print(boolValue);
}
Future<void> testDate() async {
final server = await connectSocket('localhost');
final client = RespClient(server);
final commands = RespCommands(client);
final result = await commands.set('someDate', DateTime.now());
final value = await commands.get('someDate');
print(value);
final dateValue = DateTime.parse(value);
print(dateValue);
}
But i'm thinking primarily of the basic types. I could help with a PR, if interested in this.
Could also just make some helper functions for spesific types like: getInt
, getBool
, etc.
Sorry, I really don't want that kind of logic in this package. But thanks for your offer to contribute.
Ok. No problem :)
get
now always return a string, I think it would be valuable to use generics to specify which type you'd like to return.E.g.
Would return an
int
.In the
dartis
package they did this:but not sure if the key here would be anything else than String..