Java development of Redis

Brief introduction

Redis is completely free open source, BSD comply with the agreement, is a high-performance key - value database

Redis and other key - value caching products have the following characteristics:

  • Redis supports data persistence, data in memory can be saved to disk, reboot to load when you can be reused.

  • Redis supports not only simple key - value data types, while also providing storage list, set, zset, hash and other data structures

  • Data backup slave mode - Redis data backup support, that master

advantage

  • High performance - Redis reading speed is 110 000 times / s, write speed is 81000 times / s.

  • Rich data types - Redis supports binary case Strings, Lists, Hashes, Sets and Ordered Sets the data type of the operation.

  • Atomic - Redis All operations are atomic, meaning that either succeed or fail completely executed execution. It is a single atomic operation. A plurality of operation also supports transaction, i.e. atomicity, and EXEC instructions by MULTI wrap.

  • Other features - Redis also supports publish / subscribe notification, key expiration and other characteristics.

Data types, data structures,

Redis supports five data types: string (string), hash (hash), list (list), set (collection), zset (sorted set: an ordered collection)

    Supports 8 data structure: int, raw, embstr, ziplist, linkedlist, hashtable, intset, skiplist

Relationship storage type and data structure

  Redis Key and Value in the skin is an example of redisObject (five kinds of storage bridges and Different types of data structures), so that the structure has a so-called "type", that is, for each ValueType ValueType type redisObject.;

  redisObject supports at least two different data structures of the underlying implementation. In order to respond to different application scenarios, such as the operating efficiency Redis, memory usage or the like.

  The main field has redisObject encoding (data structure) type (storage type) * ptr (pointer points to the underlying data structure implemented) the refcount (reference count) LRU (was last accessed time program command)

  ps: See Redis underlying data structure implemented

scenes to be used

 

RedisTemplate

And 5 kinds of basic information conceptual data structures Redis substantially introduction to this, in conjunction with the following RedisTemplate Spring package to explain the data structure of these five

5 kinds of operations data structure

redisTemplate.opsForValue (); // operating string 
redisTemplate.opsForHash (); // operating the hash 
redisTemplate.opsForList (); // Operation List 
redisTemplate.opsForSet (); // operating SET 
redisTemplate.opsForZSet (); // operations ordered set

For specific operations of the five types of data structures can view its source code (the source code is explained in detail), of course, also read "How to use Redis RedisTemplate access the data structure"

Serialization Strategy

Here, I need to explain, the problem is often encountered in the development - a sequence of strategic issues

  spring-data-redis in redisTemplate default JDK serialization strategy, there will be two questions:

  • When using redis-cli view the data, carry a lot of character and difficult to see
  • JDK Serializer costs too much resources

  Of course, the sequence strategy can be customized, spring-data-redis has the following sequence of several classes:

  • GenericToStringSerializer: Any object can be serialized into a string and generalization
  • Jackson2JsonRedisSerializer: virtually identical with JacksonJsonRedisSerializer
  • JacksonJsonRedisSerializer: Serialized Object An object is a string json
  • JdkSerializationRedisSerializer: serialized java object (object to be serialized must implement Serializable)
  • StringRedisSerializer: simple string sequence of
  • GenericToStringSerializer: Similar string serialization StringRedisSerializer
  • GenericJackson2JsonRedisSerializer: Similar Jackson2JsonRedisSerializer, but without the use of a particular class constructor a reference sequence of the above, the custom sequence of categories;   recommended

  StringRedisTemplate the way, tell us about it, this stock is a subclass of RedisTemplate default uses a String serialization strategy, save the key and value are based on the sequence of this policy saved.

  

 

 

 

 

Guess you like

Origin www.cnblogs.com/JackpotHan/p/12175137.html