/// <summary>
        /// `JSON.QGET`
        ///
        /// Query a JSON index for an existing object.
        ///
        /// RedisJson documentation link forthcoming.
        /// </summary>
        /// <param name="db"></param>
        /// <param name="index">Name of the index.</param>
        /// <param name="query">Pattern being applied to the index.</param>
        /// <param name="path">[Optional] Path to the expected value.</param>
        /// <typeparam name="TResult"></typeparam>
        /// <returns></returns>
        public static async Task <IndexedCollection <TResult> > JsonIndexGetAsync <TResult>(this IDatabase db, string index, string query, string path = "")
        {
            var result = await db.JsonIndexGetAsync(index, query, path);

            var serializedResult = SerializerProxy.Deserialize <IDictionary <string, IEnumerable <TResult> > >(result);

            return(new IndexedCollection <TResult>(serializedResult));
        }
Exemplo n.º 2
0
        /// <summary>
        /// `JSON.MGET`
        ///
        /// Returns an IEnumerable of the specified result type. Non-existing keys and non-existent paths are returnd as type default.
        ///
        /// 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>
        /// <typeparam name="TResult">The type to deserialize the value as.</typeparam>
        /// <returns>IEnumerable of TResult, non-existent paths/keys are returned as default(TResult).</returns>
        public static IEnumerable <TResult> JsonMultiGet <TResult>(this IDatabase db, RedisKey[] keys, string path = ".")
        {
            var serializedResults = db.JsonMultiGet(keys, path);

            foreach (var serializedResult in serializedResults)
            {
                if (serializedResult.IsNull)
                {
                    yield return(default(TResult));
                }
                else
                {
                    yield return(SerializerProxy.Deserialize <TResult>(serializedResult));
                }
            }
        }
        /// <summary>
        /// `JSON.MGET`
        ///
        /// Returns an IEnumerable of the specified result type. Non-existing keys and non-existent paths are returnd as type default.
        ///
        /// 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>
        /// <typeparam name="TResult">The type to deserialize the value as.</typeparam>
        /// <returns>IEnumerable of TResult, non-existent paths/keys are returned as default(TResult).</returns>
        public static async Task <IEnumerable <TResult> > JsonMultiGetAsync <TResult>(this IDatabase db, RedisKey[] keys, string path = ".")
        {
            IEnumerable <TResult> CreateResult(RedisResult[] srs)
            {
                foreach (var sr in srs)
                {
                    if (sr.IsNull)
                    {
                        yield return(default(TResult));
                    }
                    else
                    {
                        yield return(SerializerProxy.Deserialize <TResult>(sr));
                    }
                }
            }

            return(CreateResult(await db.JsonMultiGetAsync(keys, path)));
        }
        /// <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>
        /// <typeparam name="TResult">The type to deserialize the value as.</typeparam>
        /// <returns></returns>
        public static async Task <TResult> JsonArrayPopAsync <TResult>(this IDatabase db, RedisKey key, string path = ".", int index = -1)
        {
            var result = await db.JsonArrayPopAsync(key, path, index);

            return(SerializerProxy.Deserialize <TResult>(result));
        }
        /// <summary>
        /// `JSON.GET`
        ///
        /// Return the value at `path` as a deserialized value.
        ///
        /// 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="paths">The path(s) of the JSON properties that you want to return. By default, the entire JSON object will be returned.</param>
        /// <typeparam name="TResult">The type to deserialize the value as.</typeparam>
        /// <returns></returns>
        public static async Task <TResult> JsonGetAsync <TResult>(this IDatabase db, RedisKey key, bool noEscape = false, string indent = default, string newline = default, string space = default, params string[] paths)
        {
            var serializedResult = await db.JsonGetAsync(key, noEscape, indent, newline, space, paths);

            return(SerializerProxy.Deserialize <TResult>(serializedResult));
        }
Exemplo n.º 6
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>
        /// <typeparam name="TResult">The type to deserialize the value as.</typeparam>
        /// <returns></returns>
        public static TResult JsonArrayPop <TResult>(this IDatabase db, RedisKey key, string path = ".", int index = -1)
        {
            var result = db.JsonArrayPop(key, path, index);

            return(SerializerProxy.Deserialize <TResult>(result));
        }
Exemplo n.º 7
0
 /// <summary>
 /// `JSON.GET`
 ///
 /// Return the value at `path` as a deserialized value.
 ///
 /// 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="paths">The path(s) of the JSON properties that you want to return. By default, the entire JSON object will be returned.</param>
 /// <typeparam name="TResult">The type to deserialize the value as.</typeparam>
 /// <returns></returns>
 public static TResult JsonGet <TResult>(this IDatabase db, RedisKey key, bool noEscape = false, string indent = default, string newline = default, string space = default, params string[] paths) =>
 SerializerProxy.Deserialize <TResult>(db.JsonGet(key, noEscape, indent, newline, space, paths));