Home > Database > Redis > body text

What are the usages of the five types in redis

王林
Release: 2021-02-02 09:30:30
forward
1969 people have browsed it

What are the usages of the five types in redis

First of all, let’s introduce the five types in redis:

String, Hash/Hash/Dictionary (Hash), List ), collection (Set), ordered set (sorted set).

Controller:@Resource RedisTemplate redisTemplate;

Summary:

redisTemplate.opsForValue();//Operation string
redisTemplate .opsForHash();//Operation hash
redisTemplate.opsForList();//Operation list
redisTemplate.opsForSet();//Operation set
redisTemplate.opsForZSet();//Operation 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);//Comments below
6.redisTemplate.opsForValue().multiGet(keys);
7.redisTemplate.opsForValue().setBit(key, offset, value);//Comments 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 did not do java verification here
11.redisTemplate.opsForValue(). size(key));
12.redisTemplate.opsForValue().multiGet(Collection 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 value to the right of the value corresponding to the key key
You can see that there is no deletion method. The blogger has studied it and it can be like this: 21. del key------21.redisTemplate.opsForValue().getOperations().delete(key);

What are the usages of the five types in redis

##.setBit(key, offset, value): The ascii code corresponding to the value corresponding to the key key changes to value at the offset position (counting from left to right). (Thanks to @reference article for helping me understand). Since binary only has 0 and 1, value here Only 0 and 1 can be taken, as shown in the figure, other values ​​are out of range

.getBit(key, offset): Get the offset value of the ASCII code corresponding to the key.
@ascii code comparison table

What are the usages of the five types in redis

Hash:

1.redisTemplate.opsForHash().delete(H key, Object... hashKeys);//... means multiple maps can be passed in The keys are separated by . Or use an array to pass the value
2.redisTemplate.opsForHash().hasKey(key, hashKey);
3.redisTemplate.opsForHash().get(key, hashKey);
4.redisTemplate.opsForHash( ).entries(key);//Return map collection
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 the map key collection Set
8.redisTemplate.opsForHash().size(key);
9.redisTemplate. opsForHash().multiGet(H key, Collection 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 value collection List in the map;

What are the usages of the five types in redis

List:


redisTemplate.opsForList().leftPush(key, value);//From Store and push the stack from left to right
redisTemplate.opsForList().leftPop(key);//Pop the stack from the left
redisTemplate.opsForList().size(key);//Team/stack length
redisTemplate .opsForList().range(key, start, end);//Range retrieval, return List
redisTemplate.opsForList().remove(key, i, value);//Remove the i whose value is value in key , returns the number of deleted elements; if there is no such element, returns 0
redisTemplate.opsForList().index(key, index);//Retrieval
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 source key queue, then insert it into the left side of the target key queue, and return this value
Note: The object to be cached must implement the Serializable interface, because Spring will serialize the object first and then store it in Redis, otherwise a nested exception is java.lang.IllegalArgumentException: DefaultSerializer requires a Serializable……//;;/

What are the usages of the five types in redis

Set:
redisTemplate.opsForValue().getAndSet(key, value)
What are the usages of the five types in redis

##Related recommendations:

redis database tutorial

The above is the detailed content of What are the usages of the five types in redis. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template