コード例 #1
0
        /// <summary>
        /// `JSON.STRLEN`
        ///
        /// Report the length of the JSON String at `path` in `key`.
        ///
        /// `path` defaults to root if not provided. If the `key` or `path` do not exist, null is returned.
        ///
        /// https://oss.redislabs.com/rejson/commands/#jsonstrlen
        /// </summary>
        /// <param name="db"></param>
        /// <param name="key">The key of the JSON object you need string length information about.</param>
        /// <param name="path">The path of the JSON string you want the length of. This defaults to root.</param>
        /// <param name="commandFlags">Optional command flags.</param>
        /// <returns>Integer, specifically the string's length.</returns>
        public static async Task <int?[]> JsonStringLengthAsync(this IDatabaseAsync db, RedisKey key, string path = ".",
                                                                CommandFlags commandFlags = CommandFlags.None)
        {
            var result = await db.ExecuteAsync(JsonCommands.STRLEN, CombineArguments(key, path), flags : commandFlags)
                         .ConfigureAwait(false);

            return(NullableIntArrayFrom(result));
        }
コード例 #2
0
        /// <summary>
        /// `JSON.TOGGLE`
        ///
        /// Toggle the boolean property of a JSON object.
        ///
        /// Official documentation forthcoming.
        /// </summary>
        /// <param name="db"></param>
        /// <param name="key">The key of the JSON object that contains the property that you'd like to toggle.</param>
        /// <param name="path">The path to the boolean property on JSON object that you'd like to toggle.</param>
        /// <param name="commandFlags">Optional command flags.</param>
        /// <returns></returns>
        public static async Task <bool> JsonToggleAsync(this IDatabaseAsync db, RedisKey key, string path,
                                                        CommandFlags commandFlags = CommandFlags.None)
        {
            var result = await db.ExecuteAsync(JsonCommands.TOGGLE, new object[] { key, path }, flags : commandFlags)
                         .ConfigureAwait(false);

            return(bool.Parse(result.ToString()));
        }
コード例 #3
0
        /// <summary>
        /// `JSON.CLEAR`
        ///
        /// Clear/empty arrays and objects (to have zero slots/keys without deleting the array/object) returning the count
        /// of cleared paths (ignoring non-array and non-objects paths).
        ///
        /// Official documentation forthcoming.
        /// </summary>
        /// <param name="db"></param>
        /// <param name="key"></param>
        /// <param name="path"></param>
        /// <param name="commandFlags">Optional command flags.</param>
        /// <returns></returns>
        public static async Task <int> JsonClearAsync(this IDatabaseAsync db, RedisKey key, string path,
                                                      CommandFlags commandFlags = CommandFlags.None)
        {
            var result = await db.ExecuteAsync(JsonCommands.CLEAR, new object[] { key, path }, flags : commandFlags)
                         .ConfigureAwait(false);

            return((int)result);
        }
コード例 #4
0
 public async static Task <ThrottleResult> ThrottleAsync(
     this IDatabaseAsync db, RedisKey key, int maxBurst,
     int maxPerInterval,
     int intervalSeconds = 60, int count = 1)
 {
     return(new ThrottleResult(await db.ExecuteAsync("CL.THROTTLE",
                                                     key, maxBurst.Boxed(), maxPerInterval.Boxed(), intervalSeconds.Boxed(), count.Boxed())));
 }
コード例 #5
0
 /// <summary>
 /// `JSON.STRAPPEND`
 ///
 /// Append the json-string value(s) the string at path.
 /// path defaults to root if not provided.
 ///
 /// https://oss.redislabs.com/rejson/commands/#jsonstrappend
 /// </summary>
 /// <param name="db"></param>
 /// <param name="key">The key of the JSON object you need to append a string value.</param>
 /// <param name="path">The path of the JSON string you want to append do. This defaults to root.</param>
 /// <param name="jsonString">JSON formatted string.</param>
 /// <param name="commandFlags">Optional command flags.</param>
 /// <returns>Length of the new JSON string.</returns>
 public static async Task <int?[]> JsonAppendJsonStringAsync(this IDatabaseAsync db,
                                                             RedisKey key,
                                                             string path               = ".",
                                                             string jsonString         = "\"\"",
                                                             CommandFlags commandFlags = CommandFlags.None
                                                             ) =>
 NullableIntArrayFrom(await db.ExecuteAsync(JsonCommands.STRAPPEND, CombineArguments(key, path, jsonString),
                                            flags: commandFlags)
                      .ConfigureAwait(false));
コード例 #6
0
        /// <summary>
        /// `JSON.ARRINDEX`
        ///
        /// Search for the first occurrence of a scalar JSON value in an array.
        ///
        /// The optional inclusive `start`(default 0) and exclusive `stop`(default 0, meaning that the last element is included) specify a slice of the array to search.
        ///
        /// Note: out of range errors are treated by rounding the index to the array's start and end. An inverse index range (e.g. from 1 to 0) will return unfound.
        ///
        /// https://oss.redislabs.com/rejson/commands/#jsonarrindex
        /// </summary>
        /// <param name="db"></param>
        /// <param name="key">The key of the JSON object that contains the array you want to check for a scalar value in.</param>
        /// <param name="path">The path to the JSON array that you want to check.</param>
        /// <param name="jsonScalar">The JSON object that you are looking for.</param>
        /// <param name="start">Where to start searching, defaults to 0 (the beginning of the array).</param>
        /// <param name="stop">Where to stop searching, defaults to 0 (the end of the array).</param>
        /// <param name="commandFlags">Optional command flags.</param>
        /// <returns>Array of nullable integers, specifically, for each JSON value matching the path, the first position of the scalar value in the array, -1 if unfound in the array, or null if the matching JSON value is not an array.</returns>
        public static async Task <int?[]> JsonArrayIndexOfAsync(this IDatabaseAsync db, RedisKey key, string path,
                                                                object jsonScalar, int start = 0, int stop = 0, CommandFlags commandFlags = CommandFlags.None)
        {
            var result = await db.ExecuteAsync(JsonCommands.ARRINDEX,
                                               CombineArguments(key, path, jsonScalar, start, stop),
                                               flags : commandFlags)
                         .ConfigureAwait(false);

            return(NullableIntArrayFrom(result));
        }
コード例 #7
0
        /// <summary>
        ///  根据条件异步查询 RedisKey
        /// </summary>
        /// <param name="database"></param>
        /// <param name="keyPrefix"></param>
        /// <returns></returns>
        public static async Task <RedisKey[]> GetKeysAsync(this IDatabaseAsync database, string keyPrefix)
        {
            if (string.IsNullOrEmpty(keyPrefix))
            {
                throw new ArgumentNullException(nameof(keyPrefix));
            }

            var partten = $"{keyPrefix}*";

            return((RedisKey[])await database.ExecuteAsync("KEYS", partten));
        }
コード例 #8
0
        /// <summary>
        /// `JSON.SET`
        ///
        /// Sets the JSON value at path in key
        ///
        /// For new Redis keys the path must be the root.
        ///
        /// For existing keys, when the entire path exists, the value that it contains is replaced with the json value.
        ///
        /// https://oss.redislabs.com/rejson/commands/#jsonset
        /// </summary>
        /// <param name="db"></param>
        /// <param name="key">Key where JSON object is to be stored.</param>
        /// <param name="json">The JSON object which you want to persist.</param>
        /// <param name="path">The path which you want to persist the JSON object. For new objects this must be root.</param>
        /// <param name="setOption">By default the object will be overwritten, but you can specify that the object be set only if it doesn't already exist or to set only IF it exists.</param>
        /// <param name="commandFlags">Optional command flags.</param>
        /// <returns>An `OperationResult` indicating success or failure.</returns>
        public static async Task <OperationResult> JsonSetAsync(this IDatabaseAsync db, RedisKey key, string json,
                                                                string path = ".", SetOption setOption = SetOption.Default, CommandFlags commandFlags = CommandFlags.None)
        {
            var result =
                (await db.ExecuteAsync(
                     JsonCommands.SET,
                     CombineArguments(key, path, json, GetSetOptionString(setOption)),
                     flags: commandFlags)
                 .ConfigureAwait(false)).ToString();

            return(new OperationResult(result == "OK", result));
        }
コード例 #9
0
        /// <summary>
        /// `JSON.OBJLEN`
        ///
        /// Report the number of keys in the JSON Object at `path` in `key`.
        ///
        /// `path` defaults to root if not provided. If the `key` or `path` do not exist, null is returned.
        ///
        /// https://oss.redislabs.com/rejson/commands/#jsonobjlen
        /// </summary>
        /// <param name="db"></param>
        /// <param name="key">The key of the JSON object which you want the length of.</param>
        /// <param name="path">The path to the JSON object which you want the length of, defaults to root.</param>
        /// <param name="commandFlags">Optional command flags.</param>
        /// <returns>Integer, specifically the number of keys in the object.</returns>
        public static async Task <int?> JsonObjectLengthAsync(this IDatabaseAsync db, RedisKey key, string path = ".",
                                                              CommandFlags commandFlags = CommandFlags.None)
        {
            var result = await db.ExecuteAsync(JsonCommands.OBJLEN, CombineArguments(key, path), flags : commandFlags)
                         .ConfigureAwait(false);

            if (result.IsNull)
            {
                return(null);
            }
            else
            {
                return((int)result);
            }
        }
コード例 #10
0
        /// <summary>
        /// `JSON.GET`
        ///
        /// Return the value at `path` in JSON serialized form.
        ///
        /// https://oss.redislabs.com/rejson/commands/#jsonget
        /// </summary>
        /// <param name="db"></param>
        /// <param name="key">Key where JSON object is stored.</param>
        /// <param name="noEscape">This option will disable the sending of \uXXXX escapes for non-ascii characters. This option should be used for efficiency if you deal mainly with such text.</param>
        /// <param name="indent">Sets the indentation string for nested levels</param>
        /// <param name="newline">Sets the string that's printed at the end of each line</param>
        /// <param name="space">Sets the string that's put between a key and a value</param>
        /// <param name="commandFlags">Optional command flags.</param>
        /// <param name="paths">The path(s) of the JSON properties that you want to return. By default, the entire JSON object will be returned.</param>
        /// <returns></returns>
        public static Task <RedisResult> JsonGetAsync(this IDatabaseAsync db, RedisKey key, bool noEscape = false,
                                                      string indent             = default, string newline = default, string space = default,
                                                      CommandFlags commandFlags = CommandFlags.None, params string[] paths)
        {
            var args = new List <object> {
                key
            };

            if (noEscape)
            {
                args.Add("NOESCAPE");
            }

            if (indent != default)
            {
                args.Add("INDENT");
                args.Add(indent);
            }

            if (newline != default)
            {
                args.Add("NEWLINE");
                args.Add(newline);
            }

            if (space != default)
            {
                args.Add("SPACE");
                args.Add(space);
            }

            foreach (var path in PathsOrDefault(paths, new[] { "." }))
            {
                args.Add(path);
            }

            return(db.ExecuteAsync(JsonCommands.GET, args));
        }
コード例 #11
0
        /// <summary>
        /// Append (or create and append) a new sample to the series.
        /// </summary>
        /// <param name="db">StackExchange.Redis IDatabaseAsync instance</param>
        /// <param name="key">Key name for timeseries</param>
        /// <param name="timestamp">TimeStamp to add. UNIX timestamp of the sample. * can be used for automatic timestamp (using the system clock)</param>
        /// <param name="value">Numeric data value of the sample.</param>
        /// <param name="retentionTime">Optional: Maximum age for samples compared to last event time (in milliseconds)</param>
        /// <param name="labels">Optional: Collaction of label-value pairs that represent metadata labels of the key</param>
        /// <param name="uncompressed">Optional: Adding this flag will keep data in an uncompressed form</param>
        /// <param name="chunkSizeBytes">Optional: Each time-series uses chunks of memory of fixed size for time series samples.
        /// You can alter the default TSDB chunk size by passing the chunk_size argument (in Bytes)</param>
        /// <param name="policy">Optioal: overwrite key and database configuration for DUPLICATE_POLICY</param>
        /// <returns>The timestamp value of the new sample</returns>
        public static async Task <TimeStamp> TimeSeriesAddAsync(this IDatabaseAsync db, string key, TimeStamp timestamp, double value, long?retentionTime = null, IReadOnlyCollection <TimeSeriesLabel> labels = null, bool?uncompressed = null, long?chunkSizeBytes = null, TsDuplicatePolicy?policy = null)
        {
            var args = BuildTsAddArgs(key, timestamp, value, retentionTime, labels, uncompressed, chunkSizeBytes, policy);

            return(ParseTimeStamp(await db.ExecuteAsync(TS.ADD, args)));
        }
コード例 #12
0
 /// <summary>
 /// `JSON.RESP`
 ///
 /// This command uses the following mapping from JSON to RESP:
 ///
 ///     - JSON Null is mapped to the RESP Null Bulk String
 ///
 ///     - JSON `false` and `true` values are mapped to the respective RESP Simple Strings
 ///
 ///     - JSON Numbers are mapped to RESP Integers or RESP Bulk Strings, depending on type
 ///
 ///     - JSON Strings are mapped to RESP Bulk Strings
 ///
 ///     - JSON Arrays are represented as RESP Arrays in which the first element is the simple string `[` followed by the array's elements
 ///
 ///     - JSON Objects are represented as RESP Arrays in which the first element is the simple string `{`. Each successive entry represents a key-value pair as a two-entries array of bulk strings.
 ///
 /// https://oss.redislabs.com/rejson/commands/#jsonresp
 /// </summary>
 /// <param name="db"></param>
 /// <param name="key">The key of the JSON object that you want an RESP result for.</param>
 /// <param name="path">Defaults to root if not provided. </param>
 /// <param name="commandFlags">Optional command flags.</param>
 /// <returns>Array, specifically the JSON's RESP form as detailed.</returns>
 public static async Task <RedisResult[]> JsonGetRespAsync(this IDatabaseAsync db, RedisKey key,
                                                           string path = ".",
                                                           CommandFlags commandFlags = CommandFlags.None) =>
 (RedisResult[])(await db.ExecuteAsync(JsonCommands.RESP, new object[] { key, path }, flags: commandFlags)
                 .ConfigureAwait(false));
コード例 #13
0
 /// <summary>
 /// `JSON.DEBUG MEMORY`
 ///
 /// Report the memory usage in bytes of a value. `path` defaults to root if not provided.
 ///
 /// https://oss.redislabs.com/rejson/commands/#jsondebug
 /// </summary>
 /// <param name="db"></param>
 /// <param name="key">The key of the JSON object that you want to determine the memory usage of.</param>
 /// <param name="path">The path to JSON object you want to check, this defaults to root.</param>
 /// <param name="commandFlags">Optional command flags.</param>
 /// <returns>Integer, specifically the size in bytes of the value</returns>
 public static async Task <int> JsonDebugMemoryAsync(this IDatabaseAsync db, RedisKey key, string path = ".",
                                                     CommandFlags commandFlags = CommandFlags.None) =>
 (int)(await db.ExecuteAsync(JsonCommands.DEBUG, CombineArguments("MEMORY", key.ToString(), path),
                             flags: commandFlags)
       .ConfigureAwait(false));
コード例 #14
0
 /// <summary>
 /// `JSON.OBJKEYS`
 ///
 /// Return the keys in the object that's referenced by `path`.
 ///
 /// `path` defaults to root if not provided.If the object is empty, or either `key` or `path` do not exist, then null is returned.
 ///
 /// https://oss.redislabs.com/rejson/commands/#jsonobjkeys
 /// </summary>
 /// <param name="db"></param>
 /// <param name="key">The key of the JSON object which you want to enumerate keys for.</param>
 /// <param name="path">The path to the JSON object you want the keys for, this defaults to root.</param>
 /// <param name="commandFlags">Optional command flags.</param>
 /// <returns>Array, specifically the key names in the object as Bulk Strings.</returns>
 public static async Task <RedisResult[]> JsonObjectKeysAsync(this IDatabaseAsync db, RedisKey key,
                                                              string path = ".",
                                                              CommandFlags commandFlags = CommandFlags.None) =>
 (RedisResult[])(await db
                 .ExecuteAsync(JsonCommands.OBJKEYS, CombineArguments(key, path), flags: commandFlags)
                 .ConfigureAwait(false));
コード例 #15
0
 /// <summary>
 /// `JSON.TYPE`
 ///
 /// Report the type of JSON value at `path`.
 ///
 /// `path` defaults to root if not provided.
 ///
 /// https://oss.redislabs.com/rejson/commands/#jsontype
 /// </summary>
 /// <param name="db"></param>
 /// <param name="key">The key of the JSON object you need the type of.</param>
 /// <param name="path">The path of the JSON object you want the type of. This defaults to root.</param>
 /// <param name="commandFlags">Optional command flags.</param>
 /// <returns></returns>
 public static Task <RedisResult> JsonTypeAsync(this IDatabaseAsync db, RedisKey key, string path = ".",
                                                CommandFlags commandFlags = CommandFlags.None) =>
 db.ExecuteAsync(JsonCommands.TYPE, CombineArguments(key, path), flags: commandFlags);
コード例 #16
0
 /// <summary>
 /// `JSON.ARRPOP`
 ///
 /// Remove and return element from the index in the array.
 ///
 /// Out of range indices are rounded to their respective array ends.Popping an empty array yields null.
 ///
 /// https://oss.redislabs.com/rejson/commands/#jsonarrpop
 /// </summary>
 /// <param name="db"></param>
 /// <param name="key">The key of the JSON object that contains the array you want to pop an object off of.</param>
 /// <param name="path">Defaults to root (".") if not provided.</param>
 /// <param name="index">Is the position in the array to start popping from (defaults to -1, meaning the last element).</param>
 /// <param name="commandFlags">Optional command flags.</param>
 /// <typeparam name="TResult">The type to deserialize the value as.</typeparam>
 /// <returns>Array of `TResult`, specifically, for each path, the popped JSON value, or null element if the matching JSON value is not an array.</returns>
 public static async Task <TResult[]> JsonArrayPopAsync <TResult>(this IDatabaseAsync db, RedisKey key,
                                                                  string path = ".", int index = -1, CommandFlags commandFlags = CommandFlags.None) =>
 TypedArrayFrom <TResult>(await db.ExecuteAsync(JsonCommands.ARRPOP, CombineArguments(key, path, index), flags: commandFlags));
コード例 #17
0
        /// <summary>
        /// Update the retention, labels of an existing key.
        /// </summary>
        /// <param name="db">StackExchange.Redis IDatabaseAsync instance</param>
        /// <param name="key">Key name for timeseries</param>
        /// <param name="retentionTime">Optional: Maximum age for samples compared to last event time (in milliseconds)</param>
        /// <param name="labels">Optional: Collaction of label-value pairs that represent metadata labels of the key</param>
        /// <returns>If the operation executed successfully</returns>
        public static async Task <bool> TimeSeriesAlterAsync(this IDatabaseAsync db, string key, long?retentionTime = null, IReadOnlyCollection <TimeSeriesLabel> labels = null)
        {
            var args = BuildTsAlterArgs(key, retentionTime, labels);

            return(ParseBoolean(await db.ExecuteAsync(TS.ALTER, args)));
        }
コード例 #18
0
        /// <summary>
        /// Create the index definition in redis
        /// </summary>
        /// <param name="schema">a schema definition <seealso cref="Schema"/></param>
        /// <param name="options">index option flags <seealso cref="IndexOptions"/></param>
        /// <returns>true if successful</returns>
        public async Task <bool> CreateIndexAsync(Schema schema, IndexOptions options)
        {
            var args = new List <object>
            {
                _boxedIndexName
            };

            ConfiguredIndexOptions.SerializeRedisArgs(options, args);
            args.Add("SCHEMA".Literal());

            foreach (var f in schema.Fields)
            {
                f.SerializeRedisArgs(args);
            }

            return((string)await _db.ExecuteAsync("FT.CREATE", args).ConfigureAwait(false) == "OK");
        }
コード例 #19
0
 /// <summary>
 /// `JSON.MGET`
 ///
 /// Returns the values at `path` from multiple `key`s. Non-existing keys and non-existing paths are reported as null.
 ///
 /// https://oss.redislabs.com/rejson/commands/#jsonmget
 /// </summary>
 /// <param name="db"></param>
 /// <param name="keys">Keys where JSON objects are stored.</param>
 /// <param name="path">The path of the JSON property that you want to return for each key. This is "root" by default.</param>
 /// <param name="commandFlags">Optional command flags.</param>
 /// <returns>Array of Bulk Strings, specifically the JSON serialization of the value at each key's path.</returns>
 public static async Task <RedisResult[]> JsonMultiGetAsync(this IDatabaseAsync db, RedisKey[] keys,
                                                            string path = ".",
                                                            CommandFlags commandFlags = CommandFlags.None) =>
 (RedisResult[])(await db.ExecuteAsync(JsonCommands.MGET, CombineArguments(keys, path), flags: commandFlags)
                 .ConfigureAwait(false));
コード例 #20
0
 /// <summary>
 /// `JSON.NUMMULTBY`
 ///
 /// Multiplies the number value stored at `path` by `number`.
 ///
 /// https://oss.redislabs.com/rejson/commands/#jsonnummultby
 /// </summary>
 /// <param name="db"></param>
 /// <param name="key">They key of the JSON object which contains the number value you want to multiply.</param>
 /// <param name="path">The path of the JSON value you want to multiply.</param>
 /// <param name="number">The value you want to multiply by.</param>
 /// <param name="commandFlags">Optional command flags.</param>
 public static async Task <PathedResult <double?> > JsonMultiplyNumberAsync(this IDatabaseAsync db, RedisKey key,
                                                                            string path,
                                                                            double number, CommandFlags commandFlags = CommandFlags.None) =>
 PathedResult <double?> .Create(await db.ExecuteAsync(JsonCommands.NUMMULTBY,
                                                      CombineArguments(key, path, number), flags: CommandFlags.None));
コード例 #21
0
 /// <summary>
 /// `JSON.ARRTRIM`
 ///
 /// Trim an array so that it contains only the specified inclusive range of elements.
 ///
 /// This command is extremely forgiving and using it with out of range indexes will not produce an error.
 ///
 /// If start is larger than the array's size or start > stop, the result will be an empty array.
 ///
 /// If start is &lt; 0 then it will be treated as 0.
 ///
 /// If stop is larger than the end of the array, it will be treated like the last element in it.
 ///
 /// https://oss.redislabs.com/rejson/commands/#jsonarrtrim
 /// </summary>
 /// <param name="db"></param>
 /// <param name="key">The key of the JSON object that contains the array you want to trim.</param>
 /// <param name="path">The path of the JSON array that you want to trim.</param>
 /// <param name="start">The inclusive start index.</param>
 /// <param name="stop">The inclusive stop index.</param>
 /// <param name="commandFlags">Optional command flags.</param>
 /// <returns>Array of nullable integer, specifically for each path, the array's new size, or null element if the matching JSON value is not an array.</returns>
 public static async Task <int?[]> JsonArrayTrimAsync(this IDatabaseAsync db, RedisKey key, string path, int start,
                                                      int stop, CommandFlags commandFlags = CommandFlags.None) =>
 NullableIntArrayFrom((await db.ExecuteAsync(JsonCommands.ARRTRIM, CombineArguments(key, path, start, stop),
                                             flags: commandFlags)
                       .ConfigureAwait(false)));
コード例 #22
0
        private static TupleList <string, Task> RunStackExchangeAsync(string prefix, IDatabaseAsync db)
        {
            var tasks = new TupleList <string, Func <Task> >()
            {
                { "DebugObjectAsync", () => db.DebugObjectAsync($"{prefix}DebugObjectAsync") },
                { "ExecuteAsync", () => db.ExecuteAsync("DDCUSTOM", "COMMAND") },
                { "GeoAddAsync", () => db.GeoAddAsync($"{prefix}GeoAddAsync", new GeoEntry(1.5, 2.5, "member")) },
                { "GeoDistanceAsync", () => db.GeoDistanceAsync($"{prefix}GeoDistanceAsync", "member1", "member2") },
                { "GeoHashAsync", () => db.GeoHashAsync($"{prefix}GeoHashAsync", "member") },
                { "GeoPositionAsync", () => db.GeoPositionAsync($"{prefix}GeoPositionAsync", "member") },
                { "GeoRadiusAsync", () => db.GeoRadiusAsync($"{prefix}GeoRadiusAsync", "member", 2.3) },
                { "GeoRemoveAsync", () => db.GeoRemoveAsync($"{prefix}GeoRemoveAsync", "member") },
                { "HashDecrementAsync", () => db.HashDecrementAsync($"{prefix}HashDecrementAsync", "hashfield", 4.5) },
                { "HashDeleteAsync", () => db.HashDeleteAsync($"{prefix}HashDeleteAsync", "hashfield") },
                { "HashExistsAsync", () => db.HashExistsAsync($"{prefix}HashExistsAsync", "hashfield") },
                { "HashGetAllAsync", () => db.HashGetAllAsync($"{prefix}HashGetAllAsync") },
                { "HashIncrementAsync", () => db.HashIncrementAsync($"{prefix}HashIncrementAsync", "hashfield", 1.5) },
                { "HashKeysAsync", () => db.HashKeysAsync($"{prefix}HashKeysAsync") },
                { "HashLengthAsync", () => db.HashLengthAsync($"{prefix}HashLengthAsync") },
                { "HashSetAsync", () => db.HashSetAsync($"{prefix}HashSetAsync", new HashEntry[] { new HashEntry("x", "y") }) },
                { "HashValuesAsync", () => db.HashValuesAsync($"{prefix}HashValuesAsync") },
                { "HyperLogLogAddAsync", () => db.HyperLogLogAddAsync($"{prefix}HyperLogLogAddAsync", "value") },
                { "HyperLogLogLengthAsync", () => db.HyperLogLogLengthAsync($"{prefix}HyperLogLogLengthAsync") },
                { "HyperLogLogMergeAsync", () => db.HyperLogLogMergeAsync($"{prefix}HyperLogLogMergeAsync", new RedisKey[] { "key1", "key2" }) },
                { "IdentifyEndpointAsync", () => db.IdentifyEndpointAsync() },
                { "KeyDeleteAsync", () => db.KeyDeleteAsync("key") },
                { "KeyDumpAsync", () => db.KeyDumpAsync("key") },
                { "KeyExistsAsync", () => db.KeyExistsAsync("key") },
                { "KeyExpireAsync", () => db.KeyExpireAsync("key", DateTime.Now) },
                // () => db.KeyMigrateAsync("key", ???)
                { "KeyMoveAsync", () => db.KeyMoveAsync("key", 1) },
                { "KeyPersistAsync", () => db.KeyPersistAsync("key") },
                { "KeyRandomAsync", () => db.KeyRandomAsync() },
                { "KeyRenameAsync", () => db.KeyRenameAsync("key1", "key2") },
                { "KeyRestoreAsync", () => db.KeyRestoreAsync("key", new byte[] { 0, 1, 2, 3, 4 }) },
                { "KeyTimeToLiveAsync", () => db.KeyTimeToLiveAsync("key") },
                { "KeyTypeAsync", () => db.KeyTypeAsync("key") },
                { "ListGetByIndexAsync", () => db.ListGetByIndexAsync("listkey", 0) },
                { "ListInsertAfterAsync", () => db.ListInsertAfterAsync("listkey", "value1", "value2") },
                { "ListInsertBeforeAsync", () => db.ListInsertBeforeAsync("listkey", "value1", "value2") },
                { "ListLeftPopAsync", () => db.ListLeftPopAsync("listkey") },
                { "ListLeftPushAsync", () => db.ListLeftPushAsync("listkey", new RedisValue[] { "value3", "value4" }) },
                { "ListLengthAsync", () => db.ListLengthAsync("listkey") },
                { "ListRangeAsync", () => db.ListRangeAsync("listkey") },
                { "ListRemoveAsync", () => db.ListRemoveAsync("listkey", "value3") },
                { "ListRightPopAsync", () => db.ListRightPopAsync("listkey") },
                { "ListRightPopLeftPushAsync", () => db.ListRightPopLeftPushAsync("listkey", "listkey2") },
                { "ListRightPushAsync", () => db.ListRightPushAsync("listkey", new RedisValue[] { "value5", "value6" }) },
                { "ListSetByIndexAsync", () => db.ListSetByIndexAsync("listkey", 0, "value7") },
                { "ListTrimAsync", () => db.ListTrimAsync("listkey", 0, 1) },
                { "LockExtendAsync", () => db.LockExtendAsync("listkey", "value7", new TimeSpan(0, 0, 10)) },
                { "LockQueryAsync", () => db.LockQueryAsync("listkey") },
                { "LockReleaseAsync", () => db.LockReleaseAsync("listkey", "value7") },
                { "LockTakeAsync", () => db.LockTakeAsync("listkey", "value8", new TimeSpan(0, 0, 10)) },
                { "PublishAsync", () => db.PublishAsync(new RedisChannel("channel", RedisChannel.PatternMode.Auto), "somemessage") },
                // { "ScriptEvaluateAsync", () => db.ScriptEvaluateAsync(}
                { "SetAddAsync", () => db.SetAddAsync("setkey", "value1") },
                { "SetCombineAndStoreAsync", () => db.SetCombineAndStoreAsync(SetOperation.Union, "setkey", new RedisKey[] { "value2" }) },
                { "SetCombineAsync", () => db.SetCombineAsync(SetOperation.Union, new RedisKey[] { "setkey1", "setkey2" }) },
                { "SetContainsAsync", () => db.SetContainsAsync("setkey", "value1") },
                { "SetLengthAsync", () => db.SetLengthAsync("setkey") },
                { "SetMembersAsync", () => db.SetMembersAsync("setkey") },
                { "SetMoveAsync", () => db.SetMoveAsync("setkey1", "setkey2", "value2") },
                { "SetPopAsync", () => db.SetPopAsync("setkey1") },
                { "SetRandomMemberAsync", () => db.SetRandomMemberAsync("setkey") },
                { "SetRandomMembersAsync", () => db.SetRandomMembersAsync("setkey", 2) },
                { "SetRemoveAsync", () => db.SetRemoveAsync("setkey", "value2") },
                { "SortAndStoreAsync", () => db.SortAndStoreAsync("setkey2", "setkey") },
                { "SortAsync", () => db.SortAsync("setkey") },
                { "SortedSetAddAsync", () => db.SortedSetAddAsync("ssetkey", new SortedSetEntry[] { new SortedSetEntry("value1", 1.5), new SortedSetEntry("value2", 2.5) }) },
                { "SortedSetCombineAndStoreAsync", () => db.SortedSetCombineAndStoreAsync(SetOperation.Union, "ssetkey1", "ssetkey2", "ssetkey3") },
                { "SortedSetDecrementAsync", () => db.SortedSetDecrementAsync("ssetkey", "value1", 1) },
                { "SortedSetIncrementAsync", () => db.SortedSetIncrementAsync("ssetkey", "value2", 1) },
                { "SortedSetLengthAsync", () => db.SortedSetLengthAsync("ssetkey") },
                { "SortedSetLengthByValueAsync", () => db.SortedSetLengthByValueAsync("ssetkey", "value1", "value2") },
                { "SortedSetRangeByRankAsync", () => db.SortedSetRangeByRankAsync("ssetkey") },
                { "SortedSetRangeByRankWithScoresAsync", () => db.SortedSetRangeByRankWithScoresAsync("ssetkey") },
                { "SortedSetRangeByScoreAsync", () => db.SortedSetRangeByScoreAsync("ssetkey") },
                { "SortedSetRangeByScoreWithScoresAsync", () => db.SortedSetRangeByScoreWithScoresAsync("ssetkey") },
                { "SortedSetRangeByValueAsync", () => db.SortedSetRangeByValueAsync("ssetkey") },
                { "SortedSetRankAsync", () => db.SortedSetRankAsync("ssetkey", "value1") },
                { "SortedSetRemoveAsync", () => db.SortedSetRemoveAsync("ssetkey", "value1") },
                { "SortedSetRemoveRangeByRankAsync", () => db.SortedSetRemoveRangeByRankAsync("ssetkey", 0, 1) },
                { "SortedSetRemoveRangeByScoreAsync", () => db.SortedSetRemoveRangeByScoreAsync("ssetkey", 0, 1) },
                { "SortedSetRemoveRangeByValueAsync", () => db.SortedSetRemoveRangeByValueAsync("ssetkey", "value1", "value2") },
                { "SortedSetScoreAsync", () => db.SortedSetScoreAsync("ssestkey", "value1") },
                { "StringAppendAsync", () => db.StringAppendAsync("ssetkey", "value1") },
                { "StringBitCountAsync", () => db.StringBitCountAsync("ssetkey") },
                { "StringBitOperationAsync", () => db.StringBitOperationAsync(Bitwise.And, "ssetkey1", new RedisKey[] { "ssetkey2", "ssetkey3" }) },
                { "StringBitPositionAsync", () => db.StringBitPositionAsync("ssetkey1", true) },
                { "StringDecrementAsync", () => db.StringDecrementAsync("key", 1.45) },
                { "StringGetAsync", () => db.StringGetAsync("key") },
                { "StringGetBitAsync", () => db.StringGetBitAsync("key", 3) },
                { "StringGetRangeAsync", () => db.StringGetRangeAsync("key", 0, 1) },
                { "StringGetSetAsync", () => db.StringGetSetAsync("key", "value") },
                { "StringGetWithExpiryAsync", () => db.StringGetWithExpiryAsync("key") },
                { "StringIncrementAsync", () => db.StringIncrementAsync("key", 1) },
                { "StringLengthAsync", () => db.StringLengthAsync("key") },
                { "StringSetAsync", () => db.StringSetAsync(new KeyValuePair <RedisKey, RedisValue>[] { new KeyValuePair <RedisKey, RedisValue>("key", "value") }) },
                { "StringSetBitAsync", () => db.StringSetBitAsync("key", 0, true) },
                { "StringSetRangeAsync", () => db.StringSetRangeAsync("key", 3, "value") },
            };

            var pending = new TupleList <string, Task>();

            foreach (var item in tasks)
            {
                try
                {
                    pending.Add(item.Item1, item.Item2());
                }
                catch (Exception e)
                {
                    while (e.InnerException != null)
                    {
                        e = e.InnerException;
                    }
                    Console.WriteLine($"{e.Message}");
                }
            }

            return(pending);
        }
コード例 #23
0
 /// <summary>
 /// `JSON.DEL`
 ///
 /// Delete a value.
 ///
 /// Non-existing keys and paths are ignored. Deleting an object's root is equivalent to deleting the key from Redis.
 ///
 /// https://oss.redislabs.com/rejson/commands/#jsondel
 /// </summary>
 /// <param name="db"></param>
 /// <param name="key">Key where JSON object is stored.</param>
 /// <param name="path">Defaults to root if not provided.</param>
 /// <param name="commandFlags">Optional command flags.</param>
 /// <returns>Integer, specifically the number of paths deleted (0 or more).</returns>
 public static async Task <int> JsonDeleteAsync(this IDatabaseAsync db, RedisKey key, string path = ".",
                                                CommandFlags commandFlags = CommandFlags.None) =>
 (int)(await db.ExecuteAsync(JsonCommands.DEL, CombineArguments(key, path), flags: commandFlags)
       .ConfigureAwait(false));
コード例 #24
0
 /// <summary>
 /// `JSON.ARRINSERT`
 ///
 /// Insert the `json` value(s) into the array at `path` before the `index` (shifts to the right).
 ///
 /// The index must be in the array's range. Inserting at `index` 0 prepends to the array. Negative index values are interpreted as starting from the end.
 ///
 /// https://oss.redislabs.com/rejson/commands/#jsonarrinsert
 /// </summary>
 /// <param name="db"></param>
 /// <param name="key">The key of the JSON object that contains the array you want to insert an object into.</param>
 /// <param name="path">The path of the JSON array that you want to insert into.</param>
 /// <param name="index">The index at which you want to insert, 0 prepends and negative values are interpreted as starting from the end.</param>
 /// <param name="commandFlags">Optional command flags.</param>
 /// <param name="json">The object that you want to insert.</param>
 /// <returns>Array of nullable integer, specifically, for each path, the array's new size, or null element if the matching JSON value is not an array.</returns>
 public static async Task <int?[]> JsonArrayInsertAsync(this IDatabaseAsync db, RedisKey key, string path, int index,
                                                        CommandFlags commandFlags = CommandFlags.None, params object[] json) =>
 NullableIntArrayFrom((await db.ExecuteAsync(JsonCommands.ARRINSERT, CombineArguments(key, path, index, json),
                                             flags: commandFlags)
                       .ConfigureAwait(false)));
コード例 #25
0
        /// <summary>
        /// Create a new time-series.
        /// </summary>
        /// <param name="db">StackExchange.Redis IDatabaseAsync instance</param>
        /// <param name="key">Key name for timeseries</param>
        /// <param name="retentionTime">Optional: Maximum age for samples compared to last event time (in milliseconds)</param>
        /// <param name="labels">Optional: Collaction of label-value pairs that represent metadata labels of the key</param>
        /// <param name="uncompressed">Optional: Adding this flag will keep data in an uncompressed form</param>
        /// <param name="chunkSizeBytes">Optional: Each time-series uses chunks of memory of fixed size for time series samples.
        /// You can alter the default TSDB chunk size by passing the chunk_size argument (in Bytes)</param>
        /// <param name="policy">Optional: configure what to do on duplicate sample. When this is not set, the server-wide default will be used</param>
        /// <returns>If the operation executed successfully</returns>
        public static async Task <bool> TimeSeriesCreateAsync(this IDatabaseAsync db, string key, long?retentionTime = null, IReadOnlyCollection <TimeSeriesLabel> labels = null, bool?uncompressed = null, long?chunkSizeBytes = null, TsDuplicatePolicy?policy = null)
        {
            var args = BuildTsCreateArgs(key, retentionTime, labels, uncompressed, chunkSizeBytes, policy);

            return(ParseBoolean(await db.ExecuteAsync(TS.CREATE, args)));
        }