Five types of Redis: String, String, Hash, Dictionary, List, Set, and Sorted Set
Controller: @Resource RedisTemplate <String, String> redisTemplate;
In summary:
redisTemplate.opsForValue (); // Operation string
redisTemplate.opsForHash (); // Hash operation
redisTemplate.opsForList (); // operation list
redisTemplate.opsForSet (); // Set operation
redisTemplate.opsForZSet (); // Operated ordered set
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); // Comment below
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 is the type of timeout, such as milliseconds \ seconds \ days, etc.
9.redisTemplate.opsForValue (). SetIfAbsent (key, value);
10.redisTemplate.opsForValue (). Set (K key, V value, long offset); // The blogger has not done java verification here
11.redisTemplate.opsForValue (). Size (key));
12.redisTemplate.opsForValue (). MultiGet (Collection <K> keys);
13.redisTemplate.opsForValue (). MultiSetIfAbsent (Map <? Extends K,? Extends V> m);
14.Same as 8
15 \ 16 \ 17 \ 18 \ 19.redisTemplate.opsForValue (). Increment (K key, long delta); or .increment (K key, double delta);
20.redisTemplate.opsForValue (). Append (key, value); // Append the value to the right of the corresponding value of the key key
You can see that there are no methods such as deletion. The blogger researched it a bit like this: 21.del key ------ 21.redisTemplate.opsForValue (). GetOperations (). Delete (key);
No. Command Description
1 SET key value This command sets the value of the specified key.
2 GET key Get the value of the specified key.
3 GETRANGE key start end Gets a substring of the string stored on the key.
4 GETSET key value Sets the string value of the key and returns its old value.
5 GETBIT key offset Returns the bit value at the offset in the string value stored at the key.
6 MGET key1 [key2 ..] Get the value of all given keys
7 SETBIT key offset value Sets or clears the bit at the offset in the string value stored on the key
8 SETEX key seconds value
9 SETNX key value Set the value of the key, only if the key does not exist
10 SETRANGE key offset value Overwrite part of the string at the key starting at the specified offset
11 STRLEN key Get the length of the value stored in the key
12 MSET key value [key value…] Set the values of multiple keys individually
13 MSETNX key value [key value…] Set the values of multiple keys separately, only if the key does not exist
14 PSETEX key milliseconds value Sets the value and expiration time of the key (in milliseconds)
15 INCR key Increase the integer value of the key by 1
16 INCRBY key increment increases the integer value of the key by the given value
17 INCRBYFLOAT key increment Increase the floating point value of the key by the given value
18 DECR key Decrements the integer value of the key by 1.
19 DECRBY key decrement decreases the integer value of the key by the given value
20 APPEND key value Appends the specified value to the key
.setBit (key, offset, value): The ascii code corresponding to the value corresponding to the key key becomes the value at the offset position (counting from left to right). Since the binary is only 0 and 1, the value here can only take 0 and 1, as shown in the figure, other values are out of range
.getBit (key, offset): Get the bit value of the ascii code corresponding to the key at offset.
@ascii code comparison table
Hash:
1.redisTemplate.opsForHash (). Delete (H key, Object ... hashKeys); // ... means that multiple map keys can be passed in, separated by. Or pass an array
2.redisTemplate.opsForHash (). HasKey (key, hashKey);
3.redisTemplate.opsForHash (). Get (key, hashKey);
4.redisTemplate.opsForHash (). Entries (key); // Return map collection
5.redisTemplate.opsForHash (). Increment (H key, HK hashKey, long delta); / or increment (H key, HK hashKey, double delta);
7.redisTemplate.opsForHash (). Keys (key); // Returns the key set of the map
8.redisTemplate.opsForHash (). Size (key);
9.redisTemplate.opsForHash (). MultiGet (H key, Collection <HK> hashKeys);
10.redisTemplate.opsForHash (). PutAll (H key, Map <? Extends HK,? Extends HV> m);
11.redisTemplate.opsForHash (). Put (key, hashKey, value);
12.redisTemplate.opsForHash (). PutIfAbsent (key, hashKey, value);
13.redisTemplate.opsForHash (). Values (key); // Return the List of value set in map
No. Command Description
1 HDEL key field2 [field2] Delete one or more hash fields.
2 HEXISTS key field Determines whether a hash field exists.
3 HGET key field Gets the value of the hash field stored in the specified key.
4 HGETALL key Get all fields and values stored in the hash of the specified key
5 HINCRBY key field increment increases the integer value of the hash field by the given number
6 HINCRBYFLOAT key field increment Increase the floating point value of the hash field by the given value
7 HKEYS key Get all fields in the hash
8 HLEN key to get the number of fields in the hash
9 HMGET key field1 [field2] Get the value of all given hash fields
10 HMSET key field1 value1 [field2 value2] Set their values for multiple hash fields individually
11 HSET key field value Set the string value of the hash field
12 HSETNX key field value Set the value of the hash field only if the field does not exist
13 HVALS key Get all values in the hash
List:
redisTemplate.opsForList (). leftPush (key, value); // Press and hold the stack from left to right
redisTemplate.opsForList (). leftPop (key); // Put the stack from the left
redisTemplate.opsForList (). size (key); // team / stack length
redisTemplate.opsForList (). range (key, start, end); // Range search, return List
redisTemplate.opsForList (). remove (key, i, value); // Remove the i value of key and return the number of deletions; if there is no such element, return 0
redisTemplate.opsForList (). index (key, index); // Retrieve
redisTemplate.opsForList (). set (key, index, value); // assignment
redisTemplate.opsForList (). trim (key, start, end); // Crop, void, delete all elements except [start, end]
redisTemplate.opsForList (). rightPopAndLeftPush (String sourceKey, String destinationKey); // Delete a value on the right side of the queue of the source key, and then insert the left side of the queue of the target key, and return this value
Note: The object to be cached must implement the Serializable interface, because Spring will serialize the object before storing it in Redis, otherwise it will report a nested exception is java.lang.IllegalArgumentException: DefaultSerializer requires a Serializable ...
No. Command Description
1 BLPOP key1 [key2] timeout deletes and gets the first element in the list, or blocks until an element is available
2
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.