예제 #1
0
        /// <summary>
        /// 获取数据
        /// </summary>
        /// <param name="tabName"></param>
        /// <param name="uid"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public string Get(string tabName, string uid, string key)
        {
            string strKey = tabName + "_" + uid + "_" + key;

            if (RedisUtility.KeyExist(strKey))
            {
                return(RedisUtility.StringGet(strKey));
            }
            var sqlParams = new MySqlParameter[]
            {
                new MySqlParameter("@openid", MySqlDbType.VarChar)
                {
                    Value = uid
                },
            };
            var strsql  = "select " + key + " from " + tabName + " where uid=@uid limit 1";
            var dataset = MysqlUtility.ExecuteQuery(strsql, sqlParams);
            var obj     = dataset.Tables[0].Rows[0][key].ToString();

            if (obj != null)
            {
                logger.Warn("strKey:  " + strKey + " obj: " + obj);
                RedisUtility.StringSet(strKey, obj, expireTime);
            }
            return(obj);
        }
예제 #2
0
        /// <summary>
        /// 移除某个字段
        /// </summary>
        /// <param name="tabName"></param>
        /// <param name="uid"></param>
        /// <param name="key"></param>
        public void Remove(string tabName, string uid, string key)
        {
            if (RedisUtility.KeyExist(key))
            {
                RedisUtility.KeyDelete(key);
            }
            var sqlParams = new MySqlParameter[]
            {
                new MySqlParameter("@openid", MySqlDbType.VarChar)
                {
                    Value = uid
                },
            };
            var strsql = "update " + tabName + " set " + key + "='' where openid =@openid";

            MysqlUtility.ExecuteSql(strsql, sqlParams);
        }