Re: Request for review of new redis-fdw module - Mailing list pgsql-general

From George Silva
Subject Re: Request for review of new redis-fdw module
Date
Msg-id CAGyPVTuXeWM8u+cp8XaifeytzV8bgLQ4bFtxOuEoJcfeOG0Vjg@mail.gmail.com
Whole thread Raw
In response to Re: Request for review of new redis-fdw module  (Leon Dang <ldang@nahannisys.com>)
Responses Re: Request for review of new redis-fdw module
List pgsql-general
Great. Congratulations.

How big is the latency in the FDW? This opens up new possibilities using redis. Very cool.

On Wed, Jan 28, 2015 at 5:19 PM, Leon Dang <ldang@nahannisys.com> wrote:

Andreas Kretschmer wrote on 01/28/2015 03:36 AM:
> I've implemented a completely new Redis FDW module which has little to do with
> github.com/pg-redis-fdw/redis_fdw; although I did take some inspiration from in
> on how the tables were to be designed but most I got from looking at the
> oracle-fdw.
>
> My redis-fdw implementation supports read and write to the Redis backend, so
> you can do insert, update, and delete. e.g. you can define a hash table as:

is it possible to write multiple row's into the redis? something like

insert into foreign_redis_table select * from big_table


Thanks for pointing this out. I had a small bug which didn't let it succeed, but now it's been fixed and committed; I've also added a bulkdata.sql test script in the code to show an example.


Anyway, thx, compiled and installed (just for fun, i'm not familiar with
redis, and i'm not a coder)


Redis is great for session management as it allows you to set an expiry for each key. So by using redis_fdw, you don't need to do multiple queries to determine of the session is still valid. e.g.:

-- use a string (key-value) dataset for user sessions
CREATE FOREIGN TABLE rsessions(
    sessid TEXT,
    value  TEXT,
    expiry INT
) SERVER localredis
  OPTIONS (tabletype 'string');
ALTER FOREIGN TABLE rsessions ALTER COLUMN sessid OPTIONS (ADD param 'key');

-- a user table in postgres, can contain a whole bunch of other fields.
CREATE TEMP TABLE users (
    userid   INT,
    username TEXT,
    sessid   TEXT
);


--
-- get user's details at the same time as determining if they're session is still valid
--
WITH u AS (SELECT * FROM users WHERE username = 'foo')
SELECT u.*, r.value, r.expiry
FROM rsessions r, u
WHERE r.sessid = (SELECT u.sessid FROM u);



If the user's session is still valid then a row will be returned (Redis automatically destroys the key on expiry).


--
-- to reset the expiry timeout for the user
--
UPDATE rsessions SET expiry = 40 WHERE sessid = $1;



Leon



--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



--
George R. C. Silva
SIGMA Consultoria
----------------------------

pgsql-general by date:

Previous
From: Leon Dang
Date:
Subject: Re: Request for review of new redis-fdw module
Next
From: "Day, David"
Date:
Subject: Re: segmentation fault postgres 9.3.5 core dump perlu related ?