private IEnumerable <byte[]> GetBytesData() { using (var it = _levelDb.CreateIterator()) { for (it.SeekToFirst(); it.IsValid(); it.Next()) { var piece = new StringPiece(it.Key()); KeyPrefix prefix; ObjectStoreDataKey store; if (!KeyPrefix.Decode(piece, out prefix) || prefix.Type != KeyType.ObjectStoreData || !ObjectStoreDataKey.Decode(piece.Reset(), out store)) { continue; } var dataSlice = new StringPiece(it.Value()); long version; if (!dataSlice.DecodeVarInt(out version)) { continue; } yield return(dataSlice.ToSwappedArray()); } } }
public string GetValue(string key, string defaultValue = null, bool required = false) { var index = FindKeyIndex(key); if (index == -1) { if (required) { throw new ArgsException("Missing parameter " + KeyPrefix + key); } return(defaultValue); } if (_args.Count == index + 1) { if (required) { throw new ArgsException("Missing value for parameter " + KeyPrefix + key); } return(defaultValue); } var value = _args[index + 1]; if (value.StartsWith(KeyPrefix.ToString())) { return(defaultValue); } return(value); }
public override bool Equals(object obj) { if (obj == null || !(obj is SalesforceObjectType)) { return(false); } var salesforceObject = (SalesforceObjectType)obj; if (Name == null || salesforceObject.Name == null || !Name.Equals(salesforceObject.Name)) { return(false); } if (KeyPrefix == null || salesforceObject.KeyPrefix == null || !KeyPrefix.Equals(salesforceObject.KeyPrefix)) { return(false); } if (Label == null || salesforceObject.Label == null || !Label.Equals(salesforceObject.Label)) { return(false); } if (LabelPlural == null || salesforceObject.LabelPlural == null || !LabelPlural.Equals(salesforceObject.LabelPlural)) { return(false); } return(true); }
public void KeyComposition() { Key k1 = "test"; KeyPrefix p1 = new KeyPrefix("tenant", "region"); CacheKey cc = new CacheKey(p1, k1); Assert.True(cc.Prefix.Tenant == "tenant" && cc.Prefix.Region == "region" && cc.Suffix == "test"); CacheKey newcc = cc; Assert.True(newcc == cc); }
public RedisDb(IConnectionMultiplexer redis, string?keyPrefix = null) { Redis = redis; KeyPrefix = keyPrefix ?? ""; Database = Redis.GetDatabase(); if (!KeyPrefix.IsNullOrEmpty()) { Database = Database.WithKeyPrefix(KeyPrefix); } }
public void Affectation() { Key k1 = "ppppp"; KeyPrefix p1 = new KeyPrefix(Key.Null, "1651651645621"); CacheKey cc = new CacheKey(p1, k1); CacheKey affected = cc; Assert.True(cc == affected); var kv = new KeyValuePair<CacheKey, object>(affected, null); Assert.Equal(cc, kv.Key); }
public static bool Decode(StringPiece slice, out ObjectStoreNamesKey result) { KeyPrefix prefix; byte typeByte; if (!KeyPrefix.Decode(slice, out prefix) || !slice.DecodeByte(out typeByte)) { result = default(ObjectStoreNamesKey); return(false); } result = new ObjectStoreNamesKey(); return(slice.DecodeStringWithLength(out result._objectStoreName)); }
public static bool Decode(StringPiece slice, out DatabaseFreeListKey result) { KeyPrefix prefix; byte typeByte; if (!KeyPrefix.Decode(slice, out prefix) || !slice.DecodeByte(out typeByte)) { result = default(DatabaseFreeListKey); return(false); } result = new DatabaseFreeListKey(); return(slice.DecodeVarInt(out result.DatabaseId)); }
public static bool Decode(StringPiece slice, out IndexFreeListKey result) { KeyPrefix prefix; byte typeByte; if (!KeyPrefix.Decode(slice, out prefix) || !slice.DecodeByte(out typeByte)) { result = default(IndexFreeListKey); return(false); } result = new IndexFreeListKey(); return(slice.DecodeVarInt(out result.ObjectStoreId) && slice.DecodeVarInt(out result.IndexId)); }
public static bool Decode(StringPiece slice, out DatabaseNameKey result) { KeyPrefix prefix; byte typeByte; if (!KeyPrefix.Decode(slice, out prefix) || !slice.DecodeByte(out typeByte)) { result = default(DatabaseNameKey); return(false); } result = new DatabaseNameKey(); return(slice.DecodeStringWithLength(out result.Origin) && slice.DecodeStringWithLength(out result.DatabaseName)); }
public async Task PutGetStringRegionKeyValueAsync() { KeyPrefix prefix = new KeyPrefix(Key.Null, _keyString); Dictionary<CacheKey, string> dictionary = Enumerable.Range(0, 100) .ToDictionary(i => new CacheKey(prefix, i.ToString()), i => _dataString + i.ToString()); this._cache1.PutRegion(dictionary.ToArray()); var fetched = await this._cache2.GetRegionKeyValuesAsync<string>(prefix); Assert.Equal(dictionary.Count(), fetched.Count()); foreach (var kv in fetched) { Assert.Equal(dictionary[kv.Key], kv.Value); } }
/// <summary> /// 获取基元类型Key /// </summary> private static string GetStructKey(KeyPrefix keyPrefix, object obj) { IList <object> strList = new List <object>(); strList.Add(keyPrefix); if (obj != null) { if (!string.IsNullOrEmpty(obj.ToString())) { strList.Add(obj.ToString()); } } return(string.Join(CacheManager.MAIN_KEY_SPLIT_CHAR, strList)); }
/// <summary> /// 获取缓存过期时间 /// </summary> /// <param name="keyPrefix">前缀</param> /// <returns></returns> public static int GetExpiredMinute(KeyPrefix keyPrefix) { //最少给后端jobws 10分钟 int minute = GetMinute(keyPrefix.ToString()); if (minute > 10) { return(minute + DefaultMinute * 3); } else if (minute > 1) { return(minute + DefaultMinute * 2); } else { return(DefaultMinute); } }
public async Task PutGetStringRegionAsync() { KeyPrefix prefix = new KeyPrefix(Key.Null, _keyString); Dictionary<CacheKey, Serialized> dictionary = Enumerable.Range(0, 100) .ToDictionary(i => new CacheKey(prefix, i.ToString()), i => new Serialized { Id = i, Property = _dataString + i.ToString() }); this._cache1.PutRegion(dictionary.ToArray()); Func<Serialized, CacheKey> funk = s => new CacheKey(prefix, s.Id.ToString()); IEnumerable<Serialized> result = await this._cache2.GetRegionAsync(prefix, funk); var fetched = result.ToDictionary(funk); Assert.Equal(dictionary.Count(), fetched.Count()); foreach (var kv in fetched) { Assert.Equal(dictionary[kv.Key].Property, kv.Value.Property); } }
public static bool Decode(StringPiece slice, out ObjectStoreDataKey result) { KeyPrefix prefix; if (!KeyPrefix.Decode(slice, out prefix)) { result = default(ObjectStoreDataKey); return(false); } result = new ObjectStoreDataKey(); if (!ExtractEncodedIdbKey(slice, out result.EncodedUserKey)) { return(false); } return(true); }
/// <summary> /// 获取Key,一个object生成一个值 key。只要object的每个属性值都相同,生成的key就相同。 /// 特别注意object中的DateTime和Guid类型的属性,如果是通过DateTime.Now,Guid.NewGuid()赋值,每次key都会不同。 /// </summary> public static string GetValueKey <T>(KeyPrefix keyPrefix, T obj) { if (obj == null) { return(keyPrefix.ToString()); } if (default(T) == null) { if (obj.GetType() == typeof(string)) { return(GetStructKey(keyPrefix, obj)); } return(GetEntityKey(keyPrefix, obj)); } else { return(GetStructKey(keyPrefix, obj)); } }
public static bool Decode(StringPiece slice, out ObjectStoreMetaDataKey result) { KeyPrefix prefix; if (!KeyPrefix.Decode(slice, out prefix)) { result = default(ObjectStoreMetaDataKey); return(false); } if (slice.Empty) { result = default(ObjectStoreMetaDataKey); return(false); } slice.Next(); result = new ObjectStoreMetaDataKey(); return(slice.DecodeVarInt(out result.ObjectStoreId) && slice.DecodeByte(out result.MetaDataTypeValue)); }
/// <summary> /// 获取Key,一个object生成一个MD5 key。只要object的每个属性值都相同,生成的key就相同。 /// 特别注意object中的DateTime和Guid类型的属性,如果是通过DateTime.Now,Guid.NewGuid()赋值,每次key都会不同。 /// </summary> public static string GetMD5Key <T>(KeyPrefix keyPrefix, T obj) { //if (obj != null) //{ // SerializedType st = SerializedType.Object; // byte[] buffer = Serializer.Serialize(obj, out st, uint.MaxValue); // MD5 md5 = MD5CryptoServiceProvider.Create(); // buffer = md5.ComputeHash(buffer); // StringBuilder sb = new StringBuilder(); // sb.Append(keyPrefix); // sb.Append(CacheManager.MAIN_KEY_SPLIT_CHAR); // for (int i = 0; i < buffer.Length; i++) // { // sb.Append(buffer[i].ToString("x2")); // } // return sb.ToString(); //} //return keyPrefix.ToString(); throw new NotImplementedException(); }
/// <summary> /// 获取实体的Key /// </summary> private static string GetEntityKey <T>(KeyPrefix keyPrefix, T obj) { IList <object> strList = new List <object>(); strList.Add(keyPrefix); if (obj != null) { PropertyInfo[] properties = GetProperties <T>(); foreach (var p in properties) { object value = p.GetValue(obj, null); if (value != null) { strList.Add(value.ToString().Replace(CacheManager.MAIN_KEY_SPLIT_CHAR.ToString(), CacheManager.MAIN_KEY_SPLIT_CHAR.ToString() + CacheManager.MAIN_KEY_SPLIT_CHAR.ToString())); } else { strList.Add(string.Empty); } } } return(string.Join(CacheManager.MAIN_KEY_SPLIT_CHAR, strList)); }
// Use the hash code of the string objects and xor them together. public override int GetHashCode() { return((BaseName.GetHashCode() ^ KeyPrefix.GetHashCode()) ^ AssemblyFullName.GetHashCode()); }
public async Task CanRemoveRegion() { KeyPrefix prefix = new KeyPrefix(Key.Null, _keyString); Dictionary<CacheKey, string> dictionary = Enumerable.Range(0, 100) .ToDictionary(i => new CacheKey(prefix, i.ToString()), i => _dataString + i.ToString()); this._cache.PutRegion(dictionary.ToArray()); var fetched = await this._cache.GetRegionKeyValuesAsync<string>(prefix); Assert.Equal(dictionary.Count(), fetched.Count()); this._cache.RemoveRegion(prefix); IEnumerable<KeyValuePair<CacheKey, Serialized>> removed = await this._cache.GetRegionKeyValuesAsync<Serialized>(prefix); Assert.Empty(removed); }
public async Task PutGetSerializedRegionAsync() { KeyPrefix prefix = new KeyPrefix(Key.Null, _keyString); Dictionary<CacheKey, Serialized> dictionary = Enumerable.Range(0, 100) .ToDictionary(i => new CacheKey(prefix, i.ToString()), i => new Serialized { Property = _dataString + i.ToString() }); this._cache1.PutRegion(dictionary.ToArray()); var fetched = await this._cache2.GetRegionKeyValuesAsync<Serialized>(prefix); Assert.Equal(dictionary.Count(), fetched.Count()); foreach (var kv in fetched) { if (kv.Key.Suffix == "57") { ; } Assert.Equal(dictionary[kv.Key].Property, kv.Value.Property); } }
public void KeyPrefixTranstypeString() { KeyPrefix p1 = new KeyPrefix("test", Key.Null); Assert.True(p1.Tenant == "test"); }
public void KeyPrefixTenantTranstypeString() { KeyPrefix p1 = new KeyPrefix("tenant", "test"); Assert.True(p1.Tenant == "tenant" && p1.Region == "test"); }
// Use the hash code of the string objects and xor them together. public override int GetHashCode() { // ReSharper disable NonReadonlyMemberInGetHashCode return((BaseName.GetHashCode() ^ KeyPrefix.GetHashCode()) ^ AssemblyFullName.GetHashCode()); // ReSharper restore NonReadonlyMemberInGetHashCode }
public string FullKey(string keySuffix) => KeyPrefix.IsNullOrEmpty() ? keySuffix : keySuffix.IsNullOrEmpty() ? KeyPrefix : ZString.Concat(KeyPrefix, '.', keySuffix);
// https://cs.chromium.org/chromium/src/content/browser/indexed_db/indexed_db_database_callbacks.cc private static int Compare(StringPiece a, StringPiece b, bool onlyCompareIndexKeys) { var sliceA = a.Fork(); var sliceB = b.Fork(); KeyPrefix prefixA, prefixB; if (!KeyPrefix.Decode(sliceA, out prefixA) || !KeyPrefix.Decode(sliceB, out prefixB)) { return(0); } { var x = prefixA.CompareTo(prefixB); if (x != 0) { return(x); } } switch (prefixA.Type) { case KeyType.GlobalMetadata: { if (sliceA.Empty || sliceB.Empty) { return(0); } var typeByteA = sliceA.Next(); var typeByteB = sliceB.Next(); { var x = typeByteA - typeByteB; if (x != 0) { return(x); } } if (typeByteA < KMaxSimpleGlobalMetaDataTypeByte) { return(0); } // Compare<> is used (which re-decodes the prefix) rather than an // specialized CompareSuffix<> because metadata is relatively uncommon // in the database. switch (typeByteA) { case KDatabaseFreeListTypeByte: return(DatabaseFreeListKey.Compare(a, b)); case KDatabaseNameTypeByte: return(DatabaseNameKey.Compare(a, b)); } break; } case KeyType.DatabaseMetadata: { if (sliceA.Empty || sliceB.Empty) { return(0); } var typeByteA = sliceA.Next(); var typeByteB = sliceB.Next(); { var x = typeByteA - typeByteB; if (x != 0) { return(x); } } if (typeByteA < (int)MetaDataType.MaxSimpleMetadataType) { return(0); } switch (typeByteA) { case KObjectStoreMetaDataTypeByte: return(ObjectStoreMetaDataKey.Compare(a, b)); case KIndexMetaDataTypeByte: return(IndexMetaDataKey.Compare(a, b)); case KObjectStoreNamesTypeByte: return(ObjectStoreNamesKey.Compare(a, b)); case KObjectStoreFreeListTypeByte: return(ObjectStoreFreeListKey.Compare(a, b)); case KIndexFreeListTypeByte: return(IndexFreeListKey.Compare(a, b)); case KIndexNamesKeyTypeByte: return(IndexNamesKey.Compare(a, b)); } break; } case KeyType.ObjectStoreData: return(sliceA.Empty || sliceB.Empty ? CompareSizes(sliceA.Left, sliceB.Left) : ObjectStoreDataKey.CompareSuffix(sliceA, sliceB)); case KeyType.ExistsEntry: return(sliceA.Empty || sliceB.Empty ? CompareSizes(sliceA.Left, sliceB.Left) : ExistsEntryKey.CompareSuffix(sliceA, sliceB)); case KeyType.BlobEntry: return(sliceA.Empty || sliceB.Empty ? CompareSizes(sliceA.Left, sliceB.Left) : BlobEntryKey.CompareSuffix(sliceA, sliceB)); case KeyType.IndexData: return(sliceA.Empty || sliceB.Empty ? CompareSizes(sliceA.Left, sliceB.Left) : IndexDataKey.CompareSuffix(sliceA, sliceB, onlyCompareIndexKeys)); case KeyType.InvalidType: break; } return(0); }