在redis中我们一般存储string、list、hash类型的值,对应的方法分别为 db.StringGet(“key”)、db.ListRange、db.HashGetAll 如果取list类型值时使用了string的方法就会报WRONGTYPE Operation against a key holding the wrong kind of value错误。
redis-cli命令窗口
#读取string类型的值
get "qwer"
#读取list hash表中data的值
hget "c:System.String,k:InternalMenuJson" data
#读取list hash表中所有的值
hgetall "c:System.String,k:InternalMenuJson"
C#实现
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Caching.Distributed;
using System;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Caching;
using StackExchange.Redis;
using Newtonsoft.Json; namespace Test.Attribute
{public class AuthCustoms : AuthorizeAttribute, IAsyncAuthorizationFilter{ public async Task OnAuthorizationAsync(AuthorizationFilterContext context){var redis = ConnectionMultiplexer.Connect("123.33.44.123:6379,password=123asd,ConnectTimeout=15000,SyncTimeout=5000");var db = redis.GetDatabase();string value = db.StringGet("qwe");HashEntry[] aaaaaaaa= db.HashGetAll("c:System.String,k:InternalMenuJson");//RedisValue jsonValue = db.StringGet("62725");RedisValue bbbbb= db.HashGet("c:System.String,k:InternalMenuJson","data");}}
}