Reputation: 358
I know redis does not allow nested structures but here is what I do:
add value pairs into a set as string : SADD myset %lu:%ld
then read them with (after a SMEMBERS myset):
sscanf(conn->reply->element[i]->str,"%lu:%ld",&myfirstvalue,&mysecondvalue );
this works but I realized keeping values as string in a set uses too much memory.
Is there a better way to store this unsigned long long , long long pair in a set ?
Upvotes: 1
Views: 303
Reputation: 393
What about save as raw bytes? Both unsigned long long and long long are 64bits, which is 8 bytes long. So with 16bytes, you should be able to save any pair. Converting the 16bytes to a unsigned char array would serve your purpose.
Note that this would introduce some performance hit as after you "encode" before add value pairs, you'll need to "decode" when retrieving it. As you are doing so with saved string, I doubt the suggested solution would be slower, if not faster in fact.
Upvotes: 0