Exemple #1
0
        public async Task <URL> GetByIdAsync(ShortURL id)
        {
            string key   = id.ToString();
            string value = await _redisDB.StringGetAsync(key);

            return(new URL(value, id));
        }
        public async Task <string> CreateURLAsync(string extendedURL)
        {
            Guard.Against.NullOrEmpty(extendedURL, "URL value");
            Guard.Against.OutOfRange(extendedURL.Length, "URL value", 1, _config.MaxURLChars);
            string res = null;

            try {
                ShortURL surl = ShortURL.ComputeShortURLFromExtendedURL(extendedURL);
                if (!await _urlRepository.ExistsAsync(surl))
                {
                    URL newURL = new URL(extendedURL, surl);
                    await _urlRepository.AddAsync(newURL);
                }

                res = RemoveBase64Strings(surl.ToString());
            } catch (Exception excp) {
                _logger.LogError(excp, $"Error creating url with value: {extendedURL}.");
            }
            return(res);
        }
Exemple #3
0
 public async Task <bool> ExistsAsync(ShortURL id)
 {
     return(await _redisDB.KeyExistsAsync(id.ToString()));
 }
Exemple #4
0
 public void DeleteFireAndForget(ShortURL entity)
 {
     _redisDB.KeyDelete(entity.ToString(), flags: CommandFlags.FireAndForget);
 }