代码拉取完成,页面将自动刷新
Install-Package Apteryx.StackexChange.Redis.Extend
public class Account
{
public string Name { get; set; }
}
public class RedisEntity:RedisDBProvider
{
public RedisEntity(string conn) : base(conn) { }
public IRedisCollection<Account> Accounts
{
get { return _database.GetCollection<Account>(); }
}
}
static void Main(string[] args)
{
RedisEntity db = new RedisEntity("xxx.xx.xx.248:6379,password=xxx,defaultDatabase=1");
for (int i = 1; i <= 10; i++)
{
db.Accounts.AddAsync(new Account() {Name = "张三" + i}, TimeSpan.FromSeconds(20));
}
db.Accounts.AddAsync("key11", new Account() {Name = "张三11"}, TimeSpan.FromSeconds(20));
var account1 = db.Accounts.Find("key11");//支持key查询
var account2 = db.Accounts.FirstOrDefault(f => f.Name == "张三8");//注意此方法为遍历对比,只适用少量数据。
}
public class Account
{
public string Name { get; set; }
}
static void Main(string[] args)
{
var redisClient = ConnectionMultiplexer.Connect("xxx.xx.xx.248:6379,password=xxx,defaultDatabase=0");
var db = redisClient.GetDatabase();
using (var strlist = db.AsClientType<Account>())
{
for (int i = 1; i <= 100; i++)
{
strlist.Append(new Account() { Name = "张三" + i }, TimeSpan.FromMinutes(1));
}
}
}
public class Account
{
public string Name { get; set; }
}
public class RedisEntity : RedisDBProvider
{
public RedisEntity(IOptionsMonitor<RedisOptions> options) : base(options) { }
public IRedisCollection<Account> Accounts => Database.GetCollection<Account>();
}
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddRedis<RedisEntity>(options =>
{
options.ConnectionString = "xxx.xxx.xxx.xxx:6379,password = 123456,defaultDatabase = 0";
});
//............................
}
}
[Route("api/[controller]")]
[ApiController]
public class ValuesController : ControllerBase
{
private RedisEntity db = null;
public ValuesController(IRedisService redis)
{
db = redis as RedisEntity;
}
// GET api/values
[HttpGet()]
public IActionResult Get()
{
for (int i = 1; i <= 10; i++)
{
db.Accounts.AddAsync(new Account() {Name = "张三" + i}, TimeSpan.FromSeconds(20));
}
db.Accounts.AddAsync("key11", new Account() {Name = "张三11"}, TimeSpan.FromSeconds(20));
var account1 = db.Accounts.Find("key11");//支持key查询
var account2 = db.Accounts.FirstOrDefault(f => f.Name == "张三8");//注意此方法为遍历对比,只适用少量数据。
return Ok(account1);
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. 开源生态
2. 协作、人、软件
3. 评估模型