/// <summary> /// 清除某个业务模型下面的所有节点 /// </summary> /// <param name="nodeName">业务模型名称</param> /// <returns>bool</returns> // public static bool FlushAll(string nodeName,string logicName) // { // RedisNode cfg = RedisConfig.GetNode(nodeName); // return cfg.Set(db => db.KeyDelete(nodeName)); // } /// <summary> /// 查询指定的key是否存在 /// </summary> /// <param name="nodeName"></param> /// <param name="logicName">logicName</param> /// <param name="key"></param> /// <returns></returns> public static bool ContainsKey(string nodeName, string logicName, string key) { RedisNode cfg = RedisConfig.GetNode(nodeName); string k = getKey(logicName, key); return(cfg.Get <bool>(db => db.KeyExists(k))); }
/// <summary> /// 获取字符串对象 /// </summary> /// <param name="nodeName">节点名称</param> /// <param name="logicName">业务名称</param> /// <param name="key">key</param> /// <returns>string</returns> public static string Get(string nodeName, string logicName, string key) { RedisNode cfg = RedisConfig.GetNode(nodeName); string k = getKey(logicName, key); return(cfg.Get <string>(db => db.StringGet(k))); }
public static string LockQuery(string nodeName, string logicName, string key) { RedisNode cfg = RedisConfig.GetNode(nodeName); string k = getKey(logicName, key); return(cfg.Get <string>(db => { return db.LockQuery(k); })); }
public static bool LockRelease(string nodeName, string logicName, string key, string value) { RedisNode cfg = RedisConfig.GetNode(nodeName); string k = getKey(logicName, key); return(cfg.Get <bool>(db => { return db.LockRelease(k, value, CommandFlags.FireAndForget); })); }
public static bool LockTake(string nodeName, string logicName, string key, string value, TimeSpan expiry) { RedisNode cfg = RedisConfig.GetNode(nodeName); string k = getKey(logicName, key); return(cfg.Get <bool>(db => { return db.LockTake(k, value, expiry); })); }
public static byte[] DumpKey(string nodeName, string logicName, string key) { RedisNode cfg = RedisConfig.GetNode(nodeName); string k = getKey(logicName, key); return(cfg.Get(db => { return db.KeyDump(k); })); }
/// <summary> /// 弹出 最大的日志信息 /// </summary> /// <param name="nodeName">节点名称</param> /// <param name="logicName">业务名称</param> /// <param name="key">队列名称</param> /// <returns>最大数量日志</returns> public static List <string> PopAllQueue(string nodeName, string logicName, string key) { RedisNode cfg = RedisConfig.GetNode(nodeName); string k = getKey(logicName, key); return(cfg.Get <List <string> >(db => { var list = db.ListRange(k); return list?.Select(x => x.ToString()).ToList(); })); }
/// <summary> /// 获取某个模型下面的特定key的值 /// </summary> /// <typeparam name="T">存储对象</typeparam> /// <param name="nodeName">节点名称</param> /// <param name="logicName">业务名称</param> /// <param name="key">key</param> /// <returns>T</returns> public static T Get <T>(string nodeName, string logicName, string key) { RedisNode cfg = RedisConfig.GetNode(nodeName); string k = getKey(logicName, key); return(cfg.Get <T>(db => { RedisValue rv = db.StringGet(k); return ConvertValue <T>(rv); })); }
/// <summary> /// 获取Hash字段值 /// </summary> /// <typeparam name="T">T</typeparam> /// <param name="nodeName">nodeName</param> /// <param name="logicName">logicName</param> /// <param name="key">key</param> /// <param name="filed">filed</param> /// <returns>TT</returns> public static T GetHash <T>(string nodeName, string logicName, string key, string filed) { RedisNode cfg = RedisConfig.GetNode(nodeName); string k = getKey(logicName, key); RedisValue v = cfg.Get <RedisValue>(db => { return(db.HashGet(k, filed)); }); return(ConvertValue <T>(v)); }
/// <summary> /// 获取整个Hash表 /// </summary> /// <typeparam name="T">T</typeparam> /// <param name="nodeName">nodeName</param> /// <param name="logicName">logicName</param> /// <param name="key">key</param> /// <returns>static</returns> public static Dictionary <string, T> GetHashAll <T>(string nodeName, string logicName, string key) { RedisNode cfg = RedisConfig.GetNode(nodeName); string k = getKey(logicName, key); HashEntry[] vs = cfg.Get <HashEntry[]>(db => { return(db.HashGetAll(k)); }); if (vs == null || vs.Length < 1) { return(null); } return(vs.ToDictionary(a => a.Name.ToString(), a => ConvertValue <T>(a.Value))); }