Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 25

REmote DIctionary Server

Redis Installation
Q.What is Redis actually? Choose the correct answer.
1.database
2.cache
3.message broker
4.streaming engine
“When I say that Redis is a database, I’m only telling a partial truth. Redis is a very
fast non-relational database that stores a mapping of keys to five different types of
values.Redis supports in-memory persistent storage on disk, replication to scale
read performance, and client-side sharding to scale write performance. That was a
mouthful, but I’ll break it down by parts.”
- Josiah L.
Carlson,Redis In Action ,Section 1.1
1.Memcached only support append
command natively.

Why Redis? 2. There is no direct method of


removing items.
3. We have to use blacklisting for
The story of Memcached removing items in memcached.
Blacklisting in Memcached

1. Store the list as a string: Items are added to the end of this string, one after another, separated by a
delimiter (e.g., comma).
2. Blacklist unwanted items: To "remove" an item, a special flag is prepended to its string representation,
indicating it's no longer considered part of the active list.
3. Read and filter: When retrieving the list, the application needs to read the entire string, then filter out the
blacklisted items based on the flag.

This approach has several drawbacks:

● Read/update/write overhead: Every list operation requires reading the entire string, potentially from the
database, modifying it, and writing it back.
● Complexity: The code for manipulating the list and handling blacklisted items becomes more complex
compared to using dedicated data structures.
Structure type What it contains Structure read/write ability

STRING Strings, integers, or floating- Operate on the whole string, parts,


point values increment/
decrement the integers and floats

LIST Linked list of strings Push or pop items from both ends, trim
based on offsets, read individual or multiple
items, find or remove items by value

SET Unordered collection of unique strings Add, fetch, or remove individual items,
check membership, intersect, union,
difference, fetch random items

HASH Unordered hash table of keys to values Add, fetch, or remove individual items,
fetch the whole hash

ZSET (sorted set) Ordered mapping of string Add, fetch, or remove individual values,
members to floating-point fetch items based on score ranges or
scores, ordered by score member value
STRINGS:

Command What it does

GET Fetches the data stored at the given key

SET Sets the value stored at the given key

DEL Deletes the value stored at the given key


(works for all types)

GETSET automatically set specified string value in


redis key and returns its old value. Returns
an error when key exists but does not hold
a string value.
INCR INCR key-name—Increments the value stored at the key by
1

DECR DECR key-name—Decrements the value stored at the key


by 1

INCRBY INCRBY key-name amount—Increments the value stored at


the key by the provided integer value

DECRBY DECRBY key-name amount—Decrements the value stored


at
the key by the provided integer value

INCRBYFLOAT INCRBYFLOAT key-name amount—Increments the value


stored at the key by the provided float value
APPEND APPEND key-name value—Concatenates the
provided value to the string already
stored at the given key

GETRANGE GETRANGE key-name start end—Fetches the


substring, including all characters from the start
offset to the end offset, inclusive

GETBIT GETBIT key-name offset—Treats the byte string as


a bit string, and returns the value of the bit in the
string at the provided bit offset

SETRANGE SETRANGE key-name offset value—Sets the


substring starting at the provided offset to the given
value

SETBIT SETBIT key-name offset value—Treats the byte


string as a bit string, and sets the value of the bit in
the string at the provided bit offset

MGET MGET command is used to get the values of all


specified keys

MSET MSET command is used to set multiple values to


multiple keys
LISTS
Command Usage

RPUSH RPUSH key-name value [value...]—Pushes


the value(s) onto the right end of the list

LPUSH LPUSH key-name value [value...]—Pushes


the value(s) onto the left end of the list

RPOP RPOP key-name—Removes and returns


the rightmost item from the list

LINDEX LINDEX key-name offset—Returns the


item at the given offset

LPOP LPOP key-name—Removes and returns


the leftmost item from the list

LRANGE LRANGE key-name start end—Returns the


items in the list at the offsets from start to
end, inclusive

You might also like