Beetlex之redis驱动
BeetleX.Redis
BeetleX.Redis是基于BeetleX擴(kuò)展的Redis操作庫,全異步操作模式和基于字符緩存策略優(yōu)化可以提供出色的Redis訪問性能;支持SSL,支持讀寫分離和故障切換;默認(rèn)多數(shù)據(jù)格式支持,默認(rèn)提供json,protobuf和messagepack格式。
支持的命令
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?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
GitHub
https://github.com/IKende/BeetleX.Redis
Nuget
https://www.nuget.org/packages/BeetleX.Redis/
設(shè)置
組件默認(rèn)提供一個(gè)0庫的實(shí)例,只需要添加相應(yīng)的Redis服務(wù)地址即可
Redis.Default.DataFormater = new JsonFormater();Redis.Default.Host.AddWriteHost("localhost");//開啟SSLRedis.Default.Host.AddWriteHost("localhost",6378,true);//設(shè)置密碼Redis.Default.Host.AddWriteHost("localhost").Password="123456"創(chuàng)建一個(gè)數(shù)據(jù)實(shí)例
RedisDB DB = new RedisDB(1); DB.DataFormater = new JsonFormater(); DB.Host.AddWriteHost("localhost");//開啟SSL DB.Host.AddWriteHost("localhost",6378,true);//設(shè)置密碼 DB.Host.AddWriteHost("localhost").Password="123456"每個(gè)庫只創(chuàng)建一個(gè)實(shí)例即可,相關(guān)所有操作都是線程安全。
Json db
RedisDB DB = new RedisDB(0, new JsonFormater());Protobuf db
RedisDB DB = new RedisDB(0, new ProtobufFormater());MessagePack db
RedisDB DB = new RedisDB(0, new MessagePackFormater());SET/SET操作
await Redis.Get<Employee>("nonexisting"); await Redis.Set("emp3", GetEmployee(3)); await Redis.Get<Employee>("emp3");MSET/MGET操作
await Redis.Set(("field1", GetEmployee(1)), ("field2", GetEmployee(2))); await Redis.Get<Employee, Order, Customer>("emp1", "order1", "customer1");列表
var list = Redis.CreateList<Employee>("employees"); await list.Push(GetEmployee(1)); await list.Insert(true, GetEmployee(2), GetEmployee(3)); await list.Range(0, -1);有序集合
var sequeue = DB.CreateSequence("seq2"); await sequeue.ZAdd((100, "A1"), (200, "A2"), (300, "A3"), (400, "A4")); var items = await sequeue.ZRange(0, -1, true);鍵值表
var table = Redis.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();訂閱操作
var subscribe = Redis.Subscribe(); subscribe.Register<Employee>("employees"); subscribe.Receive = (o, e) => {Console.WriteLine($"{e.Type} {e.Channel} {e.Data}"); }; subscribe.Listen();發(fā)布
await Redis.Publish("employees", GetEmployee(1));總結(jié)
以上是生活随笔為你收集整理的Beetlex之redis驱动的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 基于Jenkins的持续交付全流程设计与
- 下一篇: .NET CORE(C#) WPF简单菜