Beispiel #1
0
 /// <summary>
 /// This method saves a single DataDocument to Redis at a <c>Location</c> within a particular schema. The Redis Key where the document
 /// is saved is determined as <code>schemaId:location</code>. All writes are "last write wins" when multiple writes to the same key are made at the same time.
 ///
 /// Best practice is for all locations used within a "schemaId" to follow the same pattern.
 /// </summary>
 /// <param name="schemaId">The id representing the schema where the document will be stored.</param>
 /// <param name="location">The location within the schema where the document will be stored.</param>
 /// <param name="doc">The <c>DataDocument</c> to persist in Redis.</param>
 /// <param name="expiration">The TTL for the key -> document pair. Defaults to null, indicating that there will not be a TTL.</param>
 /// <returns>A Task to track the asynchronous operation.</returns>
 public async Task Put(string schemaId, Location location, DataDocument doc, TimeSpan?expiration = null)
 {
     string key = schemaId + ":" + location;
     await RetryHelper.RetryOnExceptionAsync(3, async() =>
     {
         var db = RedisConnection.Connection.GetDatabase();
         await db.HashSetAsync(key, doc.ToHashEntries());
         logger.LogDebug("SET {key} {value}.", key, doc);
     });
 }
Beispiel #2
0
        /// <summary>
        /// This method saves a single DataDocument to Redis at a <c>Location</c> within a particular schema. The Redis Key where the document
        /// is saved is determined as <code>schemaId:location</code>. All writes are "last write wins" when multiple writes to the same key are made at the same time.
        ///
        /// Best practice is for all locations used within a "schemaId" to follow the same pattern.
        /// </summary>
        /// <param name="schemaId">The id representing the schema where the document will be stored.</param>
        /// <param name="location">The location within the schema where the document will be stored.</param>
        /// <param name="doc">The <c>DataDocument</c> to persist in Redis.</param>
        /// <returns>A Task to track the asynchronous operation.</returns>
        public void PutSync(string schemaId, Location location, DataDocument doc)
        {
            string key = schemaId + ":" + location;

            RetryHelper.RetryOnException(3, () =>
            {
                var db = RedisConnection.Connection.GetDatabase();
                db.HashSet(key, doc.ToHashEntries());
                logger.LogDebug("SET {key} {value}.", key, doc);
            });
        }