redis 安装及安装遇到的问题解决

Redis Quick Start

This is a quick start document that targets people without prior experience with Redis. Reading this document will help you:

Installing Redis

The suggested way of installing Redis is compiling it from sources as Redis has no dependencies other than a working GCC compiler and libc. Installing it using the package manager of your Linux distribution is somewhat discouraged as usually the available version is not the latest.

You can either download the latest Redis tar ball from theredis.ioweb site, or you can alternatively use this special URL that always points to the latest stable Redis version, that is,

In order to compile Redis follow this simple steps:

wget tar xvzf redis-stable.tar.gzcd redis-stablemake

At this point you can try if your build works correctly typingmake test, but this is an optional step. After the compilation thesrcdirectory inside the Redis distribution is populated with the different executables that are part of Redis:

redis-check-aofandredis-check-dumpare useful in the rare event of corrupted data files.

It is a good idea to copy both the Redis server than the command line interface in proper places using the following commands:

sudo cp redis-server /usr/local/bin/sudo cp redis-cli /usr/local/bin/

In the following documentation I assume that /usr/local/bin is in your PATH environment variable so you can execute both the binaries without specifying the full path.

Starting Redis

The simplest way to start the Redis server is just executing theredis-serverbinary without any argument.

$ redis-server[28550] 01 Aug 19:29:28 # Warning: no config file specified, using the default config. In order to specify a config file use ‘redis-server /path/to/redis.conf'[28550] 01 Aug 19:29:28 * Server started, Redis version 2.2.12[28550] 01 Aug 19:29:28 * The server is now ready to accept connections on port 6379… and so forth …

In the above example Redis was started without any explicit configuration file, so all the parameters will use the internal default. This is perfectly fine if you are starting Redis just to play a bit with it or for development, but for production environments you should use a configuration file.

To start Redis with a configuration file just give the full path of the configuration file to use as the only Redis argument, for instance:redis-server /etc/redis.conf. You can use the redis.conf file included in the root directory of the Redis source code distribution as a template to write your configuration file.

Check if Redis is working

External programs talk to Redis using a TCP socket and a Redis specific protocol. This protocol is implemented in the Redis client libraries for the different programming languages. However to make hacking with Redis simpler Redis provides a command line utility that can be used to send commands to Redis. This program is calledredis-cli.

The first thing to do in order to check if Redis is working properly is sending aPINGcommand using redis-cli:

$ redis-cli pingPONG

Runningredis-clifollowed by a command name and its arguments will send this command to the Redis instance running on localhost at port 6379. You can change the host and port used by redis-cli, just try the –help option to check the usage information.

Another interesting way to run redis-cli is without arguments: the program will start into an interactive mode where you can type different commands:

$ redis-cliredis 127.0.0.1:6379> pingPONGredis 127.0.0.1:6379> set mykey somevalueOKredis 127.0.0.1:6379> get mykey"somevalue"

At this point you can talk with Redis. It is the right time to pause a bit with this tutorial and start thefifteen minutes introduction to Redis data typesin order to learn a few Redis commands. Otherwise if you already know a few basic Redis commands you can keep reading.

Using Redis from your application

Of course using Redis just from the command line interface is not enough as the goal is to use it from your application. In order to do so you need to download and install a Redis client library for your programming language. You’ll find afull list of clients for different languages in this page.

For instance if you happen to use the Ruby programming language our best advice is to use theRedis-rbclient. You can install it using the commandgem install redis(also make sure to install theSystemTimergem as well).

These instructions are Ruby specific but actually many library clients for popular languages look quite similar: you create a Redis object and execute commands calling methods. A short interactive example using Ruby:

>> require ‘rubygems’=> false>> require ‘redis’=> true>> r = Redis.new=> #<Redis client v2.2.1 connected to redis://127.0.0.1:6379/0 (Redis v2.3.8)>>> r.ping=> "PONG">> r.set(‘foo’,’bar’)=> "OK">> r.get(‘foo’)=> "bar"Redis persistence那么威尼斯就是一艘轻盈和流动的舟船,

redis 安装及安装遇到的问题解决

相关文章:

你感兴趣的文章:

标签云: