clean cache data
This commit is contained in:
@@ -27,6 +27,10 @@ class BaseService:
|
||||
SEND_EMAIL_PASS = Config.SEND_EMAIL_PASS
|
||||
THIS_SITE_URL = Config.THIS_SITE_URL
|
||||
|
||||
CACHE_SERVER = Config.CACHE_SERVER
|
||||
CACHE_PORT = Config.CACHE_PORT
|
||||
CACHE_PASSWORD = Config.CACHE_PASSWORD
|
||||
|
||||
@staticmethod
|
||||
def addStripeCustomer(customerData):
|
||||
customer_data = {
|
||||
@@ -391,39 +395,21 @@ class BaseService:
|
||||
def write_cache_data(cacheSection, cacheId, cacheData):
|
||||
|
||||
try:
|
||||
cacheKey = cacheSection + ':' + cacheId
|
||||
cacheKey = cacheSection + '-' + cacheId
|
||||
logger.info(f"write_cache_data () key {cacheKey}", exc_info=True)
|
||||
# Define connection parameters and connect
|
||||
r = redis.Redis(host='10.10.33.35', port=6378,
|
||||
password='7f079034e166ecf52d82cbec9876e4dc8a154b0c37248f3fa1734d4eeab938d5',
|
||||
r = redis.Redis(host=BaseService.CACHE_SERVER, port=BaseService.CACHE_PORT,
|
||||
password=BaseService.CACHE_PASSWORD,
|
||||
decode_responses=True)
|
||||
|
||||
# Set a key 'foo' with value 'bar'
|
||||
json_string = json.dumps(cacheData, indent=4)
|
||||
r.set(cacheKey, json_string)
|
||||
r.set(cacheKey, json_string, ex=120)
|
||||
|
||||
# Verify by getting the value
|
||||
value = r.get(cacheKey)
|
||||
print(f"Value of {cacheKey}: {value}") # Output: Value of 'foo': bar
|
||||
|
||||
# Store a user session as a hash
|
||||
# user_data = {
|
||||
# 'name': 'John',
|
||||
# 'surname': 'Smith',
|
||||
# 'company': 'Redis',
|
||||
# 'age': 29
|
||||
# }
|
||||
# json_string = json.dumps(cacheData, indent=4)
|
||||
#
|
||||
# r.set(cacheSection + ':user-session:123', json_string)
|
||||
|
||||
# r.hset(cacheSection +':user-session:123', mapping=json_string)
|
||||
|
||||
# Retrieve all fields of the hash
|
||||
# session_details = r.hgetall('user-session:123')
|
||||
# print(f"Session details: {session_details}")
|
||||
# Output: Session details: {'name': 'John', 'surname': 'Smith', 'company': 'Redis', 'age': '29'}
|
||||
|
||||
response_data = {
|
||||
"session_details": value,
|
||||
# "product_id": product_id,
|
||||
|
||||
Reference in New Issue
Block a user