search
HomeDatabaseRedisWhat are the usages of the five types in redis

What are the usages of the five types in redis

Feb 02, 2021 am 09:30 AM
redisusagetype

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!

Statement
This article is reproduced at:博客园. If there is any infringement, please contact admin@php.cn delete
Redis: Exploring Its Features and FunctionalityRedis: Exploring Its Features and FunctionalityApr 19, 2025 am 12:04 AM

Redis stands out because of its high speed, versatility and rich data structure. 1) Redis supports data structures such as strings, lists, collections, hashs and ordered collections. 2) It stores data through memory and supports RDB and AOF persistence. 3) Starting from Redis 6.0, multi-threaded I/O operations have been introduced, which has improved performance in high concurrency scenarios.

Is Redis a SQL or NoSQL Database? The Answer ExplainedIs Redis a SQL or NoSQL Database? The Answer ExplainedApr 18, 2025 am 12:11 AM

RedisisclassifiedasaNoSQLdatabasebecauseitusesakey-valuedatamodelinsteadofthetraditionalrelationaldatabasemodel.Itoffersspeedandflexibility,makingitidealforreal-timeapplicationsandcaching,butitmaynotbesuitableforscenariosrequiringstrictdataintegrityo

Redis: Improving Application Performance and ScalabilityRedis: Improving Application Performance and ScalabilityApr 17, 2025 am 12:16 AM

Redis improves application performance and scalability by caching data, implementing distributed locking and data persistence. 1) Cache data: Use Redis to cache frequently accessed data to improve data access speed. 2) Distributed lock: Use Redis to implement distributed locks to ensure the security of operation in a distributed environment. 3) Data persistence: Ensure data security through RDB and AOF mechanisms to prevent data loss.

Redis: Exploring Its Data Model and StructureRedis: Exploring Its Data Model and StructureApr 16, 2025 am 12:09 AM

Redis's data model and structure include five main types: 1. String: used to store text or binary data, and supports atomic operations. 2. List: Ordered elements collection, suitable for queues and stacks. 3. Set: Unordered unique elements set, supporting set operation. 4. Ordered Set (SortedSet): A unique set of elements with scores, suitable for rankings. 5. Hash table (Hash): a collection of key-value pairs, suitable for storing objects.

Redis: Classifying Its Database ApproachRedis: Classifying Its Database ApproachApr 15, 2025 am 12:06 AM

Redis's database methods include in-memory databases and key-value storage. 1) Redis stores data in memory, and reads and writes fast. 2) It uses key-value pairs to store data, supports complex data structures such as lists, collections, hash tables and ordered collections, suitable for caches and NoSQL databases.

Why Use Redis? Benefits and AdvantagesWhy Use Redis? Benefits and AdvantagesApr 14, 2025 am 12:07 AM

Redis is a powerful database solution because it provides fast performance, rich data structures, high availability and scalability, persistence capabilities, and a wide range of ecosystem support. 1) Extremely fast performance: Redis's data is stored in memory and has extremely fast read and write speeds, suitable for high concurrency and low latency applications. 2) Rich data structure: supports multiple data types, such as lists, collections, etc., which are suitable for a variety of scenarios. 3) High availability and scalability: supports master-slave replication and cluster mode to achieve high availability and horizontal scalability. 4) Persistence and data security: Data persistence is achieved through RDB and AOF to ensure data integrity and reliability. 5) Wide ecosystem and community support: with a huge ecosystem and active community,

Understanding NoSQL: Key Features of RedisUnderstanding NoSQL: Key Features of RedisApr 13, 2025 am 12:17 AM

Key features of Redis include speed, flexibility and rich data structure support. 1) Speed: Redis is an in-memory database, and read and write operations are almost instantaneous, suitable for cache and session management. 2) Flexibility: Supports multiple data structures, such as strings, lists, collections, etc., which are suitable for complex data processing. 3) Data structure support: provides strings, lists, collections, hash tables, etc., which are suitable for different business needs.

Redis: Identifying Its Primary FunctionRedis: Identifying Its Primary FunctionApr 12, 2025 am 12:01 AM

The core function of Redis is a high-performance in-memory data storage and processing system. 1) High-speed data access: Redis stores data in memory and provides microsecond-level read and write speed. 2) Rich data structure: supports strings, lists, collections, etc., and adapts to a variety of application scenarios. 3) Persistence: Persist data to disk through RDB and AOF. 4) Publish subscription: Can be used in message queues or real-time communication systems.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)