Basic Tutorials of Redis(4) -Set
data was stored in the database randomly.And there are 15 commands you can use in Redis,the same as Hash.

can not only use it to add a single value to the key,but also multi values.For example,I add 11 to the key named
set-1 at first.Laterly I add 12 ~15 too.So easy the command is.When you execute the sadd command , the client
will return the amount of the set.
sadd set-
sadd set-

After executing the command sadd,it will return a integer to show us the amount of this set.But what can we
know the members of this set?We can use smembers to get all of the members in the set.
smembers set-

member of the set randomly.As the following picture,I remove a member from the set-1 firstly,and then I remove two
members from the set-1.At last,we will find that the set-1 only has 11 and 13.
spop set-
spop set-

ideas,not randomly.I removed the last two members from the set-1 by this command.At this time,I want to get all of the
members of the set-1 ,you will get the information that the set is empty.
srem set-

thing as well.The set-1 is empty now,I judge the member 11 whether exists in the set-11,it returns 0 meaning 11 is not
the member of the set.After adding members to this set,the second time to judge returns 1 meaning 11 is the member of set-1.
sismember set-

As all you know,we use the Property length or the method count to get how many members in the array by using C#.
In Redis,we get the numbers of members in a set by using scard.
scard set-

The commands I will show you next needs at lease two sets,so I have to add another one.And you will be familiar with
the set opreation of Mathematical.Command sinter will return the command members both set-1 and set-2 contain.Command
sunion will return all of the members both set-1 and set-2 contian.Command sdiff will return the difference members from the sets.
sinter set- set-
sunion set- set-
sdiff set- set-
sdiff set- set-

sinterstore inter-set set- set-
sunionstore union-set set- set-
sdiffstore diff-set- set- set-
sdiffstore diff-set- set- set-

After showing the native commands,we should turn to the usage of StackExchange.Redis.
//sadd smembers
db.SetAdd("set-1", );
var set_1 = new RedisValue[] {,,, };
db.SetAdd("set-1", set_1);
Console.WriteLine("the members of the set-1 :");
foreach (var item in db.SetMembers("set-1"))
{
Console.WriteLine(item);
} //spop srem
Console.WriteLine(string.Format("the value was poped is {0}", db.SetPop("set-1")));
Console.WriteLine(string.Format("the value was poped is {0}", db.SetPop("set-1")));
Console.WriteLine(string.Format("the value was poped is {0}", db.SetPop("set-1"))); db.SetRemove("set-1", db.SetMembers("set-1"));
Console.WriteLine(string.Format("amount of set-1 is {0}", db.SetMembers("set-1").Length)); //sismember
Console.WriteLine(string.Format("11 {0} the member of set-1",db.SetContains("set-1",)?"is":"isn't"));
var set_1_again = new RedisValue[] {, , , , };
db.SetAdd("set-1", set_1_again);
Console.WriteLine(string.Format("11 {0} the member of set-1", db.SetContains("set-1", ) ? "is" : "isn't")); //scard
Console.WriteLine(string.Format("amount of set-1 is {0}", db.SetLength("set-1"))); var set_2 = new RedisValue[] { , , , };
db.SetAdd("set-2", set_2); //sinter
Console.WriteLine("the result of intersect:");
foreach (var item in db.SetCombine(SetOperation.Intersect, new RedisKey[] { "set-1", "set-2" }))
{
Console.WriteLine(item);
}
// sunoin
Console.WriteLine("the result of union:");
foreach (var item in db.SetCombine(SetOperation.Union, new RedisKey[] { "set-1", "set-2" }))
{
Console.WriteLine(item);
}
//sdiff
Console.WriteLine("the result of difference1:");
foreach (var item in db.SetCombine(SetOperation.Difference, new RedisKey[] { "set-1", "set-2" }))
{
Console.WriteLine(item);
} Console.WriteLine("the result of difference2:");
foreach (var item in db.SetCombine(SetOperation.Difference, new RedisKey[] { "set-2", "set-1" }))
{
Console.WriteLine(item);
}

Basic Tutorials of Redis(4) -Set的更多相关文章
- 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(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(3) -Hash
When you first saw the name of Hash,what do you think?HashSet,HashTable or other data structs of C#? ...
- 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入门
Redis是一个开源,先进的key-value存储,并用于构建高性能,可扩展的Web应用程序的完美解决方案. Redis从它的许多竞争继承来的三个主要特点: Redis数据库完全在内存中,使用磁盘仅用 ...
随机推荐
- nodejs进阶(1)—输出hello world
下面将带领大家一步步学习nodejs,知道怎么使用nodejs搭建服务器,响应get/post请求,连接数据库等. 搭建服务器页面输出hello world var http = require ...
- Android 问题汇总(持续更新)
Q1:Error:(93, 12) 错误: 需要常量表达式 问题描述:这个问题是在添加一个module到项目中时遇到的,主要原因是因为原来module中的R文件是不会以final形式存在的,但是在mo ...
- ASP.NET MVC5+EF6+EasyUI 后台管理系统(74)-微信公众平台开发-自定义菜单
系列目录 引言 1.如果不借用Senparc.Weixin SDK自定义菜单,编码起来,工作量是非常之大 2.但是借助SDK似乎一切都是简单得不要不要的 3.自定义菜单无需要建立数据库表 4.自定义菜 ...
- 最新的 cocoaPods 安装方法
经过努力终于发现了最新的 解决cocoaPods安装的办法: taobao Gems 源已停止维护,现由 ruby-china 提供镜像服务 第一步:安装rvm, 不管需不需要升级ruby,rvm可以 ...
- Linux测试环境搭建的学习建议
随着Linux应用的扩展许多朋友开始接触Linux,根据学习Windwos的经验往往有一些茫然的感觉:不知从何处开始学起.这里介绍学习Linux测试环境搭建的一些建议. 一.Linux测试环境搭建从基 ...
- Dancing Links and Exact Cover
1. Exact Cover Problem DLX是用来解决精确覆盖问题行之有效的算法. 在讲解DLX之前,我们先了解一下什么是精确覆盖问题(Exact Cover Problem)? 1.1 Po ...
- [转]thinkphp 模板显示display和assign的用法
thinkphp 模板显示display和assign的用法 $this->assign('name',$value); //在 Action 类里面使用 assign 方法对模板变量赋值,无论 ...
- 基于Node.js实现一个小小的爬虫
以前一直听说有爬虫这种东西,稍微看了看资料,貌似不是太复杂. 正好了解过node.js,那就基于它来个简单的爬虫. 1.本次爬虫目标: 从拉钩招聘网站中找出“前端开发”这一类岗位的信息,并作相应页面分 ...
- 技术笔记:Indy的TIdSMTP改造,解决发送Html和主题截断问题
使用Indy来发邮件坑不少啊,只不过有比没有好吧,使用delphi6这种老工具没办法,只能使用了新一点的Indy版本9,公司限制... 1.邮件包含TIdText和TIdAttachment时会出现T ...
- 工大助手(C#与python交互)
工大助手(爬虫--C#与python交互) 基本内容 工大助手(桌面版) 实现登陆.查成绩.计算加权平均分等功能 团队人员 13070046 孙宇辰 13070003 张帆 13070004 崔巍 1 ...