Basic Tutorials of Redis(3) -Hash
When you first saw the name of Hash,what do you think?HashSet,HashTable or other data structs of C#?As for me,
the first time I saw the Hash,I considered is as the HashTable.Actually,Hash can identify with HashTable,the same as
DataRow.A row data of table can Regular as a Hash's data.The below picture may help you to card the point.

Hash to the database?And how can we get the Hash from the database.Command hset,hmset,hget,hmget can help us to
solve those two question.Now I use hset to add a key named user-1 with a filed named name , and the value of the filed is
hset user- name catcher
hget user- name
hmset user- age gender male
hmget user- name age gender
the Hash.And it will return a integer,meaning there are 3 fileds in the user-1.
hlen user-
hgetall command,this command will return all of the fileds and the values of this key.
hgetall user-
gender filed from the user-1.
hdel user- gender
job.As you can see,I judge wheather gender and name exists in the user-1.
hexists user- gender
hexists user- name
values of the hash.At this situation,some people may use hgetall to finish the requirements,but I don't suggest to do
more than the request.So I will use the hkeys to get all the fileds of the hash,and use the hvals to get all the values of
the hash.
hkeys user-
hvals user-
How about increase a filed's value like the string do.As for me ,both of the increased command and decreased command
are the same.Because of their regular usage.For example,I increase the age of the user-1 by 2, and you will get the result like
the below image.
hincr user- age
//hset hget hmset hmget
db.HashSet("user-1", "name", "catcher");
var user_1 = new HashEntry[] { new HashEntry("age",),new HashEntry("gender","male") };
db.HashSet("user-1", user_1); Console.WriteLine("the name of user-1 is {0}",db.HashGet("user-1","name"));
var user_1_fileds = new RedisValue[] { "name","age","gender" };
var user_1_values = db.HashGet("user-1", user_1_fileds);
foreach (var item in user_1_values)
{
Console.WriteLine(item);
} //hlen
Console.WriteLine(string.Format("the number of filed in user-1 is {0}",db.HashLength("user-1"))); //hgetall
var all = db.HashGetAll("user-1");
foreach (var item in all)
{
Console.WriteLine(string.Format("the {0} of user-1 is {1}",item.Name,item.Value));
} //hdel
db.HashDelete("user-1", "gender");
var all_after_del = db.HashGetAll("user-1");
foreach (var item in all_after_del)
{
Console.WriteLine(string.Format("the {0} of user-1 is {1}", item.Name, item.Value));
} //hexists
Console.WriteLine(string.Format("gender {0} in the user-1", db.HashExists("user-1", "gender")?"is":"isn't"));
Console.WriteLine(string.Format("gender {0} in the user-1", db.HashExists("user-1", "name") ? "is" : "isn't")); //hkeys
var keys = db.HashKeys("user-1");
Console.WriteLine("the keys of user-1 are as follow:");
foreach (var item in keys)
{
Console.WriteLine(item);
} //hvals
var values = db.HashValues("user-1");
Console.WriteLine("the values of user-1 are as follow:");
foreach (var item in values)
{
Console.WriteLine(item);
} //hincrby
Console.WriteLine(string.Format("after Increase user-1's age by 2,the age of user-1 is {0}",db.HashIncrement("user-1","age",)));
Basic Tutorials of Redis(3) -Hash的更多相关文章
- Basic Tutorials of Redis(9) -First Edition RedisHelper
After learning the basic opreation of Redis,we should take some time to summarize the usage. And I w ...
- Basic Tutorials of Redis(2) - String
This post is mainly about how to use the commands to handle the Strings of Redis.And I will show you ...
- Basic Tutorials of Redis(8) -Transaction
Data play an important part in our project,how can we ensure correctness of the data and prevent the ...
- Basic Tutorials of Redis(4) -Set
This post will introduce you to some usages of Set in Redis.The Set is a unordered set,it means that ...
- Basic Tutorials of Redis(7) -Publish and Subscribe
This post is mainly about the publishment and subscription in Redis.I think you may subscribe some o ...
- Basic Tutorials of Redis(6) - List
Redis's List is different from C#'s List,but similar with C#'s LinkedList.Sometimes I confuse with t ...
- Basic Tutorials of Redis(5) - Sorted Set
The last post is mainly about the unsorted set,in this post I will show you the sorted set playing a ...
- Basic Tutorials of Redis(1) - Install And Configure Redis
Nowaday, Redis became more and more popular , many projects use it in the cache module and the store ...
- redis的hash操作在集中式session中的应用
在集群部署时,为了高可用性的目的,往往把session进行共享,共享分为两种:session复制和集中式管理. redis在session集中式管理中可以起到比较大的作用. 制约session集中式共 ...
随机推荐
- 客户端的验证插件validator
简单,智能,令人愉悦的表单验证~~~ 官方文档:http://www.niceue.com/validator/ <!DOCTYPE html> <html> <head ...
- 理解 .NET Platform Standard
相关博文:ASP.NET 5 Target framework dnx451 and dnxcore50 .NET Platform Standard:https://github.com/dotne ...
- jquery屏幕滚动计算事件总结
获取浏览器显示区域(可视区域)的高度 : $(window).height(); 获取浏览器显示区域(可视区域)的宽度 : $(window).width(); 获取页面的文档高度: $(docume ...
- python 数据类型 ---文件一
1.文件的操作流程: 打开(open), 操作(read,write), 关闭(close) 下面分别用三种方式打开文件,r,w,a 模式 . "a"模式将不会覆盖原来的文件内容, ...
- HTML5游戏源码 飞翔的字母 可自定义内容
相信大家都玩过飞翔的小鸟吧,当然,可能已经有很多人因为这个游戏砸了不少手机.吼吼. 废话不多说,回到主题,源码如下. 博客园上传空间大小有限制,没法上传了,需要打包源码的朋友们请留言邮箱地址.当然还有 ...
- Configure a bridged network interface for KVM using RHEL 5.4 or later?
environment Red Hat Enterprise Linux 5.4 or later Red Hat Enterprise Linux 6.0 or later KVM virtual ...
- 自定义ConfigSection
CCustom configuration section with intelisense
- 《CPU的工作过程》
本文转载自inter官方网址:https://software.intel.com/zh-cn/articles/book-Processor-Architecture_CPU_work_proces ...
- 端盘子的服务生到月薪一万五的IT精英,你能相信吗
一直以来,我都觉得自己不是一个有故事的人. 以前的我,是个乖宝宝,对父母言听计从,特别内向,甚至一度感觉到自卑.不上学之后,我干过送货员,去工地除泥搬砖,当过油漆工,去过工厂,还去饭店当过端盘子的服务 ...
- 微软将向Linux用户提供SQL Server程序
微软公司(Microsoft Corp., MSFT)将向Linux操作系统的用户提供旗下一项最赚钱的产品,这是该公司几年前无法想像的举措.这家软件巨头周一表示,将向免费的Linux Server提供 ...