Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ramyaragupathy/url-shortner
https://github.com/ramyaragupathy/url-shortner
Last synced: 13 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/ramyaragupathy/url-shortner
- Owner: ramyaragupathy
- Created: 2018-04-24T03:07:56.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-04-27T11:36:01.000Z (over 6 years ago)
- Last Synced: 2024-11-07T15:52:51.352Z (2 months ago)
- Language: JavaScript
- Homepage: https://kamkar.herokuapp.com/
- Size: 2.48 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## What is Redis?
- Open Source in-memory data structure store written in C
---
### What is in-memory data structure store?
- An in-memory database(IMDB) is also called main memory database system(MMDB) or memory resident database.
- It is a database management system that primarily relies on main memory for computer data storage. i.e the whole dataset is stored in RAM
- Each time you query a DB or update the DB you only access the main memory. So there's no disk involved in the operation. Main memory is faster than the disk, so the reads are faster. However the drawback is the size of the dataset is affected by the RAM availability. A similar DB is Memcached.
---- Redis is a key-value store, often referred to as NoSQL Database. Key-value store means, data/value is stored inside a key. This data is later retrieved only if we know the exact key use dot store it.
`SET key value`
`SET server:name url-shortner`
- Data types supported in Redis:
- Strings
- Lists
- Sets
- Sorted Sets
- Hashes (similar to objects)
- Bitmaps
- Hyperloglogs
- Geospatial indexes
- Bitfields
- Streams- No schema & column names
- Both as a caching system & persistent DB. eg. Memcached is a caching system and MongoDB is persistent DB. Redis has best of both the worlds combined
- Data encryption not supported. Only trusted clients should be allowed access.### Redis Installation/commands on Mac
- Install Redis: `brew install redis`
- Launch Redis on computer start: `ln -sfv /usr/local/opt/redis/*.plist ~/Library/LaunchAgents`
- Start redis server via launchctl: `launchctl load ~/Library/LaunchAgents/homebrew.mxcl.redis.plist`
- Start redis-server using config file: `redis-server /usr/local/etc/redis.conf`
- Stop redis autostart on computer start: `launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.redis.plist`
- Location of Redis config file: `/usr/local/etc/redis.conf`
- Uninstall Redis & remove its files:
- `brew uninstall redis`
- `rm ~/Library/LaunchAgents/homebrew.mxcl.redis.plist`
- Redis package information: `brew info redis`
- Test if redis-server is running:
`redis-cli ping` => `PONG`## Redis-cli commands
### String related
Command|Response
-------|--------
ping|PONG
echo 'hello world'|"hello world"
set <key> <value> | OK
get <key>|<value> or nil if it doesn't exist
incr <key>|Increments an integer value by 1
decr <key>|Decrements an integer value by 1
exists <key>|1 if the key exists, 0 if the key doesn't exist
del <key>|Deletes a k-v pair
flushall|flushes everything from memory
expire <key> <seconds>|k-v pair expires in specified seconds
ttl <key>|Shows the time in seconds for the k-v pair to expire or shows `-2` if it has already expired or key doesn't exist
setex key <time> <value>|set k-v with expiration time
mset <key1> <value1> <key2> <value2> | set multiple k-v pairs
append <key> <value>|Appends value to the existing keyYou can use key spaces like `server:name`, `server:port`
### List related
Command|Response
-------|---------
lpush people "ramya"|Creates a list by name people and pushes "ramya" to the front
lrange people 0 -1|fetches everything in the list `people`
llen people|returns the length of the list
lpop people|removes values from the beginning of list
rpop people|removes values from the end of list
linsert people before "ragupathy" "rani"| inserts a value in the list at a specified index### Set related
Set is an unordered list of strings.
Command|Response
-------|--------
sadd cars "ford"|Creates a set by name cars and adds "ford" to it
sismember cars "ford"|returns `1` if `ford` is a member of set cars
smembers cars|gives all the members of the cars set
scard cars|gives how many members are there in the set
smove cars mycars "ford"| Moves "ford" from the cars set to another set mycars
srem cars "honda"|removes a member from the set### Sorted sets
They're similar to sets except that every member is associated to a score. Members are sorted from the smallest to greater score. Members are unique, but scores can be repeated.
Command|Response
-------|---------
zadd users 1990 user1|adds user1 with score 1990 to the users set
zrank users user1|returns the rank/index of user1 with users set
zrange users 0 -1| returns all the members in the sorted set
zincrby users 10 user1|increments the score of user 1 within the users sorted set by 10. This alters the rank of all the members### Hash related
Command|Response
-------|--------
hset user:ramya name ramya|sets a hash `user:ramya` with k-v `name-ramya`
hget user:ramya name|gets the name from user:ramya hash
hgetall user:ramya|gets all the k-v pairs in the user:ramya hash
hmset user:user1 name firstname surname surname|multiple k-v pairs for a hash
hkeys user:ramya|returns all the keys of user:ramya hash
hvals user:ramya|retruns all the values of user:ramya hash
hincrby user:user1 age 10|increments age field of hash user:user1 by 10
hdel user:user1 age|deletes a particular field in the hash user:user1
hlen user:user1|retruns the number of k-v pairs in the hash## Redis persistence
- snapshots of dataset at specified intervals
- AOF(Append-only file) persistence logs