"NOSQL" Redis Practice-Simple Demo implementation (i)

Source: Internet
Author: User
Tags delete key memcached


Redis is a key-value storage system.

The emergence of Redis, to a great extent, compensates for the memcached of such key/value storage, which can be a very good complement to relational databases in some cases.

Redis is a key-value storage system. Similar to the memcached. It supports storage of value types relative to many other, including string (string), list (linked list), set (set), Zset (sortedset--ordered collection), and hash (hash type). These data types support Push/pop, Add/remove, and intersection-set and difference sets, and richer operations, and these operations are atomic in nature. On this basis. Redis supports sorting in a variety of different ways.

As with memcached, to ensure efficiency. The data is cached in memory. The difference is that Redis periodically writes the updated data to the disk or writes the change operation to the appended record file. The Master-slave (master-slave replication) is implemented on this basis.

Memcache and Redis differences

Memcache less data types are available. There are only key-value pairs, andRedis provides a relatively large number of data types

Memcache The shutdown is gone, all data is stored in the memory, but no recovery is provided. Redis is able to store data on disk

Redis provides master-slave replication, Memcache No

Memcache is multi-threaded (with protocol resolution), Redis is a single thread


  

installation of Redis under Windows is used

1, installing Redis

Official download: Http://redis.io/download can download different version numbers according to the need

Windows Edition: Https://github.com/mythz/redis-windows

After downloading, you can right-click on a hard disk to extract the analogy E:\redis64-2.6.

2, start Redis

Turn on the service after entering the Redis folder (note plus redis.conf)

Redis-server.exe redis.conf

The Redis service shuts itself down when the form is to be turned off




Note : Redis will proactively save the data to the hard drive so let's assume it's a second time to open with a DB loaded from disk

3, test use

Also open a command line form into the Redis folder (notice to change your own IP)

redis-cli.exe-h 192.168. - . 215 - P 6379




4, using Java to operate Redis


Import Org.junit.After;  Import Org.junit.Before;  Import Org.junit.Test;  Import Redis.clients.jedis.Jedis;  Import Redis.clients.jedis.JedisPool;    Import Redis.clients.jedis.JedisPoolConfig;  Import Javax.sound.midi.Soundbank;      Import java.util.*;      public class Redistest {Jedispool pool;      Jedis Jedis;            @Before public void SetUp () {pool = new Jedispool (new Jedispoolconfig (), "192.168.24.215");         Jedis = Pool.getresource ();  /* Jedis.auth ("password"); * */** * Redis Storage 0 Base String * CRUD */@Test public void testbasicstring () {//--- --Add the data----------jedis.set ("name", "Hejingyuan");//Put Value-->hejingyuan System.out.pri into Key-->name Ntln (Jedis.get ("name"));//Run Result: Hejingyuan//-----Change data-----------//1, change jedis.append on original basis ("N   Ame "," Xvshu "); Very intuitive, similar map will Xvshu append to the already existing value System.out.println (Jedis.get ("name"));//Run Result: Hejingyuanxvshu            2, directly overwrite the original data jedis.set ("name", "He Jinghuan");          System.out.println (Jedis.get ("name"));//Run Result: He Jinghuan//delete key corresponding record Jedis.del ("name"); System.out.println (Jedis.get ("name"));//Run Result: null/** * mset equivalent to * jedis.set ("name", "Hejingyua          n ");          * Jedis.set ("Xvshu", "He Jinghuan");          */Jedis.mset ("name", "Hejingyuan", "Xvshu", "He Jinghuan");        System.out.println (Jedis.mget ("name", "Xvshu")); } }


Output Result:

Hejingyuan

Hejingyuanxvshu

He Jinghuan

Null

[Hejingyuan, He Jinghuan]

Concluding remarks:

During the operation,R Edis is saved to the hard disk by default (snapshotting), and Redis stores the snapshot files in the current folder (config Getdir to view) by default Dump.rdb file, you can specify the storage path and file name of the snapshot file by configuring Dir and dbfilename two parameters respectively.

before we operate Redis process, it is also constantly stored to the hard disk





Java Operation Redis the various tests: http://flychao88.iteye.com/blog/1527163




"NOSQL" Redis Practice-Simple Demo implementation (i)

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.