1 module konnexengine.db.redis.redis; 2 3 import vibe.db.redis.redis: connectRedis, RedisClient, RedisDatabase; 4 import vibe.db.redis.types; 5 6 /// struct RedisInstance 7 struct RedisInstance 8 { 9 string url; 10 long db; 11 string password; 12 } 13 14 /// struct RedisHash 15 struct RedisHashEntry 16 { 17 this(RedisDatabase d, string k, string f, RedisValue v) 18 { 19 this.db = d; 20 this.key = k; 21 this.field = f; 22 this.entry.value = v; 23 } 24 25 RedisDatabase db; 26 string key; 27 string field; 28 auto entry = RedisHash!string(); 29 } 30 31 /** 32 33 */ 34 RedisClient connect(T)(T t) 35 { 36 return connectRedis(t.url).getDatabase(t.db); 37 } 38 /// 39 unittest 40 { 41 42 } 43 44 45 /** 46 Template function - 47 ```dlang 48 void persist(T)(T t) 49 ``` 50 */ 51 void persist(T)(T t) 52 { 53 t.db.hset(t.key, t.field, t.entry.value); 54 } 55 /// 56 unittest 57 { 58 // string key = "User"; 59 // string field = "email"; 60 // auto db = connectRedis("127.0.0.1").getDatabase(0); 61 // auto entry = RedisHash!string(db, key); 62 // entry.value = RedisValue(db, key); 63 // auto rhe = RedisHashEntry(entry.key, field, entry.value); 64 // assert(persist!RedisHashEntry(rhe)); 65 }