using System;
using System.Collections.Generic;
using ServiceStack.Redis; namespace SysBuild
{
class Program
{
//linux服务器地址
static private string host = "182.180.50.168";
//static private string host = "127.0.0.1";
static private int port = 6379;
static RedisClient redisClient = new RedisClient(host, port);//redis服务IP和端口
static void Main(string[] args)
{
//创建一个键a,指定值
redisClient.Set<string>("a", "1");
//获取键a对应的值
var a1 = redisClient.Get<string>("a");
//删除键a
redisClient.Remove("a");
//创建一个键a,指定值,并指定10s有效
redisClient.Set<string>("b", "1", new TimeSpan(0, 0, 60)); //队列操作之入队
redisClient.EnqueueItemOnList("list", "haha");
redisClient.EnqueueItemOnList("list", "haha111111111");
redisClient.EnqueueItemOnList("list", "haha22");
redisClient.EnqueueItemOnList("list", "hahset33333333333333333");
//读取队列深度
var a = redisClient.GetListCount("list");
//队列操作之出队
for (int i = 0; i < a; i++)
{
Console.WriteLine(redisClient.DequeueItemFromList("list"));
} redisClient.SetEntryInHash("Hash", "Name", "wujf");
redisClient.SetEntryInHash("Hash", "Age", "99");
redisClient.SetEntryInHash("Hash", "Sex", "男");
redisClient.SetEntryInHash("Hash", "Address", "上海市XX号XX室");
//集合类指定超时的方法
redisClient.ExpireEntryIn("Hash", new TimeSpan(0, 0, 100));
var dic = redisClient.GetAllEntriesFromHash("Hash");
Console.WriteLine("Key-----Value");
foreach (var keyVal in dic)
{
Console.WriteLine(string.Format("{0}-----{1}", keyVal.Key, keyVal.Value));
}
List<string> haskKey = redisClient.GetHashKeys("Hash");
List<string> haskVal = redisClient.GetHashValues("Hash");
foreach (string key in haskKey)
{
Console.WriteLine("HashID--Key:{0}", key);
}
foreach (string val in haskVal)
{
Console.WriteLine("HashID--val:{0}", val);
} //栈使用,先进后出
redisClient.PushItemToList("stack", "1");
redisClient.PushItemToList("stack", "2");
redisClient.PushItemToList("stack", "3");
redisClient.PushItemToList("stack", "4");
int count = redisClient.GetListCount("stack");
for (int i = 0; i < count; i++)
{
Console.WriteLine(redisClient.PopItemFromList("stack"));
} //对Set类型进行操作
redisClient.AddItemToSet("set", "ddd");
redisClient.AddItemToSet("set", "ccc");
redisClient.AddItemToSet("set", "tttt");
redisClient.AddItemToSet("set", "sssh");
redisClient.AddItemToSet("set", "hhhh");
HashSet<string> hashset = redisClient.GetAllItemsFromSet("set");
foreach (string str in hashset)
{
Console.WriteLine(str);
} //求并集
redisClient.AddItemToSet("set1", "aa");
redisClient.AddItemToSet("set1", "bb");
redisClient.AddItemToSet("set2", "bb");
redisClient.AddItemToSet("set2", "cc");
hashset = redisClient.GetUnionFromSets(new string[] { "set1", "set2" });
foreach (string str in hashset)
{
Console.WriteLine(str);
}
//求交集
hashset = redisClient.GetIntersectFromSets(new string[] { "set1", "set2" });
//求差集.
hashset = redisClient.GetDifferencesFromSet("set1", new string[] { "set2" }); //Sorted Set类型排序
redisClient.AddItemToSortedSet("sortList", "1");
redisClient.AddItemToSortedSet("sortList", "9");
redisClient.AddItemToSortedSet("sortList", "3");
redisClient.AddItemToSortedSet("sortList", "8");
List<string> sortList = redisClient.GetAllItemsFromSortedSet("sortList");
foreach (string str in sortList)
{
Console.WriteLine(str);
} Console.ReadKey();
}
}
}

ServiceStack.redis用法的更多相关文章

  1. .Net使用Redis详解之ServiceStack.Redis(七)

    序言 本篇从.Net如何接入Reis开始,直至.Net对Redis的各种操作,为了方便学习与做为文档的查看,我做一遍注释展现,其中会对list的阻塞功能和事务的运用做二个案例,进行记录学习. Redi ...

  2. ServiceStack.Redis订阅发布服务的调用(Z)

      1.Redis订阅发布介绍Redis订阅发布是一种消息通信模式:发布者(publisher)发送消息,订阅者(Subscriber)接受消息.类似于设计模式中的观察者模式.发布者和订阅者之间使用频 ...

  3. serviceStack.Redis 在PooledRedisClientManager 中设置密码

    ServiceStack.Redis 是一个C#访问Redis的客户端,可以说可以通过它实现所有需要Redis-Cli的功能.但是今天我在主Redis 实例设置了访问密码,而在slave 上没有设置, ...

  4. ServiceStack.Redis订阅发布服务的调用

    1.Redis订阅发布介绍 Redis订阅发布是一种消息通信模式:发布者(publisher)发送消息,订阅者(Subscriber)接受消息.类似于设计模式中的观察者模式. 发布者和订阅者之间使用频 ...

  5. Redis简介、与memcached比较、存储方式、应用场景、生产经验教训、安全设置、key的建议、安装和常用数据类型介绍、ServiceStack.Redis使用(1)

    1.NOSQL简介 nosql的产生并不是要彻底的代替关系型数据库,而是作为传统关系型数据库的一个补充. Facebook和360使用Cassandra来存储海量社交数据 Twitter在其url抓取 ...

  6. ServiceStack.Redis 使用教程

    http://www.cnblogs.com/shanyou/archive/2011/11/10/2245082.html https://github.com/ServiceStack/Servi ...

  7. 在使用Redis的客户端连接工具ServiceStack.Redis要注意的问题

    在使用Redis的客户端连接工具ServiceStack.Redis要注意的问题   Redis是一个非常NB的内存级的数据库,我们可以把很多”热数据“(即读写非常多的数据)放入其中来操作,这样就减少 ...

  8. 关于 ServiceStack.Redis 4.0 License

    今天更新了框架中的Redis驱动ServiceStack.Redis,最新版本4.0.5.0. 在做简单压力测试时出现异常,提示每小时允许6000个请求. The free-quota limit o ...

  9. ServiceStack.Redis.RedisNativeClient的方法“get_Db”没有实现

    Redis 4.0.0.0版本已经开始收费 Redis 4.0.5.0 已经完成收费 今日在更换Redis版本时 出现了ServiceStack.Redis.RedisNativeClient的方法“ ...

随机推荐

  1. qt下用启动图

    void showSplash(void) { QSplashScreen*splash=newQSplashScreen; splash->setPixmap(QPixmap(":/ ...

  2. c#QQ邮件编程学习(收发邮件)

    本次c#实现邮件管理编程的目的是实现第三方邮件管理,邮箱基于QQ邮箱,发送邮件直接采用.NET自带的System.Net.Mail类,接收邮件采用第三方组件Lumisoft.Net.现将基本实现的接收 ...

  3. 在Windows下搭建基于nginx的视频直播和点播系统

    http://my.oschina.net/gaga/blog/478480 一.软件准备 由于nginx原生是为linux服务的,因此官方并没有编译好的windows版本可以下载,要在windows ...

  4. java代码-----------逻辑运算符、 &&逻辑与 ||或

    总结: && :两者均满足.是true ||: 两者中有一个满足就为true,不然就是false package com.sads; public class shou { publi ...

  5. java代码---------常用的方法indexOf()和substring()方法的小结、主要是下标都是从0开始,很重要,错了就那个差远了啊

    package com.s.x; //indexOf()方法从字符起始处的第一个位子开始的位置 //substring public class Wang { public static void m ...

  6. java代码------实现从控制台输入整型,

    总结:主要是方法的调用不能错,比如浮点型,整型,字节型,so.on int ====hasNextInt() float--------hasNextfloat() short ====hasNext ...

  7. python中scipy学习——随机稀疏矩阵及操作

    1.生成随机稀疏矩阵: scipy中生成随机稀疏矩阵的函数如下: scipy.sparse.rand(m,n,density,format,dtype,random_state) 1 参数介绍: 参数 ...

  8. 在Eclipse中使用Maven部署项目的Tomcat

    方式一:打war包到tomcat/webapps目录 点击在项目上面 -> 右键 -> Run As -> Maven install 之后查看Maven输出路径: D:\apach ...

  9. Cookie与Session的复习

    Cookie Cookie是HTTP协议制定的.先由服务器保存Cookie到浏览器,再下次浏览器请求服务器时把上一次请求得到Cookie再归还给服务器.由服务器创建保存到客户端浏览器的一个键值对(由服 ...

  10. 【洛谷】P2904 [USACO08MAR]跨河River Crossing(dp)

    题目描述 Farmer John is herding his N cows (1 <= N <= 2,500) across the expanses of his farm when ...