9 Key Points for optimizing Redis memory
9 Key Points for optimizing Redis memory
1. Pay attention to the special encoding settings for small aggregate data types in redis. conf:
Hash-max-zipmap-entries 64 (hash-max-ziplist-entries for Redis >=2.6)
Hash-max-zipmap-value 512 (hash-max-ziplist-value for Redis> = 2.6)
List-max-ziplist-entries 512
List-max-ziplist-value 64
Zset-max-ziplist-entries 128
Zset-max-ziplist-value 64
Set-max-intset-entries 512
2. Use a 32-bit instance to limit the memory to 4 GB, but their RDB and AOF files are compatible with 32-bit and 64-bit switchover.
3. Bit-level operations and byte-level operations are used to reduce unnecessary memory usage.
Bit-level operations: GETRANGE, SETRANGE, GETBIT and SETBIT
Byte-level operation: GETRANGE and SETRANGE
4. Use hashes hash as much as possible, because small Hashes will be encoded into a very small space.
5. Use hash to abstract the memory usage efficiency at the top of Redis in normal key-value storage.
6. Memory Allocation:
If maxmemory is not set, Redis will continue to allocate memory because it thinks it is appropriate, so it can (gradually) eat all your available memory. Therefore, we recommend that you configure some restrictions. You may also need to set the maxmemory policy to noeviction (this is not the default value in some older versions of Redis ).
This causes Redis to return incorrectly written commands with insufficient memory. If it reaches the limit-This in turn may lead to application errors, but will not cause the entire machine to die due to memory hunger.
In addition, the default expiration Policy of redis is volatile-lru. Setting Method
Config set maxmemory-policy volatile-lru
Maxmemory-policy six methods
Volatile-lru: Only LRU (default) is performed on keys with an expiration time set)
Allkeys-lru: deletes infrequently used keys from all keys.
Volatile-random: random deletion of expired keys
Allkeys-random: random Deletion
Volatile-ttl: delete expired
Noeviction: never expires. An error is returned.
Maxmemory-samples 3 indicates that three keys will be randomly extracted during each elimination to eliminate the least frequently used keys (default option)
7. Compress Your data before saving it to Redis.
8. Try to use a short key (Keys)
9. Use Hashes values for storage without additional data element reference:
Http://redis.io/topics/memory-optimization
Http://baike.baidu.com/link? Url = eb4_JlCybpp1AuRHHBd8GmZdftrAUa-FSc_Y6hFujHejnGb_AHLxteQRacXonNYoaJmbigEyb3yBe_z67gzI9a
Http://labs.octivi.com/how-we-cut-down-memory-usage-by-82/