-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_clan_leader.py
32 lines (26 loc) · 981 Bytes
/
update_clan_leader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import pymysql
import redis
from mysqlcursor import cur, con
# Initialize Redis client
redis_client = redis.Redis(host='localhost', port=6379, db=0)
def option_10():
"This is to update Clan-Leader of a Clan in the Game"
try:
row = {}
# Input Clan_ID and ClanLeader_ID
Clan_ID = input("Enter Clan ID: ")
ClanLeader_ID = input("Enter Clan Leader ID: ")
# Execute the update query
query = f"UPDATE Clans SET ClanLeader_ID = '{ClanLeader_ID}' WHERE Clan_ID = '{Clan_ID}'"
cur.execute(query)
con.commit()
print("Updated in database")
# Invalidate cache for the updated Clan ID
cache_key = f"clan:{Clan_ID}"
if redis_client.exists(cache_key):
redis_client.delete(cache_key)
print("Cache invalidated for Clan ID:", Clan_ID)
except Exception as e:
con.rollback()
print("Failed to update in database")
print(">>>>>>>>>>>>>", e)