Java Project configuration Redis

Source: Internet
Author: User
Tags set set

成功配置redis之后,便来学习使用redis。首先了解下redis的数据类型。
Data types for Redis

Redis supports five types of data: string (String), hash (hash), list, set (set), and Zset (sorted set: Ordered set).

String

The string is the most basic type of redis, and you can understand it as a type that is identical to memcached, a key that corresponds to a value.
The string type is binary safe. This means that a Redis string can contain any data. For example, JPG images or serialized objects.
The string type is the most basic data type of Redis, and a key can store up to 512MB.
Cases:

Hash

A Redis hash is a set of key-name pairs.
Redis Hash is a string-type field and value mapping table, and hash is particularly useful for storing objects.
Hmset Set Value
Hgetall value

List

The Redis list is a simple list of strings, sorted by insertion order. You can add an element to the head of the list (to the left) or to the tail (to the right).
Lpush Insertion
Lrange View

Set

An unordered collection of Redis's set.
The collection is implemented by a hash table, so the complexity of adding, deleting, and finding is O (1).
Sadd command
Adds a string element to the set set of key corresponding to successfully returning 1 if the element has returned in the collection 0,key the corresponding set does not have a return error.
Smembers View

Zset

Redis's Zset (sorted set) is an ordered collection of string types.
Redis Zset and set are also collections of string-type elements and do not allow duplicate members.
The difference is that each element is associated with a double-type fraction. Redis is a small-to-large ordering of the members in a collection by fractions.
Zset members are unique, but fractions (score) can be duplicated.
Zadd command
Adds an element to the collection, the element exists in the collection, and updates the corresponding score
Zrangebyscore View

了解了redis的基本数据类型之后,于是便可以在java项目中使用redis。
To download the Redis driver package in Java using Redis:

https://mvnrepository.com/artifact/redis.clients/jedis/2.9.0
Adding a Jedis.jar package to a Java project

Test Service Connection

Introduction Rack Package: Import Redis.clients.jedis.Jedis;
To test service status with the ping command

Redis Storage String Example

Use set and get to test

Redis Storage List Sample

Redis Storage Set Example

Output All

Source: https://www.cnblogs.com/xuwujing/p/7536707.html

Java Project configuration Redis

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.