LoginSignup
1
1

More than 5 years have passed since last update.

NodeJSのRedisClientメモ

Posted at

よくわからなくなるのでメモする。
色々足りてないけどとりあえず公開

基本操作

クライアントの作成

var client = require('redis').createClient(port, host);

トランザクション

repliesにはそれぞれの処理の結果が入っている。

var multiClient = client.multi();
multi.llen(...);
multi.lpush(...);
multi.exec(callback(err, replies));

リスト型の処理

LPUSH, RPUSH

LPUSHは一番前にPUSHする(つまり、最新は一番前にくる)
RPUSHは一番最後にPUSHする。

client.lpush(key, '内容文字列', callback(err));

LLEN

件数を調べる。

client.llen(key, callback(err, length));

LRANGE

範囲を指定して取得する
開始位置(begin)と終了位置(end)を指定する。(数値)
なお、-1を指定することでリストの最後を取得することが出来る。

client.lrange(key, begin, end, callback(err, messages));

LREM

同じ値のレコードを削除します。件数を指定することができ、0の場合は全て削除します。(なお、マイナス値で指定すると逆から削除します)

client.lrem(key, num, value);
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1