Java redis operation details
1. Introduction
Redis is an open source (BSD licensed) in memory key value storage system, which can be used as database, cache and message middleware.
2. Operation on key
First, establish the connection jedis jedis = new jedis ("127.0.0.1", 6379), and then operate on string, set, Zset and hash.
3. String data type
The Java operation code is:
4. List data type
Lists in redis is not an array but a linked list in the underlying implementation.
A series of operations: rpush, lpush, llen, lrange, lpop and rpop.
We can use lpush to insert a new element on the left side of lists, rpush to insert a new element on the right side of lists, and lrange to specify a range from lists to extract elements.
The Java operation code is:
5. Set type
The redis collection is an unordered collection. The elements in the collection have no order. A series of operations: Sadd, SREM, sismember, smembers and Sunion Set related operations are also very rich, such as adding new elements, deleting existing elements, taking intersection sets, taking union sets, taking difference sets, etc.
Java operation code:
6. Sorted sets type
We all call the ordered sets in redis zsets
The Java operation code is:
7. Hash type
Hashes stores the mapping between strings and string values
Java operation code:
8. Services
Transaction refers to "a complete action, either all performed or nothing done". Before talking about redis transaction processing, I'd like to introduce four redis instructions, namely multi, exec, discard and watch. These four instructions form the basis of redis transaction processing.
1. Multi is used to assemble a transaction; 2. Exec is used to execute a transaction; 3. Discard is used to cancel a transaction; 4. Watch is used to monitor some keys. Once these keys are changed before the transaction is executed, the execution of the transaction will be cancelled.
The Java operation code is:
Pipeline operation java code:
summary
The above is all about the detailed introduction of Java operation redis in this article. I hope it will be helpful to you. If there are deficiencies, please leave a message to point out. Thank you for your support.