I'm not sure if you really save space, because afaik, sometimes redis
interpretes strings as doubles (i.e. when doing incrBy). But chances
are good, you are right.
For each command, you have two versions, a String and one byte[]
variant. If you feed jedis with byte[] data, you use the byte[]
variant, and in that case, SafeEncoder is not used.
All depends how you convert int/double to/from byte[].
You can test this, independently of redis.
Just encode your int / double to byte[]s. Print out their respective sizes. I.e.
int key = 5; double value =6;
byte[] keyBA = Converter.toBA(key);
System.out.println("Converter encoded key length: " + keyBA.lenght);
byte[] valueBA = ...
Then create the byte[] representation using SafeEncoder:
byte[] keySE = SafeEncoder.encode(String.valueOf(key))
System.out.println("SafeENcoder encoded key length: " + keySE.lenght);
byte[] valueSE = ...
you should normally find that SafeEncoders byte[] are longer, but you
will probably find that there is something wrong with your way of
encoding int/doubles to byte[].
If not, I'm not sure....
Try with this:
public static int byteArrayToInt(byte[] b)
{
int value = 0;
for (int i = 0; i < 4; i++) {
value = (value << 8) | (b[i] & 0xFF);
}
return value;
}
public static byte[] intToByteArray(int a)
{
byte[] ret = new byte[4];
ret[3] = (byte) (a & 0xFF);
ret[2] = (byte) ((a >> 8) & 0xFF);
ret[1] = (byte) ((a >> 16) & 0xFF);
ret[0] = (byte) ((a >> 24) & 0xFF);
return ret;
}
hope that helps,
Ingvar
( and please report back what you find, that would be interesting for all)
2011/10/5 Ali <sale...@gmail.com>:
I speculate the used_memory is not purely taken by actual data, but
also some redis housekeeping. I also have 80MB of redis database with
much less data. I suspect that the field used_memory_human might be
the value.
There is also the dbSize method from jedis.
It would be interesting to know: What are the values when you use
SafeEncoder / Strings instead of Bytes?
Ingvar
2011/10/6 Ali <sale...@gmail.com>: