Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xin9le/CloudStructures
Redis Client based on StackExchange.Redis.
https://github.com/xin9le/CloudStructures
c-sharp redis redis-client
Last synced: about 1 month ago
JSON representation
Redis Client based on StackExchange.Redis.
- Host: GitHub
- URL: https://github.com/xin9le/CloudStructures
- Owner: xin9le
- License: mit
- Created: 2013-03-24T19:45:23.000Z (almost 12 years ago)
- Default Branch: main
- Last Pushed: 2024-06-14T20:17:47.000Z (6 months ago)
- Last Synced: 2024-11-05T00:38:03.337Z (about 2 months ago)
- Topics: c-sharp, redis, redis-client
- Language: C#
- Homepage:
- Size: 1.25 MB
- Stars: 133
- Watchers: 19
- Forks: 25
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CloudStructures
CloudStructures is the [Redis](https://redis.io/) client based on [StackExchange.Redis](https://github.com/StackExchange/StackExchange.Redis).StackExchange.Redis is very pure and low level library. It's Redis driver like ADO.NET. It's difficult to use it as raw. CloudStructures provides simple O/R (Object / Redis) mapper like [Dapper](https://github.com/StackExchange/Dapper) for ADO.NET.
[![Releases](https://img.shields.io/github/release/neuecc/CloudStructures.svg)](https://github.com/neuecc/CloudStructures/releases)
# Support framework
- .NET 6+
- .NET Standard 2.0+
- .NET Framework 4.6.1+# Installation
```
dotnet add package CloudStructures
```# Data structures of Redis
CloudStructures supports these Redis data types. All methods are async.| Structure | Description |
| --- | --- |
| `RedisBit` | Bits API |
| `RedisDictionary` | Hashes API with constrained value type |
| `RedisGeo` | Geometries API |
| `RedisHashSet` | like `RedisDictionary` |
| `RedisHyperLogLog` | HyperLogLogs API |
| `RedisList` | Lists API |
| `RedisLua` | Lua eval API |
| `RedisSet` | Sets API |
| `RedisSortedSet` | SortedSets API |
| `RedisString` | Strings API |# Getting started
Following code is simple sample.```cs
// RedisConnection have to be held as static.
public static class RedisServer
{
public static RedisConnection Connection { get; }
public static RedisServer()
{
var config = new RedisConfig("name", "connectionString");
Connection = new RedisConnection(config);
}
}// A certain data class
public class Person
{
public string Name { get; set; }
public int Age { get; set; }
}// 1. Create redis structure
var key = "test-key";
var defaultExpiry = TimeSpan.FromDays(1);
var redis = new RedisString(RedisServer.Connection, key, defaultExpiry)// 2. Call command
var neuecc = new Person("neuecc", 35);
await redis.SetAsync(neuecc);
var result = await redis.GetAsync();
```# ValueConverter
If you use this library, you *should* implement `IValueConverter` to serialize your original class. Unless you pass custom `IValueConverter` to `RedisConnection` ctor, fallback to `SystemTextJsonConverter` automatically that is default converter we provide.## How to implement custom `IValueConverter`
```cs
using CloudStructures.Converters;
using Utf8Json;
using Utf8Json.Resolvers;namespace HowToImplement_CustomValueConverter
{
public sealed class Utf8JsonConverter : IValueConverter
{
public byte[] Serialize(T value)
=> JsonSerializer.Serialize(value, StandardResolver.AllowPrivate);public T Deserialize(byte[] value)
=> JsonSerializer.Deserialize(value, StandardResolver.AllowPrivate);
}
}
``````cs
using CloudStructures.Converters;
using MessagePack;
using MessagePack.Resolvers;namespace HowToImplement_CustomValueConverter
{
public sealed class MessagePackConverter : IValueConverter
{
private MessagePackSerializerOptions Options { get; }public MessagePackConverter(MessagePackSerializerOptions options)
=> this.Options = options;public byte[] Serialize(T value)
=> MessagePackSerializer.Serialize(value, this.Options);public T Deserialize(byte[] value)
=> MessagePackSerializer.Deserialize(value, this.Options);
}
}
```# Authors
- Yoshifumi Kawai (a.k.a [@neuecc](https://twitter.com/neuecc))
- Takaaki Suzuki (a.k.a [@xin9le](https://twitter.com/xin9le))Yoshifumi Kawai is software developer in Tokyo, Japan. Awarded Microsoft MVP (C#) since April, 2011. He's the original owner of this project.
Takaaki Suzuki is software developer in Fukui, Japan. Awarded Microsoft MVP (C#) since July, 2012. He's a contributer who led the .NET Standard support.
# License
This library is under the MIT License.