Skip to content

About

C# samples for the Redis for .NET Developers blog series using StackExchange.Redis: connecting, strings, hashes, lists, sets, sorted sets, HyperLogLog, pub/sub, pipelining, transactions, Lua scripting, geospatial queries and an ASP.NET Core Web API. .NET Framework and .NET Core.

Topics

Resources

Contributing

Stars

88 stars

Watchers

9 watching

Forks

Latest commit

 

History

29 Commits

Folders and files

Repository files navigation

Redis for .NET Developers

License: MIT PRs Welcome

Sample C# code for the Redis for .NET Developers blog series on taswar.zeytinsoft.com. Each folder is a small, self-contained project covering one Redis feature, using the StackExchange.Redis client.

Samples

# Topic Project Blog post
1 Connecting to Redis (.NET Framework and .NET Core) 1.RedisConnection Connecting with C#
2 String data type 2.RedisString String data type
3 Strings as integers 3.RedisStringsAsInt String data type, part 2
4 Hash data type 4.RedisHashes Hash data type
5 List data type 5.RedisList List data type
6 Set data type 6.RedisSet Set data type
7 Sorted set data type 7.RedisSortedSets Sorted set data type
8 HyperLogLog 8.RedisHyperLogLog HyperLogLog
9 Pub/Sub 9.RedisPubSub Pub/Sub
10 Pipelining and batching 10.RedisPipeline Pipeline and batching
11 Transactions 11.RedisTransaction Transactions
12 Lua scripting 12.RedisLua Lua scripting
13 Geospatial commands (with Ottawa open data) 13.RedisGeo GeoSpatial
14 ASP.NET Core Web API with Redis 14.RedisAspDotNetCore Redis with ASP.NET Core Web API

More in the series, without code samples: Redis running in Docker, Redis password, Redis Sentinel, Redis in Azure and Redis in AWS ElastiCache.

Prerequisites

  • A running Redis server. The quickest way is Docker (see Redis running in Docker):

    docker run -d --name redis -p 6379:6379 redis
  • Samples 1–13 (.NET Framework): Visual Studio with .NET Framework 4.5.2–4.6.2. NuGet packages restore on build.

  • .NET Core samples (1.RedisConnection/RedisConnectionDotNetCore, 14.RedisAspDotNetCore): the .NET SDK. These target netcoreapp2.2, so you may need to change TargetFramework in the .csproj to a version you have installed.

Quick start

git clone https://github.com/taswar/RedisForNetDevelopers.git
cd RedisForNetDevelopers

Configuring the Redis connection

The samples were written against Redis running in Docker on different ports, so check the endpoint before you run one:

Project type Where to set it Key
.NET Framework console apps App.config redis.connection (for example localhost:6379)
.NET Core console app appsettings.json redis.connection
ASP.NET Core Web API appsettings.json Redis:Hosts

Running a sample

.NET Framework: open the .sln file in the sample's folder in Visual Studio, set the endpoint in App.config, and press F5.

.NET Core:

cd 1.RedisConnection/RedisConnectionDotNetCore
dotnet run
cd 14.RedisAspDotNetCore/RedisAspDotNetCoreWebApiSample
dotnet run

The Web API exposes its endpoints under api/redis; see RedisController.cs.

Contributing

Fixes and updates are welcome. See CONTRIBUTING.md.

License

MIT © Taswar Bhatti

About

C# samples for the Redis for .NET Developers blog series using StackExchange.Redis: connecting, strings, hashes, lists, sets, sorted sets, HyperLogLog, pub/sub, pipelining, transactions, Lua scripting, geospatial queries and an ASP.NET Core Web API. .NET Framework and .NET Core.

Topics

Resources

Contributing

Stars

88 stars

Watchers

9 watching

Forks

Releases

Packages

Used by

Contributors

Languages