Example #1
0
        /// <summary>
        /// HGET http://redis.io/commands/hget
        /// </summary>
        public Task <RedisResult <TValue> > Get <TValue>(TKey field, CommandFlags commandFlags = CommandFlags.None)
        {
            return(TraceHelper.RecordSendAndReceive(Settings, Key, CallType, async() =>
            {
                long keySize;
                var rKey = Settings.ValueConverter.Serialize(field, out keySize);

                var rValue = await Command.HashGetAsync(Key, rKey, commandFlags).ForAwait();

                long valueSize;
                var value = RedisResult.FromRedisValue <TValue>(rValue, Settings, out valueSize);

                return Tracing.CreateSentAndReceived(new { field }, keySize, value, valueSize);
            }));
        }
Example #2
0
        /// <summary>
        /// HMGET http://redis.io/commands/hmget
        /// </summary>
        public Task <Dictionary <TKey, TValue> > Get <TValue>(TKey[] fields, IEqualityComparer <TKey> dictionaryEqualityComparer = null, CommandFlags commandFlags = CommandFlags.None)
        {
            dictionaryEqualityComparer = dictionaryEqualityComparer ?? EqualityComparer <TKey> .Default;

            return(TraceHelper.RecordSendAndReceive(Settings, Key, CallType, async() =>
            {
                long keySize = 0;
                var hashFields = fields.Select(x =>
                {
                    long s;
                    var rKey = Settings.ValueConverter.Serialize(x, out s);
                    keySize += s;
                    return rKey;
                }).ToArray();

                var rValues = await Command.HashGetAsync(Key, hashFields, commandFlags).ForAwait();

                long valueSize = 0;
                var result = fields
                             .Zip(rValues, (key, x) =>
                {
                    if (!x.HasValue)
                    {
                        return new { key, rValue = default(TValue), x.HasValue }
                    }
                    ;

                    long s;
                    var rValue = Settings.ValueConverter.Deserialize <TValue>(x, out s);
                    valueSize += s;
                    return new { key, rValue, x.HasValue };
                })
                             .Where(x => x.HasValue)
                             .ToDictionary(x => x.key, x => x.rValue, dictionaryEqualityComparer);

                return Tracing.CreateSentAndReceived(new { fields }, keySize, result, valueSize);
            }));