Open an SQL Editor within PGAdmin:
Let’s create some test data
The special generate_series command in PostgreSQL allows us to do this easily.
1 2 3 4 |
create table test_data as( select a as k, 'row' || a as val from ( select generate_series(1,100,1) as a ) as x); |
We have just loaded some data into a new table called test_data.
Have a look at the data using:
1 |
select * from test_data; |
Let’s add the redis command text column so we can generate the redis data too from the same data.
1 |
alter table test_data add column rtext text; |
Update the new column with the data from the same table adding in the REDIS Command syntax
1 |
update test_data set rtext = 'SET ' || k || ' ' || val; |
Let’s output the data from PostgreSQL table into a file called a.txt for sending to REDIS
On the ubuntu VM Terminal:
1 2 3 |
su postgres cd /var/tmp/ psql -d avinton -c 'select rtext from test_data;' -o a.txt |
Now let’s change permissions for this new file so that all users can access
1 |
chmod 777 a.txt |
Let’s copi this file to a common area where users can access it
1 |
cp a.txt /var/tmp/ |
Lets use this file to load data to REDIS
Exit from postgres user
1 |
exit |
Exit from root user
1 |
exit |
As normal user lets run the redis-cli and pipe the file
1 |
cat /var/tmp/a.txt | redis-cli --pipe |
Now we should have the same data in both REDIS & PostgreSQL DB (only 100 rows)
Have a look at the data using the REDIS Desktop as here