• Stars
    star
    185
  • Rank 208,271 (Top 5 %)
  • Language
    C#
  • License
    Apache License 2.0
  • Created over 5 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A high-performance async/non-blocking redis client components for dotnet core,default data formater json protobuf and messagepack,support ssl

BeetleX.Redis

A high-performance async/non-blocking redis client components for dotnet core,default support json and protobuf data format ,support ssl

Support commands

AUTH| BLPOP| BRPOP| BRPOPLPUSH| DECR| DECRBY| DEL| DUMP| EXISTS| EXPIRE| EXPIREAT| FLUSHALL| GET| GETBIT| GETRANGE| GETSET| HDEL| HEXISTS| HGET| HGETALL| HINCRBY| HINCRBYFLOAT| HKEYS| HLEN| HMGET| HMSET| HSET| HSETNX| HSTRLEN| HVALS| INCR| INCRBY| INCRBYFLOAT| KEYS| LINDEX| LINSERT| LLEN| LPOP| LPUSH| LPUSHX| LRANGE| LREM| LSET| LTRIM| MGET| MOVE| MSET| MSETNX| OBJECT| PERSIST| PEXPIRE| PEXPIREAT| PING| PSETEX| PTTL| PUBLISH| RANDOMKEY| RENAME| RENAMENX| RPOP| RPOPLPUSH| RPUSH| RPUSHX| SCAN| SELECT| SET| SETBIT| SETEX| SETNX| SETRANGE| STRLEN| SUBSCRIBE| TOUCH| TTL| TYPE| UNLINK| UNSUBSCRIBE| WAIT| ZADD| ZCARD| ZCOUNT| ZINCRBY| ZINTERSTORE| ZLEXCOUNT| ZRANGE| ZRANGEBYLEX| ZRANGEBYSCORE| ZRANK| ZREM| ZREMRANGEBYLEX| ZREMRANGEBYRANK| ZREMRANGEBYSCORE| ZREVRANGE| ZREVRANGEBYSCORE| ZREVRANK| ZSCORE| ZUNIONSTORE| PFCount| PFAdd| PFMerge| INFO| XACK| XADD| XDEL| XGROUP| XLEN| XRANGE| XREAD| XREADGROUP| XREVRANGE| GEOADD| GEOPOS| GEODIST| GEORADIUS| GEORADIUSBYMEMBER| SADD| SCARD| SDIFF| SDIFFSTORE| SINTER| SINTERSTORE| SISMEMBER| SMEMBER| SMOVE| SPOP| SRANDMEMBER| SREM| SSCAN| SUNION| SUNIONSTORE|

nuget

https://www.nuget.org/packages/BeetleX.Redis/

Default instance setting

DefaultRedis.Instance.DataFormater = new JsonFormater();
DefaultRedis.Instance.Host.AddWriteHost("localhost");
//ssl
DefaultRedis.Instance.Host.AddWriteHost("localhost",6378,true);
//password 
DefaultRedis.Instance.Host.AddWriteHost("localhost").Password="123456"

Create db

RedisDB DB = new RedisDB(1);
DB.DataFormater = new JsonFormater();
DB.Host.AddWriteHost("localhost");
  //SSL
DB.Host.AddWriteHost("localhost",6378,true);
  //password 
DB.Host.AddWriteHost("localhost").Password="123456"

SET/SET

await DefaultRedis.Get<Employee>("nonexisting");
await DefaultRedis.Set("emp3", GetEmployee(3));
await DefaultRedis.Get<Employee>("emp3");

MSET/MGET

await DefaultRedis.Set(("field1", GetEmployee(1)), ("field2", GetEmployee(2)));
await DefaultRedis.Get<Employee, Order, Customer>("emp1", "order1", "customer1");

List

var list = DefaultRedis.CreateList<Employee>("employees");
await list.Push(GetEmployee(1));
await list.Insert(true, GetEmployee(2), GetEmployee(3));
await list.Range(0, -1);

Sequence

var sequeue = DB.CreateSequence("seq2");
await sequeue.ZAdd((100, "A1"), (200, "A2"), (300, "A3"), (400, "A4"));
var items = await sequeue.ZRange(0, -1, true);

Hash

var table = DefaultRedis.CreateHashTable("myhash");
await table.MSet(("field1", GetEmployee(1)), ("field2", GetEmployee(2)));
await table.Get<Employee, Employee>("field1", "field2");
await table.Del("emp2");
await table.Keys();

Stream

 RedisStream<Employee> stream = DB.GetStream<Employee>("employees_stream");
 await stream.Add(DataHelper.Defalut.Employees[0]);
 await stream.Len();
 await stream.Range();
 await stream.RevRange();
 await stream.Read(0, null, "0-0");
 var group = await stream.GetGroup("g1");
 await group.Read("henry");
 var items = await group.Read("henry","0");
 foreach (var item in items)
    await item.Ack();
    
 while (true)
 {
    items = await group.ReadWait(name);
    foreach (var item in items)
    {
        Console.WriteLine($"1-{name}|{item.ID} {item.Data.FirstName}\t{item.Data.LastName}");
    }
 }

Subscribe

var subscribe = DefaultRedis.Subscribe();
subscribe.Register<Employee>("employees");
subscribe.Receive = (o, e) =>
{
       Console.WriteLine($"{e.Type} {e.Channel} {e.Data}");
};
subscribe.Listen();
await Redis.Publish("employees", GetEmployee(1));

New db client

RedisDB DB = new RedisDB();
DB.Host.AddWriteHost("192.168.2.19");
// set password
DB.Host.AddWriteHost("192.168.2.19").Password=123456;

Json db

RedisDB DB = new RedisDB(0, new JsonFormater());

Protobuf db

RedisDB DB = new RedisDB(0, new ProtobufFormater());

Basic operations

await DB.Decr("mykey")
await DB.Decrby("mykey", 5);
await DB.Del("mykey");
await DB.Dump("mykey");
await DB.Exists("mykey", "order");
await DB.Expire("mykey", 10);
await DB.Expireat("mykey", 1293840000);
await DB.Get<string>("mykey");
await DB.GetBit("mykey", 0);
await DB.GetRange("mykey", -3, -1);
await DB.GetSet<string>("mycounter", 0);
await DB.Incr("mykey");
await DB.Incrby("mykey", 10);
await DB.IncrbyFloat("mykey", 0.1f);
await DB.Keys("t??");
await DB.MGet<string, string>("key1", "key2");
await DB.MGet<string, string, string>("key1", "aaa", "key2");
await DB.MSet(("key1", "hello"),("key2", "world"));
await DB.MSetNX(("key1", "hello"),("key2", "there"));
await DB.Move("one", 9);
await DB.PSetEX("mykey", 1000, "hello");
await DB.Persist("mykey");
await DB.Pexpire("mykey", 1500);
await DB.Pexpireat("mykey", 1555555555005);
await DB.Ping();
await DB.PTtl("mykey");
await DB.Randomkey();
await DB.Rename("mykey", "myotherkey");
await DB.Renamenx("mykey", "myotherkey");
await DB.Set("test", "henryfan");
await DB.SetBit("mykey", 7, false);
await DB.SetEX("mykey", 10, "hello");
await DB.SetNX("mykey", "hello");
await DB.SetRange("key1", 6, "redis");
await DB.Strlen("key1");
await DB.Type("key2");

List

create list

 var list = DB.CreateList<Employee>("employees");

operations

await list.BLPop();
await list.BRPop();
await list.BRPopLPush("List2");
await list.Index(0);
await list.Insert(true, GetEmployee(2), GetEmployee(3));
await list.Len();
await list.Pop();
await list.Push(GetEmployee(1));
await list.Push(GetEmployee(1), GetEmployee(2));
await myotherlist.PushX(GetEmployee(2));
await list.Rem(-2, GetEmployee(1));
await list.Set(-2, GetEmployee(5));
await list.Trim(1, -1);
await list.RPop();
await list.RPopLPush("myotherlist");
await list.RPush(GetEmployee(3));
await list.RPush(GetEmployee(1), GetEmployee(2));
await list.RPushX(GetEmployee(2));
await list.Range(-3, 2);

Sequence

await DB.Del("seq2");
var sequeue = DB.CreateSequence("seq2");
await sequeue.ZAdd((100, "A1"), (200, "A2"), (300, "A3"), (400, "A4"));
var items = await sequeue.ZRange(0, -1, true);
Assert.Equal<int>(items.Count, 4);
Assert.Equal<string>(items[0].Member, "A1");
Assert.Equal<string>(items[1].Member, "A2");
Assert.Equal<string>(items[2].Member, "A3");
Assert.Equal<string>(items[3].Member, "A4");

Assert.Equal<double>(items[0].Score, 100);
Assert.Equal<double>(items[1].Score, 200);
Assert.Equal<double>(items[2].Score, 300);
Assert.Equal<double>(items[3].Score, 400);
//--------------------------------------------------------------------
await DB.Del("seq2");
var sequeue = DB.CreateSequence("seq2");
await sequeue.ZAdd((100, "A1"), (200, "A2"), (300, "A3"), (400, "A4"));
var value = await sequeue.ZRevRank("A4");
Assert.Equal<long>(value, 0);

//------------------------------------------------------------------------
await DB.Del("seq2","seq3","seq4");
var seq2 = DB.CreateSequence("seq2");
await seq2.ZAdd((100, "A1"), (200, "A2"), (300, "A3"), (400, "A4"));

var seq3 = DB.CreateSequence("seq2");
await seq3.ZAdd((500, "B1"), (600, "B2"), (700, "B3"), (800, "B4"));

var seq4 = DB.CreateSequence("seq4");
await seq4.ZUnionsStore("seq2", "seq3");

var count = await seq4.ZCard();
Assert.Equal<long>(count, 8);

HashTable

create HashTable

 var table = DB.CreateHashTable("myhash");

operations

await table.Del("emp1");
await table.Exists("emp1");
await table.Get<Employee>("emp1");
await table.Keys();
await table.Len();
await table.Get<Employee, Order>("emp", "order");
await table.Get<Employee, Order, Customer>("emp", "order", "customer");
await table.MSet(("field1", GetEmployee(1)),("field2", GetCustomer(1)));
await table.Set("field1", GetEmployee(1));
await table.SetNX("field", GetEmployee(1));

Subscribe

Create subscriber

            var sub = db.Subscribe();
            sub.Register<Employee>("test1");
            sub.Receive = (o, e) =>
            {
                Console.WriteLine($"[{DateTime.Now}]{e.Channel}-{e.Type}:{e.Data}");
            };
            sub.Listen();

Publish

await DB.Publish("test1", GetEmployee(i));

Performance test

code:https://github.com/IKende/BeetleX.Redis/tree/master/PerformanceTest

{"OrderID":10255,"CustomerID":"RICSU","EmployeeID":9,"OrderDate":"1996-07-12T00:00:00","RequiredDate":"1996-08-09T00:00:00","ShippedDate":"1996-07-15T00:00:00","ShipVia":3,"Freight":148.33,"ShipName":"Richter Supermarkt","ShipAddress":"Starenweg 5","ShipCity":"Genève","ShipPostalCode":"1204","ShipCountry":"Switzerland"}

get/set/mget (BeetleX vs StackExchange)

10Gb network

-------------------------------------------------------------------------------
|Name                          | Round| Threads|     Count| Use time(s)|   Sec|
-------------------------------------------------------------------------------
|BeetleX_SET                   |     1|       1|    100000|        5.22| 19157|
-------------------------------------------------------------------------------
|StackExchange_SET             |     1|       1|    100000|        6.97| 14357|
-------------------------------------------------------------------------------
|StackExchange_Sync_SET        |     1|       1|    100000|        6.62| 15103|
-------------------------------------------------------------------------------
|BeetleX_GET                   |     1|       1|    100000|        5.41| 18487|
-------------------------------------------------------------------------------
|StackExchange_GET             |     1|       1|    100000|        7.48| 13378|
-------------------------------------------------------------------------------
|StackExchange_Sync_GET        |     1|       1|    100000|        7.09| 14105|
-------------------------------------------------------------------------------
|BeetleX_MGET                  |     1|       1|    100000|        7.03| 14216|
-------------------------------------------------------------------------------
|StackExchange_MGET            |     1|       1|    100000|        8.69| 11504|
-------------------------------------------------------------------------------
|StackExchange_Sync_MGET       |     1|       1|    100000|        8.36| 11963|
-------------------------------------------------------------------------------
|BeetleX_SET                   |     1|       2|    100000|        2.55| 39246|
-------------------------------------------------------------------------------
|StackExchange_SET             |     1|       2|    100000|        3.97| 25199|
-------------------------------------------------------------------------------
|StackExchange_Sync_SET        |     1|       2|    100000|        3.56| 28069|
-------------------------------------------------------------------------------
|BeetleX_GET                   |     1|       2|    100000|        2.78| 35946|
-------------------------------------------------------------------------------
|StackExchange_GET             |     1|       2|    100000|         4.1| 24364|
-------------------------------------------------------------------------------
|StackExchange_Sync_GET        |     1|       2|    100000|        3.72| 26907|
-------------------------------------------------------------------------------
|BeetleX_MGET                  |     1|       2|    100000|        3.59| 27871|
-------------------------------------------------------------------------------
|StackExchange_MGET            |     1|       2|    100000|        4.75| 21035|
-------------------------------------------------------------------------------
|StackExchange_Sync_MGET       |     1|       2|    100000|        4.55| 21976|
-------------------------------------------------------------------------------
|BeetleX_SET                   |     1|       4|    100000|        2.04| 48956|
-------------------------------------------------------------------------------
|StackExchange_SET             |     1|       4|    100000|        2.37| 42220|
-------------------------------------------------------------------------------
|StackExchange_Sync_SET        |     1|       4|    100000|        2.15| 46541|
-------------------------------------------------------------------------------
|BeetleX_GET                   |     1|       4|    100000|        2.14| 46822|
-------------------------------------------------------------------------------
|StackExchange_GET             |     1|       4|    100000|        2.58| 38789|
-------------------------------------------------------------------------------
|StackExchange_Sync_GET        |     1|       4|    100000|        2.24| 44619|
-------------------------------------------------------------------------------
|BeetleX_MGET                  |     1|       4|    100000|        2.49| 40238|
-------------------------------------------------------------------------------
|StackExchange_MGET            |     1|       4|    100000|        3.06| 32708|
-------------------------------------------------------------------------------
|StackExchange_Sync_MGET       |     1|       4|    100000|        2.76| 36264|
-------------------------------------------------------------------------------

More Repositories

1

BeetleX

high performance dotnet core socket tcp communication components, support TLS, HTTP, HTTPS, WebSocket, RPC, Redis protocols, custom protocols and 1M connections problem solution
C#
1,098
star
2

FastHttpApi

a lightweight and high-performance http/websocket service component in the dotnet core platform that supports TLS.
C#
640
star
3

Bumblebee

.net core fast http and websocket gateway components
C#
351
star
4

XBlog

Personal blog websites system built on Beetlex.FastHttpApi framework
JavaScript
204
star
5

Beetle.DT

分布式压力测试工具
C#
190
star
6

WebApiBenchmark

Web api management and performance testing tools
C#
161
star
7

TCPBenchmarks

tcp,websocket,webapi性能测试工具
117
star
8

BeetleX-Samples

BeetleX micro services framework (tcp webapi websocket and xrpc) samples
C#
102
star
9

SmartRoute

SmartRoute(服务即集群)
C#
84
star
10

XRPC

dotnet high performance remote interface and delegate invoke(RPC) communication components,support millions RPS remote interface method invokes
C#
80
star
11

Log4Grid

Distributed Application Log Management
C#
42
star
12

EventNext

EventNext is logic interface design actors components for .net core
C#
41
star
13

WebBenchmark

webapi 管理和性能测试工具
39
star
14

HttpClients

BeetleX http/websocket client support ssl
C#
31
star
15

ec

elastic communication component for mono and .net
C#
29
star
16

BNR

业务流水号规则生成器
C#
26
star
17

SimpleDoc

轻量化在线文档发布服务
CSS
24
star
18

KFilter

脏字过虑组件
C#
23
star
19

downloads

beetlex应用服务下载:网关,VueHost,性能测试工具和大数据分析服务
21
star
20

AdminUI

Beetlex+Vuejs+Bootstrap admin ui website
Vue
20
star
21

CacheDB

C#
18
star
22

NetBenchmark

tpc http and websocket performance benchmark testing components
C#
18
star
23

ClusterConfiguration

Beetlex Webapi cluster configuration
HTML
14
star
24

BeetleX.EFCore.Extension

BeetleX.EFCore.Extension
C#
14
star
25

dotnet-rpc-benchmark

rpc component benchmarks for dotnet
C#
14
star
26

CodeBenchmarkDoc

concurrent test components for netstandard 2.0
C#
11
star
27

WebFamily

Beetlex快速Web开发框架,内置vue,element,fontawesome
JavaScript
11
star
28

WebAPI4Grid

WebAPI集群负载组件
C#
8
star
29

ConcurrentTest

Concurrent Testing
C#
8
star
30

SmartRoute.DLocks

SmartRoute分布式锁
C#
8
star
31

RazorEngine

RazorEngine
C#
7
star
32

Configuration4Net

远程配置文件加载组件
C#
7
star
33

IKendeCLI

command line parse for .net
7
star
34

Peanut

c#数据访问组件
C#
6
star
35

Doc

Beetlex相关组件使用文档
6
star
36

vue-autoui

vue-autoui
JavaScript
6
star
37

beetlex-io

5
star
38

CS4Script

c#动态脚本编译加载组件
C#
3
star
39

SmartRoute.MRC

Message routing center
C#
3
star
40

BeetleXjs

beetlex webapi基于vue的快速开发扩展
Vue
2
star
41

mqtt

high performance .NET library for MQTT based communication
C#
2
star