You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.2 KiB
Python

3 months ago
from redis import Redis
import json
redisCred = {"host": "192.168.0.27", "port": 30036, "password": "bignigga123"}
def redis_gen_connection():
return Redis(host=redisCred["host"], port=redisCred["port"], password=redisCred["password"])
def connect_redis():
REDIS_HOST = "192.168.0.27"
REDIS_PORT = 30036
REDIS_PASSWORD = "bignigga123"
try:
client = Redis(
host=REDIS_HOST,
port=REDIS_PORT,
password=REDIS_PASSWORD,
decode_responses=True
)
response = client.ping()
if response:
print("Connected to Redis successfully!")
return client
else:
print("Failed to connect to Redis!")
return None
except Exception as e:
print(f"An error occurred: {e}")
return None
def get_streamer_data(username):
try:
redis_client = redis_gen_connection()
streamer_data = redis_client.hget("streamers", username)
if streamer_data is None:
return None
streamer_data = json.loads(streamer_data)
return streamer_data
except Exception as e:
print(f"Unexpected error: {e}")
return None