-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from RedisGears/added_mysql_example
added mysql example
- Loading branch information
Showing
9 changed files
with
106 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Set up MySql DB | ||
|
||
## Setup MySql docker | ||
```bash | ||
docker run -p 3306:3306 --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:latest | ||
``` | ||
|
||
## Create Persons table | ||
```bash | ||
docker exec -it <mysql container id> /bin/bash | ||
mysql -u root -p # set password my-secret-pw | ||
CREATE DATABASE test; | ||
CREATE TABLE test.persons (person_id VARCHAR(100) NOT NULL, first VARCHAR(100) NOT NULL, last VARCHAR(100) NOT NULL, age INT NOT NULL, PRIMARY KEY (person_id)); | ||
CREATE USER 'demouser'@'%' IDENTIFIED BY 'Password123!'; | ||
FLUSH PRIVILEGES; | ||
GRANT ALL PRIVILEGES ON test.* to 'demouser'@'%'; | ||
FLUSH PRIVILEGES; | ||
``` | ||
|
||
# Running the recipe | ||
Assuming you have RedisGears up and running (see [Quick Start](https://oss.redislabs.com/redisgears/quickstart.html)). Please use <a href="https://github.com/RedisGears/gears-cli">gears-cli</a> to send a RedisGears Write-Behind and/or Write-Through recipe for execution. For example, run the sample [MySql](example.py) recipe (contains the mapping of MySql tables with Redis Hashes and RedisGears registrations) and install its dependencies with the following command: | ||
|
||
```bash | ||
gears-cli run --host <host> --port <port> --password <password> example.py --requirements requirements.txt | ||
``` | ||
|
||
# Test | ||
Using redis-cli perform: | ||
```bash | ||
redis-cli | ||
> hset person:1 first_name foo last_name bar age 20 | ||
``` | ||
|
||
Make sure data reached MySql server: | ||
```bash | ||
docker exec -it <mysql container id> /bin/bash | ||
mysql -u root -p # set password my-secret-pw | ||
mysql> select * from test.persons; | ||
+-----------+-------+------+-----+ | ||
| person_id | first | last | age | | ||
+-----------+-------+------+-----+ | ||
| 1 | foo | bar | 20 | | ||
+-----------+-------+------+-----+ | ||
1 row in set (0.00 sec) | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from rgsync import RGWriteBehind, RGWriteThrough | ||
from rgsync.Connectors import MySqlConnector, MySqlConnection | ||
|
||
''' | ||
Create MySQL connection object | ||
''' | ||
connection = MySqlConnection('demouser', 'Password123!', 'localhost:3306/test') | ||
|
||
''' | ||
Create MySQL persons connector | ||
''' | ||
personsConnector = MySqlConnector(connection, 'persons', 'person_id') | ||
|
||
personsMappings = { | ||
'first_name':'first', | ||
'last_name':'last', | ||
'age':'age' | ||
} | ||
|
||
RGWriteBehind(GB, keysPrefix='person', mappings=personsMappings, connector=personsConnector, name='PersonsWriteBehind', version='99.99.99') | ||
|
||
RGWriteThrough(GB, keysPrefix='__', mappings=personsMappings, connector=personsConnector, name='PersonsWriteThrough', version='99.99.99') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
rgsync | ||
PyMySQL | ||
cryptography |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
rgsync | ||
redis | ||
redis-py-cluster |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
rgsync | ||
rgsync |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters