-
Notifications
You must be signed in to change notification settings - Fork 0
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 #469 from softeerbootcamp-2nd/refactor/cache-enhance
[FEAT] #225: DataFrame 캐싱을 통한 성능향상 시도
- Loading branch information
Showing
4 changed files
with
48 additions
and
19 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import io | ||
import redis | ||
import pandas as pd | ||
import os | ||
|
||
redis_pool = redis.ConnectionPool(host=os.getenv('redis_host'), port=6379, password=os.getenv('redis_password'), db=0) | ||
|
||
def redis_getData(): | ||
with redis.StrictRedis(connection_pool=redis_pool) as conn: | ||
bytes_object = conn.get("rec_dataframe") | ||
if bytes_object is None: | ||
return None | ||
buffer = io.BytesIO(bytes_object) | ||
return pd.read_pickle(buffer) | ||
|
||
def redis_setData(df): | ||
with redis.StrictRedis(connection_pool=redis_pool) as conn: | ||
buffer = io.BytesIO() | ||
df.to_pickle(buffer) | ||
buffer.seek(0) | ||
bytes_object = buffer.read() | ||
conn.set('rec_dataframe', bytes_object, 60*60*24*7) |