Awesome Open Source
Awesome Open Source

NewLife.Redis - Redis

GitHub top language GitHub License Nuget Downloads Nuget Nuget (with prereleases)

[English]

NewLife.Redis Redis
RedisRedis/RedisClientX

https://github.com/NewLifeX/NewLife.Redis
NugetNewLife.Redis
https://newlifex.com/core/redis


  • ZTO200Redis180
  • Get/Set200~600us
  • 1000

Redis

  • Linux
  • 10+keyCrc16/Crc32
  • Json
  • KeyValue1.4k
  • RedisGet/Set200~600usRedis
  • Pipeline
  • Redis

3004T


Redis

RedisNewLife.Redis
200~600us
100

// Redis6379
//var rds = new Redis("127.0.0.1", null, 7);
var rds = new Redis("127.0.0.1:6379", "pass", 7);
//var rds = new Redis();
//rds.Init("server=127.0.0.1:6379;password=pass;db=7");
rds.Log = XTrace.Log; // 

  • XTrace.UseConsole();
  • MemoryCacheRedis
  • User
class User
{
    public String Name { get; set; }
    public DateTime CreateTime { get; set; }
}
var user = new User { Name = "NewLife", CreateTime = DateTime.Now };
rds.Set("user", user, 3600);
var user2 = rds.Get<User>("user");
XTrace.WriteLine("Json: {0}", user2.ToJson());
XTrace.WriteLine("Json: {0}", rds.Get<String>("user"));
if (rds.ContainsKey("user")) XTrace.WriteLine("");
rds.Remove("user");
14:14:25.990  1 N - SELECT 7
14:14:25.992  1 N - => OK
14:14:26.008  1 N - SETEX user 3600 [53]
14:14:26.021  1 N - => OK
14:14:26.042  1 N - GET user
14:14:26.048  1 N - => [53]
14:14:26.064  1 N - GET user
14:14:26.065  1 N - => [53]
14:14:26.066  1 N - Json: {"Name":"NewLife","CreateTime":"2018-09-25 14:14:25"}
14:14:26.067  1 N - EXISTS user
14:14:26.068  1 N - => 1
14:14:26.068  1 N - 
14:14:26.069  1 N - DEL user
14:14:26.070  1 N - => 1

JsonJson
Redisstrings[53]53

GetAll/SetAll Rediskey10

var dic = new Dictionary<String, Object>
{
    ["name"] = "NewLife",
    ["time"] = DateTime.Now,
    ["count"] = 1234
};
rds.SetAll(dic, 120);

var vs = rds.GetAll<String>(dic.Keys);
XTrace.WriteLine(vs.Join(",", e => $"{e.Key}={e.Value}"));
MSET name NewLife time 2018-09-25 15:56:26 count 1234
=> OK
EXPIRE name 120
EXPIRE time 120
EXPIRE count 120
MGET name time count
name=NewLife,time=2018-09-25 15:56:26,count=1234

GetList/GetDictionary/GetQueue/GetSet RedisSet
RedisNewLife.RedisMemoryCache

  • Add keyfalse
  • Replace
  • Increment
  • Decrement
var flag = rds.Add("count", 5678);
XTrace.WriteLine(flag ? "Add" : "Add");
var ori = rds.Replace("count", 777);
var count = rds.Get<Int32>("count");
XTrace.WriteLine("count{0}{1}", ori, count);

rds.Increment("count", 11);
var count2 = rds.Decrement("count", 10);
XTrace.WriteLine("count={0}", count2);
SETNX count 5678
=> 0
Add
GETSET count 777
=> 1234
GET count
=> 777
count1234777
INCRBY count 11
=> 788
DECRBY count 10
=> 778
count=778

Bench
rand key/value
batch GetAll/SetAll

RedisAutoPipeline=100

Redis

RedisICacheMemoryCache
ICacheMemoryCache
10Redis

net6.0/netstandard2.12021.1225net5.0/netstandard2.0/net4.5/net4.0/net2.0

.NET6
NewLife.Core 2002 RPCAPM
XCode 2005 MySQL/SQLite/SqlServer/Oracle/TDengine/
NewLife.Net 2005 2266tps400Tcp
NewLife.Cube 2010 SSOOAuth100
NewLife.Agent 2008 WindowsLinuxSystemd
NewLife.Zero 2020 ZeroWebWebApi
NewLife.Redis 2017 Redis
NewLife.RocketMQ 2018 Apache RocketMQ
NewLife.MQTT 2019
NewLife.LoRa 2016 LoRaWAN
AntJob 2019 /
Stardust 2018 APM
CrazyCoder 2006 Modbus
XProxy 2005 NATHttp
SmartOS 2014 C++11 ARM Cortex-M
GitCandy 2015 Git
NewLife.A2 2019 .NET
NewLife.IoT 2020
NewLife.UWB 2020

XCode

NewLife2002
NewLifeNuget60
NewLife.XCodeAntJobStardustNewLife.RedisNewLife.IoT

IT

2002202010
https://newlifex.com
https://github.com/newlifex
QQ1600800/1600838

Related Awesome Lists
Top Programming Languages
Top Projects

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
C Sharp (166,391
Redis (23,911
Netstandard (904
Lorawan (764
Rocketmq (519
Memory Cache (77
Newlife (9