Getting started with redis

Source: Internet
Author: User
Tags install redis value store
Getting started with redis

Author: nosqlfan on Friday, February 1, 2010-comment this article [read: 1,425 times]

This is an introductory tutorial for cainiao only.

Link: http://lgone.com/html/y2010/776.html

This article includes the following content:

  1. Redis Introduction
  2. Redis Performance
  3. Introduction to parameters for installing redis and redis startup
  4. Application Example: Using redis to build a simple Weibo System (official example link)

[Note: This is an introductory tutorial for cainiao only.]

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. Introduction to parameters for installing redis and redis startup

3. 1. 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 only thing we need to compile and install redis is make. The following is the installation process. The current stable version 1.2.6 is used, and Version 2.0 is currently under development.

3.1.1. Obtain the source code, decompress it, and enter the source code directory:

wget http://redis.googlecode.com/files/redis-1.2.6.tar.gztar xzf redis-1.2.6.tar.gzcd redis-1.2.6

3.1.2. compile and generate executable files:

Since the MAKEFILE file has been written, we only need to directly execute the make command in the source code directory for compilation:

make

After the make command is executed, an executable file is generated under the current directory, including redis-server, redis-CLI, redis-benchmark, and redis-Stat. 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

3.1.3. Create a redis directory (not required)

This process is not necessary. It is only necessary to manage redis-related resources in a unified manner.

Run the following command to create a directory and copy the file to the directory:

sudo -smkdir -p /usr/local/redis/binmkdir -p /usr/local/redis/etcmkdir -p /usr/local/redis/varcp redis-server redis-cli redis-benchmark redis-stat /usr/local/redis/bin/cp redis.conf /usr/local/redis/etc/

3.2.redis configuration parameters

After we successfully install redis, we can directly execute redis-server to run redis. At this time, it runs according to the default configuration (the default configuration is not even the background operation ). If we want redis to run as required, we need to modify the configuration file. The redis configuration file is the redis operated by the second CP above. CONF file, which is copied to the/usr/local/redis/etc/directory. Modify it to configure our server. How to modify it? 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)

The following is a slightly modified configuration file:

daemonize yespidfile /usr/local/redis/var/redis.pidport 6379timeout 300loglevel debuglogfile /usr/local/redis/var/redis.logdatabases 16save 900 1save 300 10save 60 10000rdbcompression yesdbfilename dump.rdbdir /usr/local/redis/var/appendonly noappendfsync alwaysglueoutputbuf yesshareobjects noshareobjectspoolsize 1024

Write the above content as redis. conf and save it to the/usr/local/redis/etc/directory.

Then run the following command in the command line:

/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf

You can start the redis service in the background.

telnet 127.0.0.1 6379

Connect to your redis service.

4. Using redis to build a simple Weibo System

For specific examples, see the official documentation:
A Case Study: design and implementation of a simple Twitter clone using only the redis key-value store as database and PHP

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.