public ShipRepository() { var db = new RedisDB { DataFormater = new JsonFormater() }; db.Host.AddWriteHost("localhost"); _table = db.CreateHashTable("ships"); }
public async Task <(UserSession, bool)> CreateSession(UserSession userSession, int ttlInSeconds) { var sessionIdKey = RedisKeysPrefixes.SESSION + ":" + userSession.SessionId.ToString(); var table = _redisDB.CreateHashTable(sessionIdKey); var sessions = await _redisDB.MGet(new string[] { sessionIdKey }, new Type[] { typeof(UserSession) }); if (sessions.Where(s => s != null).Count() == 0) { await table.MSet((sessionIdKey, userSession)); await _redisDB.Expire(sessionIdKey, ttlInSeconds); } else { // throw new AlreadyExistsException(); // Not specified behavior at this scenario. return(null, false); } return(userSession, true); }
static async Task Main(string[] args) { var DB = new RedisDB(1) { DataFormater = new JsonFormater() }; //DefaultRedis.Instance.Host // .AddWriteHost("redisServer") // .Password = "******"; //DefaultRedis.Instance.DataFormater = new JsonFormater(); //var DB = DefaultRedis.Instance; DB.Host.AddWriteHost("redisServer"); var table = DB.CreateHashTable("beetle:experiment"); var result = await table.MSet(("field1", Employee.Employee1), ("field2", Employee.Employee2)); var employees = await table.Get <Employee, Employee>("field1", "field2"); await table.Del("emp2"); await table.Keys(); }
public async void HDel() { await DB.Flushall(); var table = DB.CreateHashTable("myhash"); Write(await table.MSet(("emp1", GetEmployee(1)))); Write(await table.Del("emp1")); Write(await table.Del("emp2")); Write(await table.Len()); }
public async void HDel() { await DB.Flushall(); var table = DB.CreateHashTable("myhash"); var mset = await table.MSet(("field1", "foo")); Write(mset); var del = await table.Del("field1"); Write(del); del = await table.Del("field2"); Write(del); }