This file contains hidden or 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
import ( | |
"context" | |
"time" | |
goRedis "github.com/redis/go-redis/v9" | |
) | |
type RedisRepository struct { | |
client goRedis.Client | |
} |
This file contains hidden or 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
func (repo *RedisRepository) Get(key string) (string, error) { | |
val, err := redigo.String(repo.conn.Do("GET", key)) | |
if err != nil { | |
return "", err | |
} | |
return val, nil | |
} | |
func (repo *RedisRepository) Set(key, value string) error { | |
_, err := repo.conn.Do("SET", key, value) |
This file contains hidden or 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
type RedisRepository struct { | |
conn redigo.Conn | |
} | |
func NewRedisRepository(address, password string) RedisRepository { | |
connection, err := redigo.Dial("tcp", address, redigo.DialPassword(password)) | |
if err != nil { | |
panic(err) | |
} | |
return RedisRepository{ |
This file contains hidden or 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
var _ redis.RedisRepository = (*RedisRepository)(nil) |
This file contains hidden or 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
func (repo *RedisRepository) Get(key string) (string, error) { | |
ctx := context.Background() | |
val, err := repo.client.Get(ctx, key).Result() | |
if err != nil { | |
return "", err | |
} | |
return val, nil | |
} | |
func (repo *RedisRepository) Set(key, value string) error { |
This file contains hidden or 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
type RedisRepository struct { | |
client goRedis.Client | |
} | |
func NewRedisRepository(address, password string) RedisRepository { | |
return RedisRepository{ | |
client: *goRedis.NewClient(&goRedis.Options{ | |
Addr: address, | |
Password: password, | |
}), |
This file contains hidden or 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
type RedisRepository interface { | |
Get(key string) (string, error) | |
Set(key, value string) error | |
} |
This file contains hidden or 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
def fromStorage_toPostgres(table, main_query, additional_query, file, columns, pg_connection, **args): | |
import urllib.request | |
import psycopg2 | |
# connect to the PostgreSQL database | |
conn_info = BaseHook.get_connection(pg_connection) | |
conn = psycopg2.connect(host=conn_info.host, | |
database=conn_info.schema, | |
user=conn_info.login, | |
password=conn_info.password) |
This file contains hidden or 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
task_merge_gs_files = PythonOperator( | |
task_id='merge_gs_file_task', | |
trigger_rule=TriggerRule.ALL_SUCCESS, | |
python_callable=compose_file, | |
op_args=[ "INSERT FIRST FUNCTION ARG", "INSERT FIRST FUNCTION ARG", ], | |
provide_context=True, | |
dag=dag) |
This file contains hidden or 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
task_export_bq_data_to_storage = BigQueryToCloudStorageOperator( | |
dag=dag, | |
task_id='export_bq_data_to_storage_task', | |
trigger_rule=TriggerRule.ONE_SUCCESS, | |
source_project_dataset_table='INSERT BQ SOURCE TABLE HERE', | |
destination_cloud_storage_uris=['gs://' + bucket_name + '/' + file_name + '-*'], | |
export_format='CSV', | |
field_delimiter=csv_delimiter, | |
print_header=True) |
NewerOlder