redisのインストールと使用

3281 ワード

Redisは高度なkey-valueデータベースです.memcachedと似ていますが、データは永続化され、サポートされているデータ型は豊富です.文字列、チェーンテーブル、コレクション、および整列コレクションがあります.サーバ側での集計、交差、補完などをサポートし、複数のソート機能もサポートします.したがって、Redisはデータ構造サーバと見なすこともできる. 
Redisのすべてのデータはメモリに保存され、不定期に非同期でディスクに保存されます(「半永続化モード」と呼ばれます).データの変化のたびにappend only file(aof)に書き込むこともできます(「全持続化モード」と呼ばれます). 
1.ダウンロードとインストール
$ wget http://redis.googlecode.com/files/redis-2.4.15.tar.gz  
$ tar xzf redis-2.4.15.tar.gz
$ cd redis-2.4.15  
$ make  
$ make install  
$ cd utils  
$./install_server

/usr/local/binディレクトリに自動的にインストールされます.このディレクトリの下に、redis-server、redis-cli、redis-benchmark、redis-stat、redis-check-aofのいくつかの実行可能ファイルが生成されます.
redis-server:Redisサーバのdaemonイニシエータ
redis-cli:Redisコマンドライン操作ツール.もちろんtelnetで純粋なテキストプロトコルに基づいて操作することもできます
redis-benchmark:Redis性能テストツール、Redisのあなたのシステムとあなたの構成の下での読み書き性能をテストします
redis-stat:Redis状態検出ツール、Redis現在の状態パラメータおよび遅延状況を検出できる
redis-check-aof: 
2.起動
$ cd utils  
$./install_server
この2つのステップで起動コマンドファイルが生成されます
Welcome to the redis service installer
This script will help you easily set up a running redis server


Please select the redis port for this instance: [6379] 
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf] 
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log] 
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379] 
Selected default - /var/lib/redis/6379
Please select the redis executable path [/usr/local/bin/redis-server] 
./install_server.sh: 153: [[: not found
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
./install_server.sh: 168: [[: not found
./install_server.sh: 168: chkconfig: not found
./install_server.sh: 168: chkconfig: not found
/etc/init.d/redis_6379: 1: -e: not found
Starting Redis server...
Installation successful!
この時点で
 
/etc/init.d/redis_6379 start 
を選択します.d/redis_6379 stopをオフにするには、もちろん/usr/local/binディレクトリの下でredis-serverを使用して起動することもできます.
3.ローカルクライアント接続
$ redis-cli  
redis> set foo bar  
OK  
redis> get foo  
"bar" 

jedisクライアントによる接続
public static void main(String[] args) {
        Jedis jedis = new Jedis("192.168.128.128");
	jedis.set("foo", "xxxxx");
	System.out.println(jedis.get("foo"));
}

4.カスタムサーバー起動パラメータ
Redis-serverを直接実行するとRedisが実行され、デフォルト構成で実行されます(デフォルト構成はバックグラウンドでも実行されません).Redisを私たちの要求通りに実行するには、プロファイルを変更する必要があります(redis解凍ディレクトリの下にredis.conがモデルになります).次はredisです.confの主な構成パラメータの意味:
daemonize:     daemon     
pidfile:pid     
port:       
timeout:       
loglevel:log     
logfile:log     
databases:         
save * *:       ,   *      ,   *          。                 ,      。       。 
rdbcompression:       
dbfilename:       (     ,     ) 
dir:         (     ) 
appendonly:    appendonlylog,             log,           ,     。 
appendfsync:appendonlylog       (    ,           fsync、      fsync、   fsync        ) 
サーバの再起動
redis-server /redis/redis-2.4.15/redis.conf

redisコマンドは中国語版を参照してください.http://redis.readthedocs.org/en/2.4/index.html