Redis Environment Setup (Linux), Jredis

Source: Internet
Author: User
Tags redis version redis server

    • Brief introduction

1. NoSQL is stored in the form of key-value, unlike traditional relational databases, which do not necessarily follow some of the basic requirements of traditional databases, such as following the SQL standard, ACID properties, table structure, and so on, such databases are mainly characterized by: non-relational, distributed, open source, Horizontally scalable.

2. Features of NoSQL:
A) processing ultra-large amounts of data.
b) run on a cheap PC server cluster
c) Shatter the performance bottleneck.

3. NoSQL Application Scenarios
A) high concurrency for data read and write. (We're working on MySQL for tens of thousands of times, so our hard drive IO may not be able to afford it.)
b) Efficient storage and access to massive amounts of data.
c) High scalability and high availability of data. (Database can add a server node to complete data migration and database maintenance)

4. Redis is fully open source free, complies with BSD protocol, advanced Key-value persistent products. It is commonly referred to as the (data structure server), because values (value) can be strings (string), hash (MAP), linked list (list), set (sets), and ordered collection (sorted sets) and other types.

5. Redis is a key-value storage system. It supports a large number of stored value types, including String,list,set,zset (ordered collections). These data types support Push/pop,add/remove and intersection and set and richer operations Redis supports sorting in a variety of different ways (because Redis has a ZSET data structure, which is the order in which it is stored by a key). To ensure efficiency, the data is cached in memory, which periodically writes the updated data to disk or writes the modified operation to the appended record file. (writes the modified operation to the appended record file, this is similar to the MySQL Bin-log, the storage is the update data, inserts the data and deletes the data related operation)

6. The API language provided by Redis: http://www.redis.io/clients

7. Applications for Redis
A) application direct access to the Redis database

Note: There may be some problems with direct access to the Redis database, which is straightforward to manipulate the database, but if one day my Redis database is down, my data will be permanently lost.

b) Application direct access to Redis, only access to MySQL if Redis access fails

Analysis: First our application directly accesses our Redis server and writes to Redis. At this point, Redis synchronizes with the MySQL cluster behind it. When the Redis service is down, the application server will look for MySQL in the back.

    More useful scenarios for Redis:
Operations that take the latest n data
Leaderboard application, Top n operation
Applications that need to set the expiration time exactly (you can set the expiration time on the key, this MySQL will not be able to do)
Counter Application
Uniq operation, get all data row weight values for a certain period of time
Real-time system, anti-spam system.
Pub/sub build a real-time messaging system. (Publish and subscribe are Redis-unique systems)
Build the queue system.
Cache

8. mysql vs. Redis, MongoDB

Redis

Mysql

Mongodb

The concept of a library

The concept of a library

The concept of a library

The concept of no table

The concept of a table

Collection

The concept of no fields

There is the concept of a field (row, column)

The concept of no fields

    • Redis Installation

1.http://www.redis.io/download

2. You can run the following command under Linux to install

wget http://download.redis.io/releases/redis-2.8.17.tar.gztar xzf redis-  2.8. . Tar . gz$ CD Redis-2.8.  -   make

After the installation is complete, the compiled Redis service redis-server will appear under the/OPT/REDIS-2.8.17/SRC directory, as well as the client program for testing REDIS-CLI

3. Start the Redis service below

[Email protected] redis-2.8.17]# Src/redis-server

[8491] 22:45:39.989 # warning:no config file specified, using the default Config. In order to specify a config file use src/redis-server/path/to/redis.conf
[8491] 22:45:39.991 * increased Maxim Um number of open files to 10032 (it is originally set to 1024).
[8491] 22:45:39.992 # warning:32 bit instance detected but no memory limit set. Setting 3 GB maxmemory limit with ' noeviction ' policy now.
_._
_.-' __ '-._
_.-'. "-._ Redis 2.8.17 (00000000/0),".-".-".-"". "/_.,_"-._
(',.-' | ') Running in stand alone mode< br> | '-._ '-...-' __...-. '-._| ' ' _.-' | port:6379
| '-._ '. _/_.-' | pid:8491
'-._ '-._ '-./_.-' _.-'
| '-._ '-._ '-.__.-' _.-' _.-' |
| '-._ '-._ _.-' _.-' | http://redis.io
'-._ '-._ '-.__.-' _.-' _.-'
| '-._ '-._ '-.__.-' _.-' _.-' |
| '-._ '-._ _.-' _.-' |
'-._ '-._ '-.__.-' _.-' _.-'
'-._ '-.__.-' _.-'
'-._ _.-'
'-.__.-'

[8491] 22:45:39.995 # Server started, Redis version 2.8.17
[8491] 22:45:39.997 # WARNING Overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add ' vm.overcommit_memory = 1 ' to/etc/sysctl.conf and then reboot or run the command ' Sysctl vm.overcom Mit_memory=1 ' for the take effect.
[8491] 22:45:39.997 * The server is now a ready-to-accept connections on port 6379

Note this way of starting Redis is using the default configuration. You can also tell Redis to start with the following command using the specified configuration file through the startup parameters.

[Email protected] redis-2.8.17]# Src/redis-server redis.conf

Redis.conf is a default configuration file. We can use our own configuration files as needed.
Once the Redis service process is started, you can use the test client program REDIS-CLI to interact with the Redis service.

    • Redis test

1. Enter the following command

[Email protected] redis-2.8. +] # src/redis-127.0. 0.1:6379> set yml blingok127.0. 0.1:6379> get yml"bling"127.0. 0.1:6379

This shows an example of the get and set commands manipulating simple type value. Foo is a key, bar is a string type of value
No Linux can be practiced through this online, of course, the online version of the many management-related commands are not supported.
http://try.redis-db.com/

    • Java Client uses

1. Client jar:http://www.java2s.com/code/jar/j/downloadjredisjar.htm

Maven Address: http://mvnrepository.com/artifact/redis.clients/jedis/2.6.0

2. Create a new MAVEN project in Eclipse and add the Jredis package dependency. Here's a simple example.

1  PackageCom.bling.redis;2 3 ImportRedis.clients.jedis.Jedis;4 5 6 /**7 * Hello world!8  *9  */Ten  Public classApp One { A      Public Static voidMain (string[] args) -     { -Jedis j =NewJedis ("192.168.168.128", 6379); theString key = "Yml"; -J.set (Key, "Hello Redis June!")); -String value =NewString (J.get (key)); -          +String Key2 = "Count"; - j.incr (key2); + j.incr (key2); AString value2 =NewString (J.get (Key2)); atSystem.out.println ("value =" +value); -System.out.println ("value2 =" +value2); -     } -}
<Projectxmlns= "http://maven.apache.org/POM/4.0.0"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  <modelversion>4.0.0</modelversion>  <groupId>Com.bling.redis</groupId>  <Artifactid>Com.bling.redis</Artifactid>  <version>0.0.1-snapshot</version>  <Packaging>Jar</Packaging>  <name>Com.bling.redis</name>  <URL>http://maven.apache.org</URL>  <Properties>    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  </Properties>  <Dependencies>    <Dependency>      <groupId>Junit</groupId>      <Artifactid>Junit</Artifactid>      <version>3.8.1</version>      <Scope>Test</Scope>    </Dependency>    <!--Jredis (client Tools) -    <Dependency>    <groupId>Redis.clients</groupId>    <Artifactid>Jedis</Artifactid>    <version>2.6.0</version>    </Dependency>  </Dependencies></Project>

The results of the operation are as follows:

Value = Hello Redis June!
value2 = 2

Redis Environment Setup (Linux), Jredis

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.