示例#1
0
        public async Task BasicTest()
        {
            IDbStore columnFamilyDbStore = this.rocksDbStoreProvider.GetColumnStoreFamily("test");

            string key   = "key1";
            string value = "value1";

            byte[] keyBytes   = key.ToBytes();
            byte[] valueBytes = value.ToBytes();
            await columnFamilyDbStore.Put(keyBytes, valueBytes);

            Option <byte[]> returnedValueBytesOption = await columnFamilyDbStore.Get(keyBytes);

            Assert.True(returnedValueBytesOption.HasValue);
            byte[] returnedValueBytes = returnedValueBytesOption.OrDefault();
            Assert.True(valueBytes.SequenceEqual(returnedValueBytes));
            Assert.Equal(value, returnedValueBytes.FromBytes());
            Assert.True(await columnFamilyDbStore.Contains(keyBytes));
            Assert.False(await columnFamilyDbStore.Contains("key2".ToBytes()));

            await columnFamilyDbStore.Remove(keyBytes);

            returnedValueBytesOption = await columnFamilyDbStore.Get(keyBytes);

            Assert.False(returnedValueBytesOption.HasValue);
        }
示例#2
0
        public async Task GetRemoveDefaultPartitionTestAsync()
        {
            var options = new RocksDbOptionsProvider(new SystemEnvironment(), true);

            var partitionsList = new[]
            {
                "Partition1"
            };

            using (IDbStoreProvider rocksDbStoreProvider = DbStoreProvider.Create(options, this.rocksDbFolder, partitionsList))
            {
                Assert.NotNull(rocksDbStoreProvider);

                IDbStore store = rocksDbStoreProvider.GetDbStore();

                string key      = "key";
                string val      = "val";
                byte[] valBytes = val.ToBytes();
                await store.Put(key.ToBytes(), valBytes);

                Option <byte[]> valRetrieved = await store.Get("key".ToBytes());

                byte[] valRetrievedBytes = valRetrieved.GetOrElse(string.Empty.ToBytes());
                Assert.True(valRetrievedBytes.SequenceEqual(valBytes));
            }
        }
示例#3
0
        public Task <TRole> FindByIdAsync(string roleId, CancellationToken cancellationToken = new CancellationToken())
        {
            cancellationToken.ThrowIfCancellationRequested();

            if (roleId == null)
            {
                throw new ArgumentNullException(nameof(roleId));
            }

            return(Task.FromResult(_dbStore.Get <TRole>(ConvertIdFromString(roleId))));
        }
示例#4
0
 public static T GetIf <T>(this IDbStore dbStore, object id)
     where T : IEntity
 {
     return(id == null ? default(T) : dbStore.Get <T>(id));
 }
示例#5
0
 public T Get <T>(object id) where T : IEntity
 {
     return(_dbStore.Get <T>(id));
 }