Redis is a very efficient key-value database, which is widely used in projects. However, Redis has obvious disadvantages in memory processing, at the beginning of the project's launch, you must plan the memory properly. Otherwise, the memory will pop up easily. one label is UbuntuRedis.
Redis is a very efficient key-value database, which is widely used in projects. However, Redis has obvious disadvantages in memory processing, at the beginning of the project launch, you must plan the memory properly. Otherwise, the memory may burst. Generally, the reasonable memory size is 3/5 of the physical memory of the computer.
Redis provides a variety of data types. I often use String, Hash, List, Set, Sorted Set, which can basically meet the project's data type requirements. We use the Redis Java client and provide a series of APIs for Redis commands. Redis Persistence provides a variety of policies, but we didn't do persistence. after studying it ourselves, the AOF method is the most reliable. The principle is similar to that of Mysql binary logs, it also records operation information and writes it to a file, reads logs from the server, and performs operations.
In general intranet development, you may need to adjust the data storage details. Therefore, if the previous data remains in the memory, many functions may fail to run normally. Therefore, after adjusting the details, perform the Flushdb operation on the Redis database.
Redis and Ssdb are very suitable for use in some scenarios. for example, some data can only be left in the database for 2 minutes, similar to T people in YY channel. they can only come in after several minutes, you can use the setex key seconds value command to determine whether the value has expired. you can use the exists key command.
Redis common command site: http://redis.readthedocs.org/en/latest/ covers redis commands and demo.
Redis was mentioned before building Ssdb because Ssdb is compatible with Redis APIs. It is a good alternative to Redis.
Compared with Redis, Ssdb has many advantages: it is 100 times the capacity of Redis database and can store billions of data. Apsaradb for Redis occupies a small amount of memory. So I downloaded ssdb myself. The following describes how to build ssdb.
- Environment: ubuntu14
- Vm a: 192.168.1.20.
- Virtual Machine B: 192.168.1.252
- Gateway: 192.168.1.1
My two virtual machines are respectively mounted on different physical machines, but both adopt the bridging mode, and the ip addresses are all in the same ip segment.
Install ssdb online on both VMS.
- wget--no-check-certificatehttps://github.com/ideawu/ssdb/archive/master.zip
- unzipmaster
- cdssdb-master
- make
- sudomakeinstall
These can be found on the ssdb official website at http://www.ideawu.com/ssdb/zh_cn /.
The ssdb master-slave architecture is actually very simple. you only need to find ssdb. conf under the ssdb installation directory of the two virtual machines.
- sudovissdb.conf
Change the ip address of the server to the default ip address of the VM.
Virtual machine:
- Server:
- Ip: 192.168.1.20.
- Port: 8888 // The port is not changed. use the default value.
Virtual Machine B:
- server:
- ip:192.168.1.252
- port:8888
This is the most basic configuration.
Now, you only need to configure ssdb. conf on the basis of:
- replication:
- slaveof:
- #toidentifyamasterevenifitmoved(ip,portchanged)
- #ifsettoemptyornotdefined,ip:portwillbeused.
- id:svc_2
- #sync|mirror,defaultissync
- type:sync
- ip:192.168.1.252
- port:8888
Note: In the above configuration process, do not use the space key, use tab.
Now you can start ssdb.
- ./ssdb-serverssdb.conf
Then you can use the command line tool provided by ssdb to perform operations.
Vm a:./ssdb-cli-h 192.168.1.20.- p 8888
Virtual Machine B:./ssdb-cli-h 192.168.1.252-p 8888