Redis - DhruvSingh861/Netcore_Assignment GitHub Wiki
Redis
- Redis is an open source, BSD licensed, advanced key-value store.
- It is often referred to as a data structure server, since the keys can contain strings, hashes, lists, sets and sorted sets.
- Redis is written in C.
- Redis holds its database entirely in the memory, using the disk only for persistence.
- Redis has a relatively rich set of data types when compared to many key-value data stores.
- Redis can replicate data to any number of slaves.
- All Redis operations are atomic, which ensures that if two clients concurrently access, Redis server will receive the updated value.
Redis Commands
redis-cli This will connect to your local server and now you can run any command.
redis-cli -h host -p port -a password To run commands on Redis remote server.
Keys
DEL keyThis command deletes the key, if it exists.DUMP keyThis command returns a serialized version of the value stored at the specified key.EXISTS keyThis command checks whether the key exists or not.EXPIRE key secondsSets the expiry of the key after the specified time.EXPIREAT key timestampSets the expiry of the key after the specified time. Here time is in Unix timestamp format.PEXPIRE key millisecondsSet the expiry of key in milliseconds.PEXPIREAT key milliseconds-timestampSets the expiry of the key in Unix timestamp specified as milliseconds.KEYS patternFinds all keys matching the specified pattern.MOVE key dbMoves a key to another database.PERSIST keyRemoves the expiration from the key.PTTL keyGets the remaining time in keys expiry in milliseconds.TTL keyGets the remaining time in keys expiry.RANDOMKEYReturns a random key from Redis.RENAME key newkeyChanges the key name.RENAMENX key newkeyRenames the key, if a new key doesn't exist.TYPE keyReturns the data type of the value stored in the key.
String
SET key valueThis command sets the value at the specified key.GET keyGets the value of a key.GETRANGE key start endGets a substring of the string stored at a key.GETSET key valueSets the string value of a key and returns its old value.GETBIT key offsetReturns the bit value at the offset in the string value stored at the key.MGET key1 [key2..]Gets the values of all the given keys.SETBIT key offset valueSets or clears the bit at the offset in the string value stored at the key.SETEX key seconds valueSets the value with the expiry of a key.SETNX key valueSets the value of a key, only if the key does not exist.SETRANGE key offset valueOverwrites the part of a string at the key starting at the specified offset.STRLEN keyGets the length of the value stored in a key.MSET key value [key value ...]Sets multiple keys to multiple values.MSETNX key value [key value ...]Sets multiple keys to multiple values, only if none of the keys exist.PSETEX key milliseconds valueSets the value and expiration in milliseconds of a key.INCR keyIncrements the integer value of a key by one.INCRBY key incrementIncrements the integer value of a key by the given amount.INCRBYFLOAT key incrementIncrements the float value of a key by the given amount.DECR keyDecrements the integer value of a key by one.DECRBY key decrementDecrements the integer value of a key by the given number.APPEND key valueAppends a value to a key.