Redis封装之Hash
RedisHashService:
/// <summary>
/// Hash:类似dictionary,通过索引快速定位到指定元素的,耗时均等,跟string的区别在于不用反序列化,直接修改某个字段
/// Hash的话,一个hashid-{key:value;key:value;key:value;}
/// 可以一次性查找实体,也可以单个,还可以单个修改
/// </summary>
public class RedisHashService : RedisBase
{
#region 添加
/// <summary>
/// 向hashid集合中添加key/value
/// </summary>
public bool SetEntryInHash(string hashid, string key, string value)
{
return RedisBase.iClient.SetEntryInHash(hashid, key, value);
}
/// <summary>
/// 如果hashid集合中存在key/value则不添加返回false,
/// 如果不存在在添加key/value,返回true
/// </summary>
public bool SetEntryInHashIfNotExists(string hashid, string key, string value)
{
return RedisBase.iClient.SetEntryInHashIfNotExists(hashid, key, value);
}
/// <summary>
/// 存储对象T t到hash集合中
/// </summary>
public void StoreAsHash<T>(T t)
{
RedisBase.iClient.StoreAsHash<T>(t);
}
#endregion #region 获取
/// <summary>
/// 获取对象T中ID为id的数据。
/// </summary>
public T GetFromHash<T>(object id)
{
return RedisBase.iClient.GetFromHash<T>(id);
}
/// <summary>
/// 获取所有hashid数据集的key/value数据集合
/// </summary>
public Dictionary<string, string> GetAllEntriesFromHash(string hashid)
{
return RedisBase.iClient.GetAllEntriesFromHash(hashid);
}
/// <summary>
/// 获取hashid数据集中的数据总数
/// </summary>
public long GetHashCount(string hashid)
{
return RedisBase.iClient.GetHashCount(hashid);
}
/// <summary>
/// 获取hashid数据集中所有key的集合
/// </summary>
public List<string> GetHashKeys(string hashid)
{
return RedisBase.iClient.GetHashKeys(hashid);
}
/// <summary>
/// 获取hashid数据集中的所有value集合
/// </summary>
public List<string> GetHashValues(string hashid)
{
return RedisBase.iClient.GetHashValues(hashid);
}
/// <summary>
/// 获取hashid数据集中,key的value数据
/// </summary>
public string GetValueFromHash(string hashid, string key)
{
return RedisBase.iClient.GetValueFromHash(hashid, key);
}
/// <summary>
/// 获取hashid数据集中,多个keys的value集合
/// </summary>
public List<string> GetValuesFromHash(string hashid, string[] keys)
{
return RedisBase.iClient.GetValuesFromHash(hashid, keys);
}
#endregion #region 删除
/// <summary>
/// 删除hashid数据集中的key数据
/// </summary>
public bool RemoveEntryFromHash(string hashid, string key)
{
return RedisBase.iClient.RemoveEntryFromHash(hashid, key);
}
#endregion #region 其它
/// <summary>
/// 判断hashid数据集中是否存在key的数据
/// </summary>
public bool HashContainsEntry(string hashid, string key)
{
return RedisBase.iClient.HashContainsEntry(hashid, key);
}
/// <summary>
/// 给hashid数据集key的value加countby,返回相加后的数据
/// </summary>
public double IncrementValueInHash(string hashid, string key, double countBy)
{
return RedisBase.iClient.IncrementValueInHash(hashid, key, countBy);
}
#endregion
}
Redis封装之Hash的更多相关文章
- [C#] 使用 StackExchange.Redis 封装属于自己的 Helper
使用 StackExchange.Redis 封装属于自己的 Helper 目录 核心类 ConnectionMultiplexer 字符串(String) 哈希(Hash) 列表(List) 有序集 ...
- [C#] 使用 StackExchange.Redis 封装属于自己的 RedisHelper
使用 StackExchange.Redis 封装属于自己的 RedisHelper 目录 核心类 ConnectionMultiplexer 字符串(String) 哈希(Hash) 列表(List ...
- python学习之-- redis模块操作 HASH
redis 操作 之 -Hash Hash 操作:hash在内存中的存储格式 name hash n1 ------> k1 -> v1 k2 -> v2 k3 -> v3hs ...
- Redis 哈希(Hash)
Redis hash 是一个string类型的field和value的映射表,hash特别适合用于存储对象. Redis 中每个 hash 可以存储 232 - 1 键值对(40多亿). 实例 red ...
- Redis数据类型之Hash(二)
前言: Redis hash是一个String类型的field和value的映射表.添加.删除操作复杂度平均为O(1),为什么是平均呢?因为Hash的内部结构包含zipmap和hash两种.hash特 ...
- Redis实战 - 3.Hash
hash Redis的Hash有点像一个对象(object),一个Hash里面可以存多个Key-Value对作为它的field,所以它通常可以用来表示对象. Hash里面能存放的值也能作为String ...
- redis下操作hash对象
redis下操作hash对象 hash用于存储对象,对象的格式为键值对 命令 设置 设置单个属性 HSET key field value 设置多个属性 HMSET key field value [ ...
- 6、Redis中对Hash类型的操作命令
写在前面的话:读书破万卷,编码如有神 -------------------------------------------------------------------- ------------ ...
- Redis原子性写入HASH结构数据并设置过期时间
Redis中提供了原子性命令SETEX或SET来写入STRING类型数据并设置Key的过期时间: > SET key value EX NX ok > SETEX key value ok ...
随机推荐
- bzoj4551 [HEOI2016]树
题目描述 在2016年,佳媛姐姐刚刚学习了树,非常开心.现在他想解决这样一个问题:给定一颗有根树(根为1),有以下 两种操作:1. 标记操作:对某个结点打上标记(在最开始,只有结点1有标记,其他结点均 ...
- 浅谈 MySQL的外键的作用
MySQL中外键的介绍: MySQL外键必须使用存储引擎为 innDB 其中MySAM 和MEMORYH这两种引擎不支持 由数据库自身保证数据一致性,完整性,更可靠,因为程序很难100%保证数据的 ...
- docker mysql镜像忽略表名大小写
原文:docker mysql镜像忽略表名大小写 1.安装mysql镜像 docker pull mysql/mysql-server 2.运行mysql docker run --net=host ...
- 响应http报文中的Date属性与cookie过期时间的关系
今天在測试.net时,发现一个莫名其妙的问题:cookie老是保存不到浏览器端; 经过细致的比对成功与不成功的报文,居然无意中发现好像Date与它有关系,这太让我意想不到了,从来不知道cookie保存 ...
- LeetCode【8】. String to Integer (atoi) --java实现
String to Integer (atoi) Implement atoi to convert a string to an integer. Hint: Carefully consider ...
- WPF-MVVM-Demo
MVVM The model-view-viewmodel is a typically WPF pattern. It consists of a view that gets all the us ...
- ubuntu,jdk安装成功后,点击eclipse,提示信息A Java RunTime Environment (JRE) or Java Development Kit (JDK)
A Java RunTime Environment (JRE) or Java Development Kit (JDK) must be available in order to run Ecl ...
- thinkphp5.0的验证码安装和相关错误
thinkphp5.0的验证码安装和相关错误 问题 只要是之前使用thinkphp5框架搭建网站的时候发现不管如何调用验证码都无法使用,按照官网要求,使用composer安装验证码出现报错Fatal ...
- TortoiseGit配合msysGit在Git@OSC代码托管的傻瓜教程
命令行太麻烦,肿么破?便便利用睡觉的时间解决了一点效率问题,tortoiseGit处理GitHub,一样可以处理 Git @osc ,虽然说可以用gitk来调出图形界面,but,我就是不想看见黑黑的命 ...
- struts2标签#、%、$取值
转自:https://blog.csdn.net/kosum/article/details/21375635 首先了解下OGNL的概念: OGNL是Object-Graph Navigation L ...