NoSQL Redis (ii) (Java)

Source: Internet
Author: User
Tags data structures message queue

The first time I heard about Redis, I was looking at a rookie tutorial: http://www.runoob.com/redis/redis-intro.html

Later, the habit is to read the blog, know these. Then I will come here to give you a little bit more:

I. Introduction to REDIS:

Redis (REmote DIctionary Server) is an open-source persistent database storage System for local Key-value key-value pairs, commonly used as a cache or message queue. Support for multiple data Structures: string (string), list (linked list), set (set), Zset (ordered array), hash (hash type), these data types support Push/pop, Add/remove, and intersection sets and differences and richer operations, And all of these operations are atomic in nature. Redis supports sorting in a variety of different ways. To ensure efficiency, the data is cached in memory , and it can periodically write updated data to disk or write modifications to the appended record file.

Second, why to use NoSQL

NoSQL is stored in Key-value mode (like map, JSON), unlike traditional relational databases, and does not necessarily follow some of the basic requirements of traditional databases, such as following the SQL standard (SELECT, delete, update, INSERT, These operational statements are not in NoSQL, the acid standard, the table structure, and so on. These databases mainly have the following characteristics: non-relational, distributed, open-source, horizontally extensible .

The main features are:

1, the processing of ultra-large amounts of data has a great advantage;

(1) High concurrent read and write data;

(2) Efficient storage and access to massive amounts of data;

(3) High scalability and high availability of data (database system upgrades and extensions are easy, NoSQL distribution is very simple, extension nodes, NoSQL does not have a fixed table structure (data structure modification is easy)).

2. Run on a cheap PC server cluster

3, compared to MySQL requires a lot of performance optimization, and NoSQL does not need, because its performance is very high.

Third, Java connection Redis

        redisclientSupports multiple languages, including:C、C + +、C #、PHP、Java、Python、Goand other languages, according to their own development language, choose the rightRedis ClientVersion type. ForJavaLanguageRedis ClientA variety of client support is also available, followed by the recommended type:Jedis、Redisson、Jredis、Jdbc-redis、RJC、Redis-protocol、Aredis、lettuce。 The first two types are more recommended, and we use theRedissonType version asredisclientThe use of.

Iv. Introductory attempt phase

The code below, just as a simple primer:

import org.redisson.config;import org.redisson.redisson;import java.util.queue;import  java.util.set;import java.util.concurrent.concurrentmap;public class redisexample {     /**     *     */     Public static void main (String[] args) {        // 1. Initialize         config config = new config ();         config.setconnectionpoolsize (Ten);         config.addaddress ("127.0.0.1:6379");         redisson  redisson = redisson.create (config);         SYSTEM.OUT.PRINTLN ("redis  connection succeeded!");         //Test concurrentmap        concurrentmap<string,object> map = redisson.getmap ("FirstMap1");         map.put ("Zhangsan", "male");         map.put ( "Lisi", "male"),         map.put ("Wangwu", "female");         concurrentmap resultmap = redisson.getmap ("FirstMap1");         system.out.println ("resultmap = "  + resultMap.keySet () ); &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;//2, Test set class         set  myset = redisson.getset ("FirstSet1");         myset.add ("Baidu");         myset.add ("Xinlang");         myset.add ("Souhu");         myset.add ("Wangyi");     &Nbsp;   set resultset = redisson.getset ("FirstSet1");         system.out.println ("resultset = "  + resultset.size ());   &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;//3, test queue queues         Queue  Myqueue = redisson.getqueue ("FirstQueue1");         Myqueue.add ("Dong Zhe");         myqueue.add ("Faye Wong");         myqueue.add ("Eason Chan");         myqueue.peek ();         myqueue.poll ();         queue resultqueue = redisson.getqueue ("FirstQueue1");         system.out.println ("resultqueue = "  + resultqueue);         //Closing the connection &NBSP;&NBsp;      redisson.shutdown ();     }} 


Run with the following results:

Redis connection is successful!
Resultmap = [Zhangsan, Lisi, Wangwu]
ResultSet = 4
Resultqueue = [Faye Wong, Eason Chan]

Process finished with exit code 0







NoSQL Redis (ii) (Java)

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.