Ubuntu12.04 install redis

Source: Internet
Author: User
Tags benchmark install redis

Redis shutdown command

/Usr/local/redis-cli-H 127.0.0.1-P 6379 shutdown to shut down the redis server. Be sure to specify the IP address and port of the redis server to be shut down.

 

The following references the original author's document original author link http://www.hello-code.com/blog/nosql/201404/3238.html
1. Go to the official website to find a download link for the latest stable version.Http://redis.io/downloadAt present, the latest version is 2.8.8. Let's just copy it and copy its link.

CD/tmp
Wget http://download.redis.io/releases/redis-2.8.8.tar.gz
CD redis-2.8.8
Make
Make install
Installed in the/usr/local/bin directory by default


2. Set the configuration file path and service

There is already a configuration file redis. conf in the decompressed directory. In the utils folder, The redis_init_script

Sudo mkdir/etc/redis
Sudo CP redis. CONF/etc/redis/6379. conf
CD utils
Sudo CP redis_init_script/etc/init. d/redis_6379
The default configuration file path in the redis_init_script file is/etc/redis/$ {redisport}. conf. I will not modify it. Keep this international convention ~


3. modify the configuration file

Create a directory before modifying the configuration file

Sudo mkdir/var/apsaradb for redis/6379
Sudo Vim/etc/redis/6379. conf
The items to be modified are as follows:

Set the service as a background program: daemonize Yes
Set the log file path: logfile "/var/log/redis_62.16.log"
Set the database file path: Dir "/var/redis/6379"


4. Check. Then, under Hello World

If the sudo service redis_6379 start command cannot be executed, replace it with the directory of the redis-server.

CD/etc/

Then redis-server/etc/redis/6379. conf
Redis-cli
> Set Hello World
> OK
> Get hello
"World"
Check the following content:

Check whether/var/redis/6379/dump. RDB exists
Check whether/var/log/redis_62.16.log has content.
All of the above are available for test.

 

Install the phpredis Module

First install git, PhP5, apache2, php5-dev this can be ignored

Sudo apt-Get install PhP5 php5-dev apache2

Time required for Installation

In the PHP-redis source code directory, run

Git clone https://github.com/nicolasff/phpredis.git

Here, you need to enter the downloaded directory to execute phpize.

CD phpredis/

Phpize

./Configure

Make & sudo make install

Prompt message:

Installing shared extensions:/usr/lib/PHP 5/20090626/

 

Remember that the above prompt information is very important, and then write a phpinfo () in PHP at will; view your phpini path

Open your phpini

Write extension =/usr/lib/PhP5/20090626/redis. So

Restart nginx or Apache. I am using the lnmp environment.

Service php5-fpm restart

Service nginx restart

Then redis will be OK.

========================================================== ================

<? PHP

$ Redis = new redis ();

$ Redis-> connect ('2017. 0.0.1 ', 127 );

$ Redis-> set ('test', 'Hello world! ');

Echo $ redis-> get ('test ');


?>

The following is the page output result.

 

 

The above code has been tested by myself. The following are some references.

Others also refer to http://blog.csdn.net/love__coder/article/details/8271832

Http://redis.io/topics/introduction

Http://timyang.net/data/mcdb-tt-redis/

Http://redis.io/commands#server

Http://code.google.com/p/redis/

 

Http://www.cnblogs.com/shanyou/archive/2012/01/28/2330451.html

 

Like jquery, rdis is generated purely for applications. Here we record the following learning articles on centos 5.7:

1. redis Introduction

Redis is a key-value storage system. Similar to memcached, But it solves the problem that data is completely lost after power-off, and she supports more undefined value types. Besides string, it also supports lists (linked list), sets, and zsets. These data types support push/pop, Add/Remove, Intersection Set and difference set, and more abundant operations, and these operations are atomic.

2. redis Performance

The following is the official benchmark-mark data:

  • The test was done with 50 simultaneous clients timing Ming 100000 requests.
  • The value set and get is a 256 bytes string.
  • The Linux box is runningFor Linux 2.6, It'sXeon x33 20 2.5 GHz.
  • Text executed using the loopback interface (127.0.0.1 ).

    Results:About 110000 sets per second, about 81000 gets per second.

For more details, see the official Alibaba-mark page (http://code.google.com/p/redis/wiki/Benchmarks)

3. Install redis

Redis Code follows the ANSI-C and can be written in all POSIX systems (such as Linux,*BSD, Mac OS X, Solaris, etc. In addition, redis does not rely on any non-standard library, nor does it need to add compilation parameters. The installation of redis is surprisingly simple. This may also be one of the reasons why it is popular. It is easy to get started. Unlike some things, the compilation phase can be totally desperate.

Go to the official website to download the source code:

Wget http://redis.googlecode.com/files/redis-2.4.6.tar.gz

Decompress:

Tar-zxvf redis-2.4.6.tar.gz

Compile

The installation of apsaradb for redis is very simple and there are ready-made makefile files. Run the make command directly.

Make

Make install

Redis consists of four executable files:Redis-Benchmark,Redis-cli,Redis-Server,Redis-statAdd one of the four filesRedis. confIt constitutes the final available package of the entire redis. Their functions are as follows:

  • Redis-server: Daemon Startup Program of the redis Server
  • Redis-CLI: redis command line operation tool. Of course, you can also use Telnet to operate based on its plain text protocol.
  • Redis-benchmark: redis performance testing tool to test the read/write performance of redis in your system and your configuration
  • Redis-stat: redis status detection tool that can detect redis's current status parameters and latency

Now you can start redis. redis has only one startup parameter, that is, its configuration file path.

Redis-server/etc/redis. conf

Note: by defaultRedis. confFileDaemonizeThe parameter isNoSo redis will not run in the background. To test this, we need to re-open a terminal. ChangeYesRun redis in the background. In addition, the PID file, log file, and data file address are specified in the configuration file. If you need to modify the address first, the default log information is directed to stdout.

The main configuration parameters of redis. conf are as follows:

  • Daemonize: whether to run in daemon mode
  • Pidfile: PID File Location
  • Port: the port number of the listener.
  • Timeout: Request timeout
  • Loglevel: log information level
  • Logfile: Location of the log file
  • Databases: number of databases Enabled
  • Save **: the frequency at which snapshots are saved. The first "*" indicates the duration and the third "indicates the number of write operations performed. Snapshots are automatically saved when a certain number of write operations are performed within a certain period of time. You can set multiple conditions.
  • Rdbcompression: whether to use Compression
  • Dbfilename: Data snapshot file name (only file name, excluding directory)
  • Dir: directory for storing data snapshots (this is the Directory)
  • Appendonly: whether to enable appendonlylog. If it is enabled, a log is recorded for each write operation, which improves data risk resistance but affects efficiency.
  • Appendfsync: How to synchronize appendonlylog to the disk (three options are force-call fsync for each write, enable fsync once per second, and do not call fsync to wait for the system to synchronize itself)

Now you can open a terminal for testing. The default listening port in the configuration file is6379

We can start a redis client for testing.

[[Email protected] ~] # Redis-cli
Cocould not connect to redis at 127.0.0.1: 6379: Connection refused
Not connected> exit
[[Email protected] ~] # Redis-server/etc/redis. conf
[[Email protected] ~] # Redis-cli
Redis 127.0.0.1: 6379> quit

4. redis Data Structure

Redis author antirez once called it a Data Structure server (Data Structures Server), This is a very accurate expression. All redis functions are to save data in several inherent structures and provide users with interfaces to operate these structures. We can imagine the inherent data types and their operations in various languages.

Redis currently provides four data types:String,List,SetAndZset(Sorted set) andHash.

  • StringIs the simplest type. You can understand it as a Type modeled by memcached. A key corresponds to a value, and the operations supported on it are similar to those of memcached. However, it provides more functions.
  • ListIs a linked list structure, the main function is to push, Pop, get all values of a range, and so on. In the operation, the key is interpreted as the name of the linked list.
  • SetIs a set. Similar to the set concept in our mathematics, we add and delete elements to the set operations, and perform operations such as intersection of multiple sets. The key in the operation is interpreted as the name of the set.
  • ZsetIs an upgraded version of set. It adds an ordered Attribute Based on set. This attribute can be specified when adding and modifying elements. After each attribute is specified, zset automatically re-adjusts the order according to the new value. It can be understood that there are two columns of MySQL tables, one column stores value and one column stores order. In the operation, the key is interpreted as the zset name.
  • HashThe data type allows users to use redis to store object types. An important advantage of the hash data type is that when there are only a few key values in the data object you store, the memory consumption of the data storage will be very small. for more information about hash data types, see: http://code.google.com/p/redis/wiki/Hashes

A list of all supported interfaces is provided on the official website. The list is detailed:

Http://code.google.com/p/redis/wiki/CommandReference

In addition, the author provides a very intimate web command line simulation page for beginners to try redis. Address:

Http://try.redis-db.com/

5. redis Data Storage

Redis storage is divided into three parts: memory storage, disk storage, and log files. The configuration file contains three parameters for configuration.

Save seconds updates,SaveConfiguration, indicating how long and how many update operations are performed, the data is synchronized to the data file. This can be used with multiple conditions. For example, three conditions are set in the default configuration file.

Appendonly Yes/No,AppendonlyConfiguration, indicating whether to record logs after each update operation. If not enabled, data may be lost for a period of time during power failure. Because redis synchronizes data files according to the above save conditions, some data will only exist in the memory for a period of time.

Appendfsync No/Always/Everysec,AppendfsyncConfiguration,NoIndicates that the data cache is synchronized to the disk by the operating system,AlwaysIndicates that it is manually called after each update operationFsync() Write data to the disk,EverysecIndicates synchronization once per second.

6. redis Master/Slave Configuration

Redis supportMaster-slaveMaster/Slave configuration, which is specified in the slave configuration fileSlaveofThe parameter is the IP address and port of the host.

7. Start redis (link sorting)

The project Homepage contains a list of Supported languages:

Http://code.google.com/p/redis/

The author provides a very good example in wiki to help us get started quickly:

Http://code.google.com/p/redis/wiki/TwitterAlikeExample

Another tutorial recommended by the author, at the same time:

Http://labs.alcacoop.it/doku.php? Id = articles: redis_land

A discussion site created by a redis enthusiast:

Http://www.rediscookbook.org/

Why use redis and its product positioning

Http://www.infoq.com/cn/articles/tq-why-choose-redis

Redis memory usage optimization and storage

Http://www.infoq.com/cn/articles/tq-redis-memory-usage-optimization-storage

Http://blog.csdn.net/love__coder/article/details/8271832

 

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.