0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

redisをその場限りで使う話

Last updated at Posted at 2017-04-19

redis の zset がどうしても使いたいけど、そのためだけに常駐させるのは嫌だし、永続化する必要も無いし、
leveldb とか sqlite とかも代替にならなそうなので、
その場限りで redis-server 立ち上げてソケットで繋ぐことにした話。

# !/bin/bash

set -ue

# バックグラウンドでredis起動
cat <<EOD | redis-server -
daemonize yes
pidfile redis.pid

port 0
bind 127.0.0.1

logfile redis.log
loglevel verbose

unixsocket redis.sock
unixsocketperm 700

timeout 0
databases 16
EOD
# 後始末
trap 'kill $(cat redis.pid)' EXIT

# 立ち上がりを待機
while test ! -S redis.sock; do sleep 1; done

# socket 経由で繋いでみる
redis-cli -s redis.sock <<EOD
set hoge 123
get hoge
EOD

やっぱredisだよね、みたいな。

0
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?