import redis
import time
import sys
def main():
print("🔥 Ignix Python Client Example")
print("=" * 40)
try:
print("Connecting to Ignix server at localhost:7379...")
client = redis.Redis(
host='localhost',
port=7379,
decode_responses=True, socket_connect_timeout=5,
socket_timeout=5
)
print("Testing connection...")
response = client.ping()
print(f"PING response: {response}")
print("\n📝 Basic Operations:")
print("-" * 20)
print("Setting key 'hello' to 'world'...")
client.set('hello', 'world')
print("✅ SET hello world")
value = client.get('hello')
print(f"✅ GET hello: {value}")
exists = client.exists('hello')
print(f"✅ EXISTS hello: {exists}")
client.set('counter', 0)
client.set('user:1:name', 'Alice')
client.set('user:1:age', 25)
print("\n🔢 Counter Operations:")
print("-" * 25)
for i in range(5):
counter = client.incr('counter')
print(f"✅ INCR counter: {counter}")
time.sleep(0.1)
print("\n👤 User Data:")
print("-" * 15)
name = client.get('user:1:name')
age = client.get('user:1:age')
print(f"✅ User: {name}, Age: {age}")
print("\n🗂️ Bulk Operations:")
print("-" * 20)
client.mset({
'fruit:1': 'apple',
'fruit:2': 'banana',
'fruit:3': 'orange'
})
print("✅ MSET fruit:1=apple, fruit:2=banana, fruit:3=orange")
fruits = client.mget(['fruit:1', 'fruit:2', 'fruit:3'])
print(f"✅ MGET fruits: {fruits}")
print("\n🔄 Key Management:")
print("-" * 20)
client.rename('hello', 'greeting')
print("✅ RENAME hello -> greeting")
old_exists = client.exists('hello')
new_exists = client.exists('greeting')
new_value = client.get('greeting')
print(f"✅ hello exists: {old_exists}, greeting exists: {new_exists}, value: {new_value}")
deleted = client.delete('greeting')
print(f"✅ DEL greeting: {deleted} key(s) deleted")
print("\n📊 Statistics:")
print("-" * 15)
all_keys = client.keys('*')
print(f"✅ Total keys: {len(all_keys)}")
print(f"✅ Keys: {all_keys}")
print("\n✅ All operations completed successfully!")
except redis.ConnectionError as e:
print(f"❌ Connection Error: {e}")
print("Make sure Ignix server is running: cargo run --release")
sys.exit(1)
except redis.RedisError as e:
print(f"❌ Redis Error: {e}")
sys.exit(1)
except Exception as e:
print(f"❌ Unexpected Error: {e}")
sys.exit(1)
if __name__ == "__main__":
main()