Пример #1
0
 public T Get(TKey key)
 {
     byte[] obj;
     if (_tx.TryGet(_db, _settings.SerializeKey(key), out obj))
     {
         return(_settings.Deserialize(obj));
     }
     else
     {
         return(default(T));
     }
 }
Пример #2
0
        public static bool TryGet(this LightningTransaction tx, LightningDatabase db, string key, out string value)
        {
            var enc = System.Text.Encoding.UTF8;

            byte[] result;
            var    found = tx.TryGet(db, enc.GetBytes(key), out result);

            value = enc.GetString(result);
            return(found);
        }
Пример #3
0
        public void TryGetShouldReturnValueIfKeyExists()
        {
            var key   = "key";
            var value = "value";

            _txn.Put(_db, key, value);

            string persistedValue;
            var    exists = _txn.TryGet(_db, key, out persistedValue);

            Assert.True(exists);
            Assert.Equal(value, persistedValue);
        }
Пример #4
0
        public void TryGetShouldReturnValueIfKeyExists()
        {
            var key   = "key";
            var value = 25;

            _txn.Put(_db, key, value);

            int persistedValue;
            var exists = _txn.TryGet(_db, key, out persistedValue);

            Assert.IsTrue(exists);
            Assert.AreEqual(value, persistedValue);
        }
Пример #5
0
 public static bool GetVulnerability(string id, out OSSIndexVulnerability v)
 {
     if (!Environment.IsOpened)
     {
         Environment.MapSize = 2L * 1024L * 1024L * 1024L;
         Environment.Open(EnvironmentOpenFlags.None);
     }
     using (LightningTransaction tx = Environment.BeginTransaction(TransactionBeginFlags.ReadOnly))
     {
         LightningDatabase db  = tx.OpenDatabase();
         byte[]            ret = null;
         if (!tx.TryGet(db, Encoding.UTF8.GetBytes(id), out ret))
         {
             v = null;
             return(false);
         }
         else
         {
             v = JsonConvert.DeserializeObject <OSSIndexVulnerability>(Encoding.UTF8.GetString(ret));
             return(true);
         }
     }
 }