Redis is a key-value storage system. The emergence of Redis, to a large extent, compensates for the lack of memcached such key/value storage, in some cases can be a good complement to the relational database
Redis is a key-value storage system. Similar to memcached, it supports storing more value types, 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 sets and differences, and richer operations, and these operations are atomic in nature. Based on this, Redis supports sorting in a variety of different ways. As with memcached, data is cached in memory to ensure efficiency. The difference is that Redis periodically writes the updated data to disk or writes the modification to the appended record file, and implements the Master-slave (master-slave copy) on this basis.
Memcache and Redis differences
Memcache There are few data types available, only key-value pairs, Redis relatively large number of data types provided
Memcache The shutdown is gone, the data is all stored in memory, but no recovery is provided . Redis data can be stored to 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 versions as needed
Windows Edition: Https://github.com/mythz/redis-windows
After the download is complete, you can right-click on a hard drive such as E:\redis64-2.6.
2, start Redis
Turn on the service after entering the Redis directory (note plus redis.conf)
Redis-server.exeredis.conf
The Redis service shuts down automatically when this window is to be turned on and off
Note : Redis automatically saves data to the hard disk so if it's a second time, it's a DB loaded from disk.
3, test use
Also open a command line window into the Redis directory (note to modify 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 Primary String * CRUD * * * @Test public void testbasicstring () {//---- -Add Data----------jedis.set ("name", "Hejingyuan");//Put Value-->hejingyuan System.out.prin into Key-->name TLN (Jedis.get ("name"));//Execution Result: Hejingyuan//-----Modify the Data-----------//1, modify the Jedis.append on the original basis ("NA Me "," Xvshu "); Very intuitive, similar to map will Xvshu append to already have value after System.out.println (Jedis.get ("name"));//Execution Result: Hejingyuanxvshu 2, directly overwrite the original data jedis.set ("name", "He Jinghuan"); System.out.println (Jedis.get ("name"));//Execution Result: He Jinghuan//delete key corresponding record Jedis.del ("name"); System.out.println (Jedis.get ("name"));//execution 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 defaults to storing the snapshot files in the current directory (configurable Getdir to view) 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 of various tests: http://flychao88.iteye.com/blog/1527163
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
"NOSQL" Redis Practice-Simple Demo implementation (i)