PostgreSQL9.6.3的REDIS测试
安装redis_fdw
cd /usr/local/src
git clone https://github.com/pg-redis-fdw/redis_fdw.git
cd redis_fdw/
git checkout REL9_6_STABLE
git clone https://github.com/redis/hiredis
cd hiredis
make
make PREFIX=/usr/local/hiredis_bin install
vi Makefile
# 末尾追加
LDFLAGS += -L/usr/local/hiredis_bin/lib
export PATH=/usr/local/pgsql/bin:$PATH
make USE_PGXS=1
make USE_PGXS=1 install
2.添加环境变量。因程序运行时,会用到libhiredis.so.0.13这个动态库,所以需要把它的路径加到环境变量里
vi ~/.bash_profile #用vi打开当前用户的bash_profile
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib #在最后一行添加
source ~/.bash_profile
psql -U postgres
CREATE EXTENSION redis_fdw;
CREATE SERVER redis_server FOREIGN DATA WRAPPER redis_fdw OPTIONS (address '10.10.6.199', port '9221');
CREATE FOREIGN TABLE redis_db0 (key text, val text) SERVER redis_server OPTIONS (database '0');
CREATE USER MAPPING FOR PUBLIC SERVER redis_server OPTIONS (password 'digoal');
CREATE FOREIGN TABLE myredishash (key text, val text[]) SERVER redis_server OPTIONS (database '0', tabletype 'hash', tablekeyprefix 'mytable:');
INSERT INTO myredishash (key, val) VALUES ('mytable:r1','{prop1,val1,prop2,val2}');
UPDATE myredishash SET val = '{prop3,val3,prop4,val4}' WHERE key = 'mytable:r1';
select * from myredishash;
--级联删除掉
drop SERVER redis_server CASCADE;
参考地址:
https://yq.aliyun.com/articles/9035