The basic use redis

1.Redis supports a total of five data types:

Are: String (String), hash / hash / dictionary (Hash), list (List), the set (Set), ordered collection (sorted set).

2.java use can be injected

RedisTemplate @Autowired <String, String> redisTemplate; 

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

here cite content experts
String:
1.redisTemplate.opsForValue () SET (Key, value));. 
. 2.redisTemplate.opsForValue () GET (Key));
. 3.redisTemplate.opsForValue () GET (Key, Start, End);
4.redisTemplate .opsForValue () getAndSet (Key,. value);
5.redisTemplate.opsForValue () GETBIT (Key, offset);. // below the comment
6.redisTemplate.opsForValue () MultiGet (Keys);.
7.redisTemplate.opsForValue ( ) .setBit (key, offset, value ); // comment below
8.redisTemplate.opsForValue () set (K key, V value, long timeout, TimeUnit unit);. // TimeUnit type is timeout, such as milliseconds \ seconds \ days, etc.
9.redisTemplate.opsForValue () setIfAbsent (Key, value);.
10.redisTemplate.opsForValue () SET (Key K, V value, Long offset);. // java bloggers herein without making verification
11. . redisTemplate.opsForValue () size (key) );
12.redisTemplate.opsForValue().multiGet(Collection<K> keys);
13.redisTemplate.opsForValue().multiSetIfAbsent(Map<? extends K, ? extends V> m);
14.同8
15\16\17\18\19.redisTemplate.opsForValue().increment(K key, long delta);或.increment(K key, double delta);
20.redisTemplate.opsForValue().append(key, value);//在key键对应值的右面追加值value
21.del key------21.redisTemplate.opsForValue().getOperations().delete(key);
Hash:
1.redisTemplate.opsForHash () delete (H key, Object ... hashKeys);. // ... you can pass key representation of multiple map with separated. Or pass an array value 
2.redisTemplate.opsForHash () hasKey (Key, hashKey);.
3.redisTemplate.opsForHash () GET (Key, hashKey);.
. 4.redisTemplate.opsForHash () entries It (Key); // returns a collection of map
5,6.redisTemplate.opsForHash () increment (H key, HK hashKey, long delta);. // or INCREMENT (H Key, HK hashKey, Double Delta) ;;
7.redisTemplate.opsForHash () Keys. (key); // return key map collection of the set
8.redisTemplate.opsForHash () size (Key);.
. 9.redisTemplate.opsForHash () Multiget (H Key, collection <HK> HASHKEYS);
10.redisTemplate.opsForHash () .putAll (H Key, the Map m <the extends HK, the extends the HV??>);
. 11.redisTemplate.opsForHash () PUT (Key, hashKey, value);
12.redisTemplate.opsForHash().putIfAbsent(key, hashKey, value);
13.redisTemplate.opsForHash().values(key);//返回map中的value集合List;
List: 

. RedisTemplate.opsForList () leftPush (Key, value); // save from left to right push
redisTemplate.opsForList () leftPop (key); // left out of the stack.
RedisTemplate.opsForList () size (Key. ); // Force / stack length
redisTemplate.opsForList () range (key, start , end);. // range search, returns List
redisTemplate.opsForList () remove (key, I, value);. // key removal a median value of i, returns the number of deleted; 0 if this element is not returned
redisTemplate.opsForList () index (key, index );. // retrieve
. redisTemplate.opsForList () set (key, index, value ); // assignment
redisTemplate.opsForList () trim (key, start , end);. // cut, void, delete all elements except [start, end] of 
. redisTemplate.opsForList () rightPopAndLeftPush (String sourceKey , String destinationKey ); // will be a key source of value to the right of the queue to delete, and then inserted into the left side of the key target queue, the return value
Note: To cache object must implement Serializable interface because Spring will be subject to serialize and then into Redis, otherwise reported abnormal nested exception is java.lang.IllegalArgumentException: DefaultSerializer requires a Serializable ...... // ;; /
Set:
redisTemplate.opsForValue (). getAndSet (key, value) 

finally posted a website, command operations
https://www.yiibai.com/redis/sets_sadd.html
 

 

Guess you like

Origin www.cnblogs.com/guagua-join-1/p/10965912.html
Recommended