korechi’s diary

とあるVR/ARエンジニアのブログ

CentOS に Redis をインストールして C 言語で使う方法

参考記事

  1. Redis のインストール
$ wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
$ wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
$ rpm -Uvh remi-release-6*.rpm epel-release-6*.rpm
$ yum --enablerepo=remi,epel install -y redis
$ git clone https://github.com/redis/hiredis.git
$ cd hired is
$ make
# make install
  1. テストデータの挿入
# service redis start
$ redis-cli 
set 1 tamura
set 2 tanaka
set 3 senuma
  1. C 言語サンプルプログラム examplesフォルダ下に example.c があるのでそれを使います。
$ cd examples
$ gcc -Wall -o example example.c -lhiredis -L/usr/local/lib -I/usr/local/include/hiredis
$ ./example
PING: PONG
SET: OK
SET (binary API): OK
GET foo: hello world
INCR counter: 1
INCR counter: 2
0) element-9
1) element-8
2) element-7
3) element-6
4) element-5
5) element-4
6) element-3
7) element-2
8) element-1
9) element-0