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数据库完全在内存中,使用磁盘仅用 ...
随机推荐
- 【接口开发】浅谈 SOAP Webserver 与 Restful Webserver 区别
接口,强大,简单,交互,跨越平台 下面简单阐述这两大接口思想 一 REST: REST是一种架构风格,其核心是面向资源,REST专门针对网络应用设计和开发方式,以降低开发的复杂性,提高系统的可伸缩性. ...
- 前端学Markdown
前面的话 我个人理解,Markdown就是一个富文本编辑器语言,类似于sass对于css的功能,Markdown也可以叫做HTML预处理器,只不过它是一门轻量级的标记语言,可以更简单的实现HTML ...
- 使用Zabbix监控Oracle数据库
Orabbix介绍 监控Oracle数据库我们需要安装第三方提供的Zabbix插件,我们先测试比较有名的Orabbix,http://www.smartmarmot.com/product/orabb ...
- Android Notification 详解——基本操作
Android Notification 详解 版权声明:本文为博主原创文章,未经博主允许不得转载. 前几天项目中有用到 Android 通知相关的内容,索性把 Android Notificatio ...
- 高效而稳定的企业级.NET Office 组件Spire(.NET组件介绍之二)
在项目开发中,尤其是企业的业务系统中,对文档的操作是非常多的,有时几乎给人一种错觉的是”这个系统似乎就是专门操作文档的“.毕竟现在的很多办公中大都是在PC端操作文档等软件,在这些庞大而繁重的业务中,单 ...
- 通过AngularJS实现前端与后台的数据对接(一)——预备工作篇
最近,笔者在做一个项目:使用AngularJS,从而实现前端与后台的数据对接.笔者这是第一次做前端与后台的数据对接的工作,因此遇到了许多问题.笔者在这些问题中,总结了一些如何实现前端与后台的数据对接的 ...
- slf4j中的MDC
slf4j中MDC是什么鬼 slf4j除了trace.debug.info.warn.error这几个日志接口外,还可以配合MDC将数据写入日志.换句话说MDC也是用来记录日志的,但它的使用方式与使用 ...
- 学习C的笔记
[unsigned] 16位系统中一个int能存储的数据的范围为-32768~32767,而unsigned能存储的数据范围则是0~65535.由于在计算机中,整数是以补码形式存放的.根据最高位的不同 ...
- Linux 利用Google Authenticator实现ssh登录双因素认证
1.介绍 双因素认证:双因素身份认证就是通过你所知道再加上你所能拥有的这二个要素组合到一起才能发挥作用的身份认证系统.双因素认证是一种采用时间同步技术的系统,采用了基于时间.事件和密钥三变量而产生的一 ...
- Nlog配置实例
彩色Console target <?xml version="1.0" encoding="utf-8" ?> <nlog xmlns= ...