您的位置:首页 > 数据库 > Redis

redis简单的读写

2016-04-15 11:24 357 查看
redis简单的读写记录key value。首先要引用redes 算了,还是代码来说话吧。麻烦。
链接方式
//引用
public static PooledRedisClientManager poolreds;
//这个对应的redis的库
static int port = 1;

static RedisPool()
{
try
{
// 对于的redis库的 密码 ip 端口
RedisUrlopenid=“密码@ip:端口”

poolreds = new PooledRedisClientManager(port, new string[] { ConfigurationManager.AppSettings["RedisUrlopenid"] }); } catch (Exception ex) { } }
  对于上面的:写/// <summary>
/// 缓存到Redis中
/// </summary>
/// <param name="key">key值</param>
/// <param name="danhaoList">详细的信息</param>
public static void EnqueueList(string key, string obj)
{
using (var client = poolreds.GetClient())
{
//队列使用
if (obj != null)
{
client.AddItemToList(key, obj);
}
}
}  
对于上面的:读

// //<summary>
// //读取当前
// //</summary>
// //<param name="key"></param>
// //<returns></returns>
public static string DequeueModel(string key)
{
using (var client = poolreds.GetClient())
{
string danhao = client.GetItemFromList(key, 0);
return danhao;
}
}
  // //<summary>
// //判断当前是否有记录
// //</summary>
// //<param name="key"></param>
// //<returns></returns>
public static long GetListCount(string key)
{
using (var client = poolreds.GetClient())
{
long count = client.GetListCount(key);
return count;
}
}  这个是插入到一个list里面。如图
插入到统一的kjgz2016-04-08 list里面。list的里面又可以插入很多记录。一个key 对于很多value。可以记录很多东西。很好用的一种排版不是很好啊。嘿嘿。。。 后面还有哦
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: