English 中文(简体)
珠宝库 这一问题是否来自红色或杰迪?
原标题:Jedis Storage Confusion, Is this issue from Redis or Jedis?
  • 时间:2011-10-06 07:30:39
  •  标签:
  • redis
  • jedis

下面的java法典将100万英亩的奶制品重新分类。

 public class JedisInsertion { 
        public static byte[] fromInt(int v) { 
                return ByteBuffer.allocate(4).putInt(v).array(); 
        } 
        public static void main(String args[]) { 
                Jedis j = new Jedis("localhost"); 
                for (int i = 0;i<1000*1000;i++){ 
                   j.set(fromInt(i),fromInt(i)); 
                } 
        } 
} 

这里,信息产出重新分类

... 
used_memory:89319664 
arch_bits:64 
... 

89319664 意味着每张关键价值奶粉中约有89 tes。

我期望的是大约8种甲基溴(关键+4的 by价为4种)。

I also compiled redis in 32 bit mode (still running the test on a 64 bit machine).

The results for 32-bit version of redis:

used_memory: 68831664 => 68 bytes per key value pair.

Both results are several times higher than what I was expecting.

When I look at redis using CLI, I see a typical key would look like this: "x00x00xc2xff"

I appreciate your feedback

PS - I am using Redis 2.2.14 and Jedis 2.0 on a 64-bit machine

PSS - I also tried to store all the values in one hash as suggested by one of the comments, here is the code:

for (int i = 0;i<1000*1000;i++){
    j.hset("my-hash".getBytes(),fromInt(i),fromInt(i));
}

结果是:

used_memory_rss:84676608 (for 32bit build)
used_memory:105319712 (for 64bit build)

当我使用单一散射器时,结果更糟。

问题回答

每一关键/价值类型68的对应数字是正确的。 Redis公司内部并不把物品作为简单的文字文件存放,否则,它就无法迅速加以研究,无法有不同类型的物体等等。 与此相关的间接费用。 在Redis.io的文件中,有关这方面的资料越来越多。

The fact that your key is a non-readable binary value is a decision made by Jedis, since Redis can use pretty much anything as a key.

Redis keys have expirations and other meta-data that takes up additional space. If you are concerned about space, consider storing all your values within a single Redis hash. There is significantly less overhead for key/value pairs within a hash than for standard key/value pairs.

http://redis.io/topics/memory-optimization





相关问题
How do you mix SQL DB vs. Key-Value store (i.e. Redis)

I m reviewing my code and realize I spend a tremendous amount of time taking rows from a database, formatting as XML, AJAX GET to browser, and then converting back into a hashed javascript object ...

Predis sharding (consistent hashing)

Predis claim to have Client-side sharding (support for consistent hashing of keys). http://github.com/nrk/predis I can do sharding using connect to an array of profiles (nodes) but it isn t ...

key value stores for extendable objects

http://www.infoq.com/presentations/newport-evolving-key-value-programming-model is a video about KV stores, and the whole premise is that redis promotes a column-based style for storing the attributes ...

nginx/redis and handling tracking params in url

I am using nginx and redis in my website. For several items on my site, I want to add tracking params to their urls so that when a user clicks on an item, I can collect statistics of user usage apart ...

热门标签