当前位置: 首页>>代码示例>>C#>>正文


C# RedisClient.HSet方法代码示例

本文整理汇总了C#中RedisClient.HSet方法的典型用法代码示例。如果您正苦于以下问题:C# RedisClient.HSet方法的具体用法?C# RedisClient.HSet怎么用?C# RedisClient.HSet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RedisClient的用法示例。


在下文中一共展示了RedisClient.HSet方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestHGetAll

        public void TestHGetAll()
        {
            using(var mock = new MockConnector("localhost", 9999, "*2\r\n$6\r\nfield1\r\n$5\r\ntest1\r\n"))
            using(var redis = new RedisClient(mock))
            {
                var response = redis.HGetAll("test");
                Assert.Equal(1, response.Length);
                Assert.Equal("field1", response[0].Field);
                Assert.Equal("test1", (string)response[0].Value);
                Assert.Equal("*2\r\n$7\r\nHGETALL\r\n$4\r\ntest\r\n", mock.GetMessage());
            }

            this.RealCall(redis =>
            {
                redis.HSet("test", "field1", "value1");
                redis.HSet("test", "field2", "value2");

                var response = redis.HGetAll("test");
                Assert.Equal(2, response.Length);
                for(int i = 0; i < 2; i++)
                {
                    Assert.Equal("field" + (i + 1), response[i].Field);
                    Assert.Equal("value" + (i + 1), (string)response[i].Value);
                }
            });
        }
开发者ID:glorylee,项目名称:Aoite,代码行数:26,代码来源:RedisHashTests.cs

示例2: TestHDel

        public void TestHDel()
        {
            using(var mock = new MockConnector("localhost", 9999, ":2\r\n"))
            using(var redis = new RedisClient(mock))
            {
                Assert.Equal(2, redis.HDel("test", "test1", "test2"));
                Assert.Equal("*4\r\n$4\r\nHDEL\r\n$4\r\ntest\r\n$5\r\ntest1\r\n$5\r\ntest2\r\n", mock.GetMessage());
            }

            this.RealCall(redis =>
            {
                redis.HSet("test", "field1", "value1");
                redis.HSet("test", "field2", "value2");
                Assert.Equal(2, redis.HDel("test", "field1", "field2"));
            });
        }
开发者ID:glorylee,项目名称:Aoite,代码行数:16,代码来源:RedisHashTests.cs

示例3: TestHGet

        public void TestHGet()
        {
            using(var mock = new MockConnector("localhost", 9999, "$5\r\nvalue\r\n"))
            using(var redis = new RedisClient(mock))
            {
                Assert.Equal("value", (string)redis.HGet("test", "field"));
                Assert.Equal("*3\r\n$4\r\nHGET\r\n$4\r\ntest\r\n$5\r\nfield\r\n", mock.GetMessage());
            }

            this.RealCall(redis =>
            {
                redis.HSet("test", "field", "value");
                Assert.Equal("value", (string)redis.HGet("test", "field"));
            });
        }
开发者ID:glorylee,项目名称:Aoite,代码行数:15,代码来源:RedisHashTests.cs

示例4: TestHExists

        public void TestHExists()
        {
            using(var mock = new MockConnector("localhost", 9999, ":1\r\n"))
            using(var redis = new RedisClient(mock))
            {
                Assert.True(redis.HExists("test", "field"));
                Assert.Equal("*3\r\n$7\r\nHEXISTS\r\n$4\r\ntest\r\n$5\r\nfield\r\n", mock.GetMessage());
            }

            this.RealCall(redis =>
            {
                redis.HSet("test", "field", "value1");
                Assert.True(redis.HExists("test", "field"));
                Assert.False(redis.HExists("not_exists_key", "field"));
                Assert.False(redis.HExists("test", "not_exists_field"));
            });
        }
开发者ID:glorylee,项目名称:Aoite,代码行数:17,代码来源:RedisHashTests.cs

示例5: Main

    static void Main(string[] args)
    {
        // You may download Redis for Windows from https://github.com/MSOpenTech/redis/tree/2.6/bin/release
        // Start the Redis server by double-click on redis-server.exe
        // Start the Redis client by double-click on the redis-cli.exe
        // Then start the VS project to see the result on the Console

        using (var redisClient = new RedisClient())
        {
            // -----------------------------------------------------------
            // Adds words and their translations to our EnBg dictionary
            // ----------------------------------------------------------
            redisClient.HSet("EnBg", "tree", "дърво");
            redisClient.HSet("EnBg", "apple", "ябълка");
            redisClient.HSet("EnBg", "strawberry", "ягода");
            redisClient.HSet("EnBg", "blueberry", "боровинка");
            redisClient.HSet("EnBg", "peach", "праскова");
            redisClient.HSet("EnBg", "cherry", "череша");
            redisClient.HSet("EnBg", "grape", "грозде");

            // ---------------------------------------
            // List all words and their translations
            // ----------------------------------------
            string[] allWords = redisClient.HKeys("EnBg");

            Console.WriteLine("Word -> Translation");
            Console.WriteLine(new string('-', 30));
            for (int i = 0; i < allWords.Length; i++)
            {
                Console.WriteLine(allWords[i] + " -> " + redisClient.HGet("EnBg", allWords[i]));
            }
            Console.WriteLine();

            // ----------------------------------------
            // Find the translation of given word
            // ----------------------------------------
            Console.WriteLine("Find translation of a word");
            Console.WriteLine(new string('-', 30));
            Console.WriteLine("Translation of 'tree' is {0}", redisClient.HGet("EnBg", "tree"));
            Console.WriteLine("Translation of 'apple' is {0}", redisClient.HGet("EnBg", "apple"));
            Console.WriteLine("Translation of 'cherry' is {0}", redisClient.HGet("EnBg", "cherry"));
        }
    }
开发者ID:sabrie,项目名称:TelerikAcademy,代码行数:43,代码来源:DictionaryInRedis.cs

示例6: Main

        //static PooledRedisClientManager pooledClientManager = new PooledRedisClientManager("localhost");
        static void Main(string[] args)
        {
            
            using (var clienteRedis = new RedisClient("localhost",6379))
            //using (clienteRedis)
            {
                clienteRedis.ConnectTimeout = 5000;
                
                ServiceStack.Licensing.RegisterLicense(@"TRIAL30SANTANA - e1JlZjpUUklBTDMwU0FOVEFOQSxOYW1lOkhlbnJpcXVlIFNhbnRhbmEsVHlwZTpUcmlhbCxIYXNoOlFWR0ZSejNMcjR4NXQrS0xKYm0ySVpaaEl6OFV6c052YzY3OWRGYXdVMTBLNmNFSVpNaTdKK1VnL01jcFZrdlZxb05rUE9aaklNUFQ1R01sY29rQkZBOGtpK1ZhS1lVSDNBNHNDWUhvT0FXekhpaUpFeW9XSkJaVy9GN0I4WmVmQ1dMUTdicWpBZUFONGZXOUVFcW5UVW1IU2Q4MjROVC9VcFB3cXN0UkZ6MD0sRXhwaXJ5OjIwMTYtMDItMTB9");

                Stopwatch stopWatch = new Stopwatch();

                stopWatch.Start();
                KeyValue keyValue = new KeyValue();
                //Clientes
                IList<Locadora.Cliente> clientesList = keyValue.GetClientes;
                List<string> chavesClienteList = keyValue.GeraChaveCliente();
                List<Dictionary<string, string>> camposClienteList = keyValue.GeraCamposCliente();

                //Categoria
                IList<Locadora.Categoria> categoriaList = keyValue.GetCategorias;
                List<string> chavesCategoriaList = keyValue.GeraChaveCategoria();
                List<Dictionary<string, string>> camposCategoriaList = keyValue.GeraCamposCategorias();

                //Filmes
                IList<Locadora.Filme> filmeList = keyValue.GetFilmes;
                List<string> chavesFilmeList = keyValue.GeraChaveFilme();
                List<Dictionary<string, string>> camposFilmeList = keyValue.GeraCamposFilmes();

                //Locadoras
                IList<Locadora.Locacao> locacaoList = keyValue.GetLocacoes;
                List<string> chavesLocacaoList = keyValue.GeraChaveLocacao();
                List<Dictionary<string, string>> camposLocacaoList = keyValue.GeraCamposLocacao();

                stopWatch.Stop();
                Console.WriteLine("Criação de Objetos: {0:hh\\:mm\\:ss}", stopWatch.Elapsed);
                Console.ReadKey();

               /* stopWatch.Start();
                foreach (var item in clientesList)
                {
                    Console.WriteLine("Cod Cliente {0} | Nome {1} | Sexo {2} | Data Nascimento {3}", item.CodCliente, item.NomeCliente, item.Sexo, item.DatNascimento);
                }
                stopWatch.Stop();
                Console.WriteLine("Exibição de Objetos: {0:hh\\:mm\\:ss}", stopWatch.Elapsed);

                //Inserindo no Redis
                /*Perguntar ao professor como manipula Bytes, para podermos usar o HMset
                Porém, sua implementação é tão diferente que acho que não vale a pena.
                */


                //Cliente
                stopWatch = new Stopwatch();
                stopWatch.Start();
                int i = 0;
                foreach (var d in camposClienteList)
                {
                    foreach (var campoValor in d)
                    {
                        clienteRedis.HSet(chavesClienteList[i], campoValor.Key.ToUtf8Bytes(), campoValor.Value.ToUtf8Bytes());
                    }
                    i++;
                }
                stopWatch.Stop();
                Console.WriteLine("Inserção Cliente no Redis: {0:hh\\:mm\\:ss}", stopWatch.Elapsed);
                ////ToUtf8Bytes()

                //Categoria
                stopWatch = new Stopwatch();
                stopWatch.Start();
                i = 0;
                foreach (var dictionary in camposCategoriaList)
                {
                    foreach (var campoValor in dictionary)
                    {
                        clienteRedis.HSet(chavesCategoriaList[i], campoValor.Key.ToUtf8Bytes(), campoValor.Value.ToUtf8Bytes());
                    }
                    i++;
                }
                stopWatch.Stop();
                Console.WriteLine("Inserção Categoria no Redis: {0:hh\\:mm\\:ss}", stopWatch.Elapsed);

                //Filmes
                stopWatch = new Stopwatch();
                stopWatch.Start();
                i = 0;
                foreach (var dictionary in camposFilmeList)
                {
                    foreach (var campoValor in dictionary)
                    {
                        clienteRedis.HSet(chavesFilmeList[i], campoValor.Key.ToUtf8Bytes(), campoValor.Value.ToUtf8Bytes());
                    }
                    i++;
                }
                stopWatch.Stop();
                Console.WriteLine("Inserção Filmes no Redis: {0:hh\\:mm\\:ss}", stopWatch.Elapsed);

                //Locacao
//.........这里部分代码省略.........
开发者ID:rikes,项目名称:TesteRedis,代码行数:101,代码来源:ProgramServiceStack.cs

示例7: TestHGetAllT

        public void TestHGetAllT()
        {
            using(var mock = new MockConnector("localhost", 9999, "*2\r\n$6\r\nfield1\r\n$5\r\ntest1\r\n"))
            using(var redis = new RedisClient(mock))
            {
                var response = redis.HGetAll<HGetAllModel>("test");
                Assert.Equal("test1", response.Field1);
                Assert.Null(response.Field2);
                Assert.Equal("*2\r\n$7\r\nHGETALL\r\n$4\r\ntest\r\n", mock.GetMessage());
            }

            this.RealCall(redis =>
            {
                redis.HSet("test", "field1", "value1");
                redis.HSet("test", "field2", "value2");

                var response = redis.HGetAll<HGetAllModel>("test");

                Assert.Equal("value1", response.Field1);
                Assert.Equal("value2", response.Field2);
            });
        }
开发者ID:glorylee,项目名称:Aoite,代码行数:22,代码来源:RedisHashTests.cs

示例8: TestHSetNX

        public void TestHSetNX()
        {
            using(var mock = new MockConnector("localhost", 9999, ":1\r\n"))
            using(var redis = new RedisClient(mock))
            {
                Assert.True(redis.HSet("test", "field1", "test1", true));
                Assert.Equal("*4\r\n$6\r\nHSETNX\r\n$4\r\ntest\r\n$6\r\nfield1\r\n$5\r\ntest1\r\n", mock.GetMessage());
            }

            this.RealCall(redis =>
            {
                Assert.True(redis.HSet("test", "field1", "value1", true));
                Assert.False(redis.HSet("test", "field1", "value1", true));

                var response = redis.HKeys("test");
                Assert.Equal(1, response.Length);
                Assert.Equal("field1", response[0]);
            });
        }
开发者ID:glorylee,项目名称:Aoite,代码行数:19,代码来源:RedisHashTests.cs

示例9: TestHMGet

        public void TestHMGet()
        {
            using(var mock = new MockConnector("localhost", 9999, "*2\r\n$5\r\ntest1\r\n$5\r\ntest2\r\n"))
            using(var redis = new RedisClient(mock))
            {
                var response = redis.HMGet("test", "field1", "field2");
                Assert.Equal(2, response.Length);
                Assert.Equal("test1", (string)response[0]);
                Assert.Equal("test2", (string)response[1]);
                Assert.Equal("*4\r\n$5\r\nHMGET\r\n$4\r\ntest\r\n$6\r\nfield1\r\n$6\r\nfield2\r\n", mock.GetMessage());
            }

            this.RealCall(redis =>
            {
                redis.HSet("test", "field1", "value1");
                redis.HSet("test", "field2", "value2");

                var response = redis.HMGet("test", "field1", "field2");
                Assert.Equal(2, response.Length);
                Assert.Equal("value1", (string)response[0]);
                Assert.Equal("value2", (string)response[1]);
            });
        }
开发者ID:glorylee,项目名称:Aoite,代码行数:23,代码来源:RedisHashTests.cs

示例10: TestHSet

 public void TestHSet()
 {
     using (var mock = new FakeRedisSocket(":1\r\n"))
     using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999)))
     {
         Assert.IsTrue(redis.HSet("test", "field1", "test1"));
         Assert.AreEqual("*4\r\n$4\r\nHSET\r\n$4\r\ntest\r\n$6\r\nfield1\r\n$5\r\ntest1\r\n", mock.GetMessage());
     }
 }
开发者ID:DTBruce,项目名称:csredis,代码行数:9,代码来源:HashTests.cs


注:本文中的RedisClient.HSet方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。