Cachier is a .NET-based application that leverages Redis for efficient caching and data management. It supports various Redis operations including strings, hashes, lists, sets, sorted sets, hyperloglogs, transactions, and pub/sub functionality.
- String Operations: Set, get, and delete string values.
- Hash Operations: Manage and retrieve hash fields.
- List Operations: Add, get, and remove list items.
- Set Operations: Add, get, and remove set members.
- Sorted Set Operations: Add, get, and remove items from sorted sets.
- HyperLogLog Operations: Add items and count unique items.
- Transactions: Execute multiple Redis commands in a transaction.
- Pub/Sub: Publish and subscribe to Redis channels.
-
Clone the repository:
git clone https://github.com/nimanikoo/cachier.git cd cachier
-
Install dependencies:
dotnet restore
-
Configure your environment:
Update the
appsettings.json
file with your database and Redis connection strings:{ "Logging": { "LogLevel": { "Default": "Information", "Microsoft.AspNetCore": "Warning" } }, "AllowedHosts": "*", "ConnectionStrings": { "DefaultConnection": "Server=.;Database=CashingApi_db;Trusted_Connection=True;TrustServerCertificate=True" }, "RedisCacheUrl": "localhost" }
-
Run the application:
dotnet run
The application exposes several API endpoints to interact with the cache:
-
Set a String Value
POST /cache/string Content-Type: application/json { "key": "myKey", "value": "myValue" }
-
Get a String Value
GET /cache/string?key=myKey
-
Delete a String Value
DELETE /cache/string?key=myKey
-
Set a Hash Field
POST /cache/hash Content-Type: application/json { "key": "myHash", "field": "myField", "value": "myValue" }
-
Get a Hash Field
GET /cache/hash?key=myHash&field=myField
-
Get All Hash Fields
GET /cache/hash/all?key=myHash
-
Delete a Hash Field
DELETE /cache/hash?key=myHash&field=myField
-
Add to List
POST /cache/list Content-Type: application/json { "key": "myList", "value": "myValue" }
-
Get List Items
GET /cache/list?key=myList
-
Remove from List
DELETE /cache/list Content-Type: application/json { "key": "myList", "value": "myValue" }
-
Add to Set
POST /cache/set Content-Type: application/json { "key": "mySet", "value": "myValue" }
-
Get Set Members
GET /cache/set?key=mySet
-
Remove from Set
DELETE /cache/set Content-Type: application/json { "key": "mySet", "value": "myValue" }
-
Add to Sorted Set
POST /cache/sortedset Content-Type: application/json { "key": "mySortedSet", "value": "myValue", "score": 1 }
-
Get Sorted Set Range
GET /cache/sortedset?key=mySortedSet&start=0&end=10
-
Remove from Sorted Set
DELETE /cache/sortedset Content-Type: application/json { "key": "mySortedSet", "value": "myValue" }
-
Add to HyperLogLog
POST /cache/hyperloglog Content-Type: application/json { "key": "myHyperLogLog", "value": "myValue" }
-
Get HyperLogLog Count
GET /cache/hyperloglog?key=myHyperLogLog
-
Execute a Redis Transaction
POST /cache/transaction Content-Type: application/json { "commands": [ {"type": "set", "key": "key1", "value": "value1"}, {"type": "get", "key": "key1"} ] }
-
Subscribe to a Channel
POST /cache/subscribe Content-Type: application/json { "channel": "myChannel" }
-
Publish a Message
POST /cache/publish Content-Type: application/json { "channel": "myChannel", "message": "Hello, world!" }
- Fork the repository
- Create a new branch (
git checkout -b feature/your-feature
) - Commit your changes (
git commit -am 'Add new feature'
) - Push to the branch (
git push origin feature/your-feature
) - Create a Pull Request
This project is licensed under the MIT License.
For questions or suggestions, please open an issue on GitHub or email me at nikoonazar.nima@gmail.com.
Feel free to further customize it as needed!