public async void Expire() { var add = await DB.Set("mykey", "hello"); Write(add); var expire = await DB.Expire("mykey", 10); Write(expire); var ttl = await DB.Ttl("mykey"); Write(ttl); add = await DB.Set("mykey", "hello world"); Write(add); ttl = await DB.Ttl("mykey"); Write(ttl); }
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); }