public async Task RestoreSetTest() { // Add items to restore to Redis var firstKey = new RedisKeyObject() { Prefix = "TestSetForDelete", Id = "1" }; var secondKey = new RedisKeyObject() { Prefix = "TestSetForDelete", Id = "1", }; var entry1 = new SortedSetEntry("testValueOne", 12384828182L); var entry2 = new SortedSetEntry("testValueTwo", 12357263237L); await _tableRedisBackup.AddSetItemAsync(firstKey, entry1); await _tableRedisBackup.AddSetItemAsync(secondKey, entry2); await _tableRedisBackup.RestoreSetAsync(_database, firstKey); // Clean Up await _tableRedisBackup.DeleteSetAsync(firstKey); }
public async Task AddSetItemTests() { var firstKey = new RedisKeyObject() { Prefix = "TestSet", Id = "1" }; var secondKey = new RedisKeyObject() { Prefix = "TestSet2", Id = "2", Suffix = "TestSuffix" }; var entry1 = new SortedSetEntry("testValueOne", 12384828182L); var entry2 = new SortedSetEntry("testValueTwo", 12357263237L); await _tableRedisBackup.AddSetItemAsync(firstKey, entry1); await _tableRedisBackup.AddSetItemAsync(secondKey, entry2); // Clean Up await _tableRedisBackup.DeleteSetItemAsync(firstKey, entry1.Score); await _tableRedisBackup.DeleteSetItemAsync(secondKey, entry2.Score); }
private void ReadFields(IndexInput meta /*, FieldInfos infos // LUCENENET: Not read */) { int fieldNumber = meta.ReadVInt32(); while (fieldNumber != -1) { // check should be: infos.fieldInfo(fieldNumber) != null, which incorporates negative check // but docvalues updates are currently buggy here (loading extra stuff, etc): LUCENE-5616 if (fieldNumber < 0) { // trickier to validate more: because we re-use for norms, because we use multiple entries // for "composite" types like sortedset, etc. throw new Exception("Invalid field number: " + fieldNumber + " (resource=" + meta + ")"); } byte type = meta.ReadByte(); if (type == Lucene45DocValuesFormat.NUMERIC) { numerics[fieldNumber] = ReadNumericEntry(meta); } else if (type == Lucene45DocValuesFormat.BINARY) { BinaryEntry b = ReadBinaryEntry(meta); binaries[fieldNumber] = b; } else if (type == Lucene45DocValuesFormat.SORTED) { ReadSortedField(fieldNumber, meta /*, infos // LUCENENET: Never read */); } else if (type == Lucene45DocValuesFormat.SORTED_SET) { SortedSetEntry ss = ReadSortedSetEntry(meta); sortedSets[fieldNumber] = ss; if (ss.Format == Lucene45DocValuesConsumer.SORTED_SET_WITH_ADDRESSES) { ReadSortedSetFieldWithAddresses(fieldNumber, meta /*, infos // LUCENENET: Never read */); } else if (ss.Format == Lucene45DocValuesConsumer.SORTED_SET_SINGLE_VALUED_SORTED) { if (meta.ReadVInt32() != fieldNumber) { throw new Exception("sortedset entry for field: " + fieldNumber + " is corrupt (resource=" + meta + ")"); } if (meta.ReadByte() != Lucene45DocValuesFormat.SORTED) { throw new Exception("sortedset entry for field: " + fieldNumber + " is corrupt (resource=" + meta + ")"); } ReadSortedField(fieldNumber, meta /*, infos // LUCENENET: Never read */); } else { throw new Exception(); } } else { throw new Exception("invalid type: " + type + ", resource=" + meta); } fieldNumber = meta.ReadVInt32(); } }
static async Task Main(string[] args) { IDatabase redis = await GetRedis(); //Create data that will store in Redis var pastDateTimeTicks = DateTime.UtcNow.AddYears(-10).Ticks; SortedSetEntry sortedSetPastEntry = new SortedSetEntry("My past data", pastDateTimeTicks); var presentDateTimeTicks = DateTime.UtcNow.Ticks; SortedSetEntry sortedSetPresentEntry = new SortedSetEntry("My present data", presentDateTimeTicks); var futureDateTimeTicks = DateTime.UtcNow.AddYears(10).Ticks; SortedSetEntry sortedSetFutureEntry = new SortedSetEntry("My future data", futureDateTimeTicks); //Save to Redis await redis.SortedSetAddAsync(CACHE_KEY, new SortedSetEntry[] { sortedSetPastEntry, sortedSetPresentEntry, sortedSetFutureEntry }); //Get only past data with score var pastDateTicks = DateTime.UtcNow.AddDays(-1).Ticks; var pastData = await redis.SortedSetRangeByScoreAsync(CACHE_KEY, stop : pastDateTicks); //Get only present data with score var startDateTicks = DateTime.UtcNow.AddDays(-1).Ticks; var stoptDateTicks = DateTime.UtcNow.AddDays(1).Ticks; var presentData = await redis.SortedSetRangeByScoreAsync(CACHE_KEY, start : startDateTicks, stop : stoptDateTicks); //Get only future data with score var currentDateTicks = DateTime.UtcNow.AddHours(1).Ticks; var futureData = await redis.SortedSetRangeByScoreAsync(CACHE_KEY, start : currentDateTicks); //Remove past and present data var removeDateTicks = DateTime.UtcNow.AddYears(1).Ticks; await redis.SortedSetRemoveRangeByScoreAsync(CACHE_KEY, start : double.NegativeInfinity, stop : removeDateTicks); }
public void SetBathScore(long companyID, List <long> lstProductIDUpdate, int score) { while (true) { try { if (lstProductIDUpdate.Count > 0) { foreach (var lstProductBath in QT.Entities.Common.SplitArray <long>(lstProductIDUpdate.ToArray(), 100)) { SortedSetEntry[] arSortedSetEntry = new SortedSetEntry[lstProductBath.Count]; for (int i = 0; i < lstProductBath.Count; i++) { arSortedSetEntry[i] = new SortedSetEntry(lstProductBath[i], score); } database.SortedSetAdd("cp:" + companyID, arSortedSetEntry); } break; } } catch (Exception ex01) { log.Error(ex01); Thread.Sleep(10000); } } }
public void StoreResultValue(DateTime period, double value) { var score = (double)period.Ticks; SortedSetEntry sse = new SortedSetEntry(value, score); RedisClient.Current.Database.SortedSetAdd(ValuesKey, new[] { sse }); }
public RandomAccessOrdsAnonymousClass(SortedSetEntry entry, NumericDocValues docToOrdAddress, NumericDocValues ords, BinaryDocValues values) { this.entry = entry; this.docToOrdAddress = docToOrdAddress; this.ords = ords; this.values = values; }
public RandomAccessOrdsAnonymousInnerClassHelper(DirectDocValuesProducer outerInstance, SortedSetEntry entry, NumericDocValues docToOrdAddress, NumericDocValues ords, BinaryDocValues values) { this.entry = entry; this.docToOrdAddress = docToOrdAddress; this.ords = ords; this.values = values; }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: @Override public synchronized index.SortedSetDocValues getSortedSet(index.FieldInfo field) throws java.io.IOException public override SortedSetDocValues getSortedSet(FieldInfo field) { lock (this) { SortedSetRawValues instance = sortedSetInstances[field.number]; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final SortedSetEntry entry = sortedSets.get(field.number); SortedSetEntry entry = sortedSets[field.number]; if (instance == null) { // Lazy load instance = loadSortedSet(entry); sortedSetInstances[field.number] = instance; } //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final index.NumericDocValues docToOrdAddress = instance.docToOrdAddress; NumericDocValues docToOrdAddress = instance.docToOrdAddress; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final index.NumericDocValues ords = instance.ords; NumericDocValues ords = instance.ords; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final index.BinaryDocValues values = instance.values; BinaryDocValues values = instance.values; // Must make a new instance since the iterator has state: return(new RandomAccessOrdsAnonymousInnerClassHelper(this, entry, docToOrdAddress, ords, values)); } }
/// <summary> /// Zset 批量添加 /// </summary> /// <param name="key"></param> /// <param name="values"></param> /// <returns></returns> public bool AddZsetAsync(string key, List <KeyValuePair <long, string> > values) { Count = 0; try { using (var client = ConnectionMultiplexer.Connect(Profile.redisIp + ",abortConnect=false")) { var cv = client.GetDatabase(); SortedSetEntry[] entryArray = new SortedSetEntry[values.Count]; for (int i = 0; i < values.Count; i++) { entryArray[i] = new SortedSetEntry(values[i].Value, values[i].Key); } var result = cv.SortedSetAddAsync(key, entryArray); } } catch (Exception ex) { Logger.Error(ex); Message = ex.Message; Code = ErrorCode.ReadRedisErrorCode; Sucess = false; } return(Sucess); }
public void StoreResult(TimePeriod period, double value) { var key = string.Format("persistent-metric|{0}|{1}", Name, period.ToString()); var score = (double)period.StandardizeDate(DateTime.UtcNow).Ticks; SortedSetEntry sse = new SortedSetEntry(value, score); RedisClient.Current.Database.SortedSetAdd(key, new[] { sse }); }
private static SortedSetEntry ReadSortedSetEntry(IndexInput meta) // LUCENENET: CA1822: Mark members as static { var entry = new SortedSetEntry(); entry.docToOrdAddress = ReadNumericEntry(meta); entry.ords = ReadNumericEntry(meta); entry.values = ReadBinaryEntry(meta); return(entry); }
private SortedSetEntry ReadSortedSetEntry(IndexInput meta) { var entry = new SortedSetEntry(); entry.docToOrdAddress = ReadNumericEntry(meta); entry.ords = ReadNumericEntry(meta); entry.values = ReadBinaryEntry(meta); return(entry); }
internal void ZAdd(string key, params Tuple <double, string>[] memberScores) { SortedSetEntry[] entries = new SortedSetEntry[memberScores.Length]; for (int i = 0; i < memberScores.Length; ++i) { entries[i] = new SortedSetEntry(memberScores[i].Item2, memberScores[i].Item1); } DB.SortedSetAdd(key, entries); }
private SortedSetRawValues LoadSortedSet(SortedSetEntry entry) { var instance = new SortedSetRawValues(); instance.docToOrdAddress = LoadNumeric(entry.docToOrdAddress); instance.ords = LoadNumeric(entry.ords); instance.values = LoadBinary(entry.values); return(instance); }
/// fill out all rank redis cache from db /// @todo: huge amount of data processing - split 10,000 or ... /// dt.Rows check. if bigger than 10,000, seperate as another loop /// dt.Rows / 10,000 = mod value + 1 = loop count........... /// call count query first and then paging processing at query side to prevent DB throttling? public static bool FillAllRankFromDB() { try { // redis connection ConnectionMultiplexer connection = ConnectionMultiplexer.Connect(redisConnectionStringRank); IDatabase cache = connection.GetDatabase(1); // delete rank sorted set - caution. this process remove all rank set data cache.KeyDelete(globalVal.CloudBreadRankSortedSet); // data table fill for easy count number RetryPolicy retryPolicy = new RetryPolicy <SqlAzureTransientErrorDetectionStrategy>(globalVal.conRetryCount, TimeSpan.FromSeconds(globalVal.conRetryFromSeconds)); SqlConnection conn = new SqlConnection(globalVal.DBConnectionString); conn.Open(); string strQuery = "SELECT MemberID, CaptianChange, LastWorld FROM DWMembers"; SqlCommand command = new SqlCommand(strQuery, conn); DataTable dt = new DataTable(); using (SqlDataAdapter da = new SqlDataAdapter(command)) { da.Fill(dt); } /// make SortedSetEntry to fill out SortedSetEntry[] sse = new SortedSetEntry[dt.Rows.Count + 1]; Int64 i = 0; foreach (DataRow dr in dt.Rows) { string id = (string)dr[0]; long captianChange = (long)dr[1]; short lastWorld = (short)dr[2]; // fill rank row to redis struct array sse[i] = new SortedSetEntry(id, DWMemberData.GetPoint(lastWorld, captianChange)); i++; } // 무조건 -1.0점 유저를 넣어서 Rank의 카운트를 얻어온다 sse[i] = new SortedSetEntry(EMPTY_USER, -1.0); // fill out all rank data cache.SortedSetAdd(globalVal.CloudBreadRankSortedSet, sse); connection.Close(); connection.Dispose(); return(true); } catch (Exception) { throw; } }
/// <summary> /// Caches all the meta categories and values. /// </summary> private void CacheMetaContext() { //metaCategory->(meta value->score) var metaCategoryScores = base.GetMetaValuesWithScores(); foreach (var categoryPair in metaCategoryScores) { var categoryId = categoryPair.Key; var categoryKey = $"{Prefix}:_m:{categoryId}"; foreach (var val in categoryPair.Value) { var fullKey = $"{categoryKey}:{val.Key}"; var cntHash = new HashEntry("count", val.Value.Count); var scoreHash = new HashEntry("score", val.Value.Value); _cacher.SetHash(fullKey, cntHash); _cacher.SetHash(fullKey, scoreHash); } } //metaCategory->(metaValue->element set) var metaCategoryValueSets = base.GetEntityMetaValues(); foreach (var categoryPair in metaCategoryValueSets) { uint categoryId = categoryPair.Key; var categoryKey = $"{Prefix}:_mv:{categoryId}"; var categoryValues = categoryPair.Value; foreach (var metaVal in categoryValues) { var isSorted = SetIsSorted(categoryId, metaVal.Key); var fullKey = $"{categoryKey}:{metaVal.Key}"; var set = metaVal.Value; if (isSorted) { //Generate scores from x _cacher.SortedSetAddAll(fullKey, set.Select(x => { double score = 0; try { score = (double)double.Parse(x); } catch (Exception ex) { Trace.WriteLine($"Malformed data (double): {ex.Message}"); } var entry = new SortedSetEntry((RedisValue)x, score); return(entry); })); } else { _cacher.SetAddAll(fullKey, set.Select(x => (RedisValue)x)); } } } }
public void SortedSetAdd <Key, Value>(CacheUnitModel model, Key key, KeyValuePair <Value, double> keyValuePairs) { var redisKey = RedisValueKeyHelper.ToKey(key); var redisValue = RedisValueKeyHelper.ToValue(keyValuePairs.Key); var sortedSetEntry = new SortedSetEntry(redisValue, keyValuePairs.Value); _redisRepository.SortSetAdd(model.DataBaseIndex, redisKey, sortedSetEntry, model.Expire); }
/// <summary> /// Sets items in a sorted set. /// <para>Updates existing items in the set if they have the same identity. </para> /// <para>Because of this, make sure the object set is the IDENTITY of the object and does not change over time.</para> /// </summary> /// <param name="setKey"></param> /// <param name="toSet"></param> public void SortedSet_Set(string setKey, RedisSortedSetObjectValue[] toSet) { var toSetArr = new SortedSetEntry[toSet.Length]; for (int i = 0, max = toSet.Length; i < max; i++) { toSetArr[i] = new SortedSetEntry(toSet[i].value, toSet[i].score); } this.db.SortedSetAdd(setKey, toSetArr); }
public static SortedSetEntry[] ToSortedSetEntry <T>(this IEnumerable <SortedSetEntity <T> > sortedSets, ISerializer serializer) { SortedSetEntry[] sorteds = new SortedSetEntry[sortedSets.Count()]; for (int i = 0; i < sortedSets.Count(); i++) { RedisValue redisValue = sortedSets.ElementAt(i).Item.Serialize(serializer); SortedSetEntry setEntry = new SortedSetEntry(redisValue, sortedSets.ElementAt(i).Score); sorteds[i] = setEntry; } return(sorteds); }
/// <summary> /// 将一个或多个 member 元素及其 score 值加入到有序集 key 当中。 /// </summary> /// <param name="key">有序集合名称</param> /// <param name="value">值</param> /// <param name="score">分值</param> /// <returns></returns> public long SortedSetAdd(string key, string[] values, int[] score) { List <SortedSetEntry> list = new List <SortedSetEntry>(); for (int i = 0; i < values.Length; i++) { SortedSetEntry entry = new SortedSetEntry(values[i], score[i]); list.Add(entry); } return(RedisManager.WriteDataBase().SortedSetAdd(key, list.ToArray())); }
private List <UserScore> AddScore(string name, int score) { string key = RedisConstants.SCORES; //Add the record to Sorted Set SortedSetEntry sortedSetEntry = new SortedSetEntry(name, score); _cacheDatabase.SortedSetAdd(key, new SortedSetEntry[] { sortedSetEntry }); var scores = _cacheDatabase.SortedSetRangeByRankWithScores(key, order: Order.Descending); return(GetUserScores()); }
internal void SortSetAdd(int dataBaseIndex, RedisKey key, SortedSetEntry value, TimeSpan?expire, When when = When.Always) { var database = GetDatabase(dataBaseIndex); database.SortedSetAdd(key, value.Element, value.Score, when: when); if (expire.HasValue) { database.KeyExpire(key, expire); } }
public static void ZAddDemo() { SortedSetEntry[] sortedSet = new SortedSetEntry[] { new SortedSetEntry("小红", 20), new SortedSetEntry("小黑", 20), new SortedSetEntry("小白", 20), new SortedSetEntry("小青", 20) }; //成绩排名: client.SortedSetAdd("score", sortedSet); }
public long SetSortList <T>(string key, List <T> rlist) { if (key == null) { throw new ArgumentNullException(nameof(key)); } SortedSetEntry[] vals = new SortedSetEntry[rlist.Count]; for (int i = 0, j = rlist.Count; i < j; i++) { vals[i] = new SortedSetEntry(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(rlist[i])), i); } return(GetCache(key).SortedSetAdd(GetKeyForRedis(key), vals)); }
/// fill out all rank redis cache from db /// @todo: huge amount of data processing - split 10,000 or ... /// dt.Rows check. if bigger than 10,000, seperate as another loop /// dt.Rows / 10,000 = mod value + 1 = loop count........... /// call count query first and then paging processing at query side to prevent DB throttling? public static bool FillAllRankFromDB() { try { // redis connection ConnectionMultiplexer connection = ConnectionMultiplexer.Connect(redisConnectionStringRank); IDatabase cache = connection.GetDatabase(1); // delete rank sorted set - caution. this process remove all rank set data cache.KeyDelete(globalVal.CloudBreadRankSortedSet); // data table fill for easy count number RetryPolicy retryPolicy = new RetryPolicy <SqlAzureTransientErrorDetectionStrategy>(globalVal.conRetryCount, TimeSpan.FromSeconds(globalVal.conRetryFromSeconds)); SqlConnection conn = new SqlConnection(globalVal.DBConnectionString); conn.Open(); string strQuery = "SELECT Members.Name1, MemberGameInfoes.Points FROM Members inner join MemberGameInfoes on Members.MemberID = MemberGameInfoes.MemberID"; SqlCommand command = new SqlCommand(strQuery, conn); DataTable dt = new DataTable(); using (SqlDataAdapter da = new SqlDataAdapter(command)) { da.Fill(dt); } /// make SortedSetEntry to fill out SortedSetEntry[] sse = new SortedSetEntry[dt.Rows.Count]; Int64 i = 0; foreach (DataRow dr in dt.Rows) { // fill rank row to redis struct array sse[i] = new SortedSetEntry(dr[0].ToString(), Int64.Parse(dr[1].ToString())); i++; } // fill out all rank data cache.SortedSetAdd(globalVal.CloudBreadRankSortedSet, sse); connection.Close(); connection.Dispose(); return(true); } catch (Exception) { throw; } }
internal static SortedSetEntry[] ToEntry <Value>(IEnumerable <KeyValuePair <Value, double> > values) { var enumerator = values.GetEnumerator(); var keyValuePairs = new SortedSetEntry[values.Count()]; int i = 0; while (enumerator.MoveNext()) { var value = ToValue(enumerator.Current.Key); keyValuePairs[i] = new SortedSetEntry(value, enumerator.Current.Value); i++; } return(keyValuePairs); }
public SortedSetEntry?GetSortedSetMax(string fqkey) { Connect(); var result = _db.ScriptEvaluate("return redis.call('ZREVRANGE', KEYS[1], 0,0, 'withscores')", new RedisKey[] { fqkey }); if (!result.IsNull) { var maxValueRes = (RedisResult[])result; var entry = new SortedSetEntry(maxValueRes[0].ToString(), double.Parse(maxValueRes[1].ToString())); return(entry); } return(null); }
/// fill out all rank redis cache from db /// @todo: huge amount of data processing - split 10,000 or ... /// dt.Rows check. if bigger than 10,000, seperate as another loop /// dt.Rows / 10,000 = mod value + 1 = loop count........... /// call count query first and then paging processing at query side to prevent DB throttling? public static bool FillAllRankFromDB() { try { // redis connection ConnectionMultiplexer connection = ConnectionMultiplexer.Connect(redisConnectionStringRank); IDatabase cache = connection.GetDatabase(1); // delete rank sorted set - caution. this process remove all rank set data cache.KeyDelete(globalVal.CloudBreadRankSortedSet); // data table fill for easy count number RetryPolicy retryPolicy = new RetryPolicy<SqlAzureTransientErrorDetectionStrategy>(globalVal.conRetryCount, TimeSpan.FromSeconds(globalVal.conRetryFromSeconds)); SqlConnection conn = new SqlConnection(globalVal.DBConnectionString); conn.Open(); string strQuery = "SELECT Members.Name1, MemberGameInfoes.Points FROM Members inner join MemberGameInfoes on Members.MemberID = MemberGameInfoes.MemberID"; SqlCommand command = new SqlCommand(strQuery, conn); DataTable dt = new DataTable(); using (SqlDataAdapter da = new SqlDataAdapter(command)) { da.Fill(dt); } /// make SortedSetEntry to fill out SortedSetEntry[] sse = new SortedSetEntry[dt.Rows.Count]; Int64 i = 0; foreach(DataRow dr in dt.Rows) { // fill rank row to redis struct array sse[i] = new SortedSetEntry(dr[0].ToString(), Int64.Parse(dr[1].ToString())); i++; } // fill out all rank data cache.SortedSetAdd(globalVal.CloudBreadRankSortedSet, sse); return true; } catch (Exception) { throw; } }
public bool Set(IDatabase database, string key, string value, int timeLive = 0) { if (String.IsNullOrEmpty(value) || string.IsNullOrEmpty(key)) { return(false); } bool isOk = Helper.RemoveExist(database, key); if (!isOk) { return(false); } string[] array = value.Split(CommonConst.REDIS_MULTI_VALUE_SPLIT_CHARS, StringSplitOptions.RemoveEmptyEntries); List <SortedSetEntry> list = new List <SortedSetEntry>(); foreach (var item in array) { int index = item.IndexOf(CommonConst.INLINE_SPLIT_CHAR); if (index <= 0) { continue; } string itemValue = item.Substring(0, index); string itemScore = item.Substring(index + CommonConst.INLINE_SPLIT_CHAR.Length); double score = 0d; double.TryParse(itemValue, out score); SortedSetEntry entry = new SortedSetEntry(itemScore, score); list.Add(entry); } isOk = database.SortedSetAdd(key, list.ToArray(), CommandFlags.PreferMaster) == list.Count; if (!isOk) { return(false); } else { if (timeLive > 0) { isOk = database.KeyExpire(key, Helper.SetTimeSpan(timeLive), CommandFlags.PreferMaster); } return(isOk); } }
internal virtual SortedSetEntry ReadSortedSetEntry(IndexInput meta) { SortedSetEntry entry = new SortedSetEntry(); if (version >= Lucene45DocValuesFormat.VERSION_SORTED_SET_SINGLE_VALUE_OPTIMIZED) { entry.Format = meta.ReadVInt32(); } else { entry.Format = Lucene45DocValuesConsumer.SORTED_SET_WITH_ADDRESSES; } if (entry.Format != Lucene45DocValuesConsumer.SORTED_SET_SINGLE_VALUED_SORTED && entry.Format != Lucene45DocValuesConsumer.SORTED_SET_WITH_ADDRESSES) { throw new Exception("Unknown format: " + entry.Format + ", input=" + meta); } return(entry); }
public long Add(SortedSetEntry[] values, CommandFlags flags = CommandFlags.None) { return RedisSync.SortedSetAdd(Key, values, flags); }
public Task<long> AddAsync(SortedSetEntry[] values, CommandFlags flags = CommandFlags.None) { return RedisAsync.SortedSetAddAsync(Key, values, flags); }
private SortedSetRawValues LoadSortedSet(SortedSetEntry entry) { var instance = new SortedSetRawValues(); instance.docToOrdAddress = LoadNumeric(entry.docToOrdAddress); instance.ords = LoadNumeric(entry.ords); instance.values = LoadBinary(entry.values); return instance; }
public void StoreState() { try { var key = StateKey(); // Save the actual state... RedisClient.Current.Database.StringSet(key, Serialize(CurrentState)); // Now save our sorted list of keys, so we can easily iterate over // them by date to generate lists of values for charts and such var score = (double)CurrentState.AsOf.Ticks; SortedSetEntry sse = new SortedSetEntry(key, score); RedisClient.Current.Database.SortedSetAdd(MetricSortedListKey, new[] { sse }); _stateIsDirty = false; } catch (Exception ex) { } }
public void AddSetItem(RedisKeyObject key, SortedSetEntry entry) { Task.Run(async () => await AddSetItemAsync(key, entry)).Wait(); }
public void UpdateSetItem(RedisKeyObject key, SortedSetEntry entry, SortedSetEntry oldEntry) { Task.Run(async () => await UpdateSetItemAsync(key, entry, oldEntry)).Wait(); }
internal virtual SortedSetEntry ReadSortedSetEntry(IndexInput meta) { SortedSetEntry entry = new SortedSetEntry(); if (Version >= Lucene45DocValuesFormat.VERSION_SORTED_SET_SINGLE_VALUE_OPTIMIZED) { entry.Format = meta.ReadVInt(); } else { entry.Format = Lucene45DocValuesConsumer.SORTED_SET_WITH_ADDRESSES; } if (entry.Format != Lucene45DocValuesConsumer.SORTED_SET_SINGLE_VALUED_SORTED && entry.Format != Lucene45DocValuesConsumer.SORTED_SET_WITH_ADDRESSES) { throw new Exception("Unknown format: " + entry.Format + ", input=" + meta); } return entry; }
public abstract Task AddSetItemAsync(RedisKeyObject key, SortedSetEntry entry, CancellationToken token = default(CancellationToken));
private SortedSetEntry ReadSortedSetEntry(IndexInput meta) { var entry = new SortedSetEntry(); entry.docToOrdAddress = ReadNumericEntry(meta); entry.ords = ReadNumericEntry(meta); entry.values = ReadBinaryEntry(meta); return entry; }
public void SortedSetAdd_2() { SortedSetEntry[] values = new SortedSetEntry[0]; wrapper.SortedSetAdd("key", values, CommandFlags.HighPriority); mock.Verify(_ => _.SortedSetAdd("prefix:key", values, CommandFlags.HighPriority)); }
public void OnExecuted(RedisCommand command, ref object result, RedisKey[] involvedKeys = null) { if (CanBeExecuted(involvedKeys)) { if (result != null && result.GetType() != typeof(bool) && result.GetType() != typeof(int) && result.GetType() != typeof(long)) { bool isScanResult = command == RedisCommand.SCAN || command == RedisCommand.HSCAN || command == RedisCommand.SSCAN || command == RedisCommand.ZSCAN; object scanValues = null; if (isScanResult) scanValues = result.GetType() .GetField("Values", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance) .GetValue(result); if (result.GetType() == typeof(RedisValue)) { byte[] valueBlob = (RedisValue)result; RedisValueCompressor.Compressor.Decompress(ref valueBlob); if (valueBlob != null && valueBlob.Length > 0) result = (RedisValue)Encoding.UTF8.GetString(valueBlob); } else if (result.GetType() == typeof(RedisValue[]) || (command == RedisCommand.SCAN || command == RedisCommand.SSCAN)) { RedisValue[] values; if (!isScanResult) values = (RedisValue[])result; else values = (RedisValue[])scanValues; for (int i = 0; i < values.Length; i++) { byte[] valueBlob = values[i]; RedisValueCompressor.Compressor.Decompress(ref valueBlob); values[i] = (RedisValue)valueBlob; } } else if (result.GetType() == typeof(SortedSetEntry)) { SortedSetEntry source = (SortedSetEntry)result; byte[] valueBlob = source.Element; RedisValueCompressor.Compressor.Decompress(ref valueBlob); result = new SortedSetEntry((RedisValue)valueBlob, source.Score); } else if (result.GetType() == typeof(SortedSetEntry[]) || command == RedisCommand.ZSCAN) { SortedSetEntry[] entries; if (!isScanResult) entries = (SortedSetEntry[])result; else entries = (SortedSetEntry[])scanValues; for (int i = 0; i < entries.Length; i += 2) { SortedSetEntry source = (SortedSetEntry)entries[i]; byte[] valueBlob = source.Element; RedisValueCompressor.Compressor.Decompress(ref valueBlob); entries[i] = new SortedSetEntry((RedisValue)valueBlob, source.Score); } } else if (result.GetType() == typeof(HashEntry)) { HashEntry source = (HashEntry)result; byte[] valueBlob = source.Value; RedisValueCompressor.Compressor.Decompress(ref valueBlob); result = new HashEntry(source.Name, (RedisValue)valueBlob); } else if (result.GetType() == typeof(HashEntry[]) || command == RedisCommand.HSCAN) { HashEntry[] entries; if (!isScanResult) entries = (HashEntry[])result; else // TODO: Not the best solution... But I need to investigate further how to improve StackExchange.Redis // to get these values directly... entries = (HashEntry[])scanValues; for (int i = 0; i < entries.Length; i++) { HashEntry source = entries[i]; byte[] valueBlob = source.Value; RedisValueCompressor.Compressor.Decompress(ref valueBlob); entries[i] = new HashEntry(source.Name, (RedisValue)valueBlob); } } } } }