Giter Club home page Giter Club logo

chaunceeasyredis's Introduction

💥 ChaunceEasyRedis

ChaunceEasyRedis is a free, open source,RedisService built on the .NETStandard platform.

 http://www.cnblogs.com/xiaoliangge/

About ChaunceEasyRedis

Please visit our website at http://www.cnblogs.com/xiaoliangge/ for the most current information about this project.

ChaunceEasyRedis reference https://github.com/dotnetcore/EasyCaching ChaunceEasyRedis is free,open source.

💥 How to use

Step 1 : ConfigureServices

public class Startup
{
    //...
    
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc();
            //注入ChaunceRedisCache
        services.AddChaunceRedisCache(option =>
        {
                option.Database = 0;
                option.Endpoints.Add(new ServerEndPoint("localhost", 6379));
                option.DefaultCustomKey = "chaunce:";
        });
    }    
}

Step 2 : Write code in you controller

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Chaunce.EasyRedis;
using Microsoft.AspNetCore.Mvc;

namespace ExampleWeb.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class ValuesController : ControllerBase
    {
        private readonly IRedisCache _provider;
        public ValuesController(IRedisCache provider)
        {
            _provider = provider;
        }
        // GET api/values
        [HttpGet]
        public ActionResult<IEnumerable<string>> Get()
        {
            _provider.CustomPrefixKey = "www:";//改边默认key
            _provider.Set("demo", "yyy", TimeSpan.FromMinutes(1));
            var str2 = _provider.Get("demo", () => { return "缓存"; }, TimeSpan.FromMinutes(1));
            _provider.CustomPrefixKey = "EEE:";//继续改边默认key
            var str3 = _provider.Get("demo", () => { return "缓存"; }, TimeSpan.FromMinutes(1));

            return new string[] { "value1", "value2" };
        }

        // GET api/values/5
        [HttpGet("{id}")]
        public ActionResult<string> Get(int id)
        {
            return "value";
        }

        // POST api/values
        [HttpPost]
        public void Post([FromBody] string value)
        {
        }

        // PUT api/values/5
        [HttpPut("{id}")]
        public void Put(int id, [FromBody] string value)
        {
        }

        // DELETE api/values/5
        [HttpDelete("{id}")]
        public void Delete(int id)
        {
        }
    }
}

chaunceeasyredis's People

Contributors

liuyl1992 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.