arefshojaei / redis
A memory database with key & value
Requires
- php: ^8.1
README
🚀 Redis - PHP In-Memory Key-Value Database
A lightweight Redis-inspired in-memory database built with PHP. Store, manage, and explore your data using a powerful CLI interface or a live web dashboard.
✨ Features
- 🔑 Key-Value Storage - Fast in-memory data management
- 💻 Interactive CLI - Manage your database through terminal commands
- 🌐 Live Web Server - Explore your data from a browser interface
- 📝 String Operations - Set, get, append, and manipulate text data
- 🔢 Number Operations - Increment and decrement numeric values
- 🗂️ Hash Support - Store structured objects using key-value pairs
- 📚 List Support - Manage ordered collections of values
- ⏱️ Expiration System - Set TTL for temporary data
- ⚡ Fast & Lightweight - Built entirely with pure PHP
📥 Installation
Requirements
- PHP 8.1 or higher
- Composer
Install with Composer
composer require arefshojaei/redis
Clone from GitHub
git clone https://github.com/ArefShojaei/Redis.git
cd Redis
🚀 Getting Started
Redis can be used in two different modes.
1. Interactive CLI Mode
Run the database shell:
php bin/redis-cli
Or make it executable:
chmod +x ./bin/redis-cli ./bin/redis-cli
2. Web Dashboard Mode
Start the live server:
php bin/redis-server
Or:
chmod +x ./bin/redis-server ./bin/redis-server
Then open your browser:
http://localhost:8000
📚 Data Types & Commands
🔤 String Commands
Set and get values:
set username Robert
get username
Set and return old value:
getSet username Kevin
Multiple values:
mset name=John age=25 country=USA
Append text:
append message World
Expiration:
setex token 3600 secret-key ttl token
Delete:
del username unlink user1 user2 user3
🔢 Number Commands
Increase and decrease numbers:
set counter 10
incr counter
decr counter
Custom increment:
incrBy counter 5 decrBy counter 2
🗂 Hash Commands
Create object-like data:
hset user name Robert hset user age 25
Multiple fields:
hmset user name:Robert age:25 role:admin
Get data:
hget user name hgetall user
Other operations:
hkeys user hvals user hlen user hexists user age
📋 List Commands
Push values:
lpush tasks "Build Redis" rpush tasks "Write Documentation"
Read data:
lrange tasks 0 10 llen tasks
Remove items:
lpop tasks rpop tasks
🗄 Database Commands
Show all stored data:
dump
List all keys:
keys
Remove all data:
flushdb
🔚 Session Commands
Exit the CLI:
quit
Check connection:
ping
💡 Example Workflow
Create a simple user record:
hset user:1 name Robert hset user:1 email robert@example.com hset user:1 role admin
Retrieve the data:
hgetall user:1
🔥 Why This Project?
This project is useful for learning:
- Database engine concepts
- Key-value storage design
- Command parsing
- CLI application development
- Memory management
- Data structures implementation in PHP
It is a great educational project for understanding how systems like Redis work internally.
🤝 Contributing
Contributions are welcome.
- Fork the repository
- Create a feature branch
git checkout -b feature/amazing-feature
- Commit your changes:
git commit -m "Add amazing feature"
- Push your branch:
git push origin feature/amazing-feature
- Open a Pull Request
👨💻 Author
Aref Shojaei
- 📧 Email: arefshojaei82@gmail.com
- 🐙 GitHub: @ArefShojaei
- 📦 Packagist: arefshojaei/redis
⭐ Show Your Support
If this project helps you learn database internals or PHP system development, consider giving it a Star ⭐ on GitHub.
Your support motivates future improvements.