A BRIEF INTRODUCTION ABOUT REDIS DATA TYPES

 What is REDIS:


Redis stands for Remote Dictionary server and it is a fast and open source in memory, it is a key-value data store. Redis is an open-source (BSD licensed), in-memory data store used as a database, cache, message, and streaming engine.

 

Redis supports most leading programming languages and protocols, including Python, Java, PHP, Go, Ruby, C/C#/C++, JavaScript, Node.js, etc.



  • It is released under the terms of the three clause BSD license. Most of the Redis source code was written and is copyrighted by Salvatore Sanfilippo and Pieter Noordhuis. A list of other contributors can be found in the proper history.

Redis Data Types:

Redis Supports many data types. They are:

  • Strings
  • Lists
  • Sets
  • Hashes
  • Sorted sets
  • Bitmaps and HyperLogLogs
  • Streams
  • Geospatial Indexes

Strings:

The most basic type of Redis value is a string. Redis Strings are binary safe, which implies that they may hold any type of data, such as a JPEG picture or a serialized Ruby object.

A string value can be at a max of 512 Megabytes in length.

Redis Strings commands:

SET Key value: Sets the value for the specified key.

GET Key: Retrieves the value for the specified key.

DEL Key: Deletes the value for the given key.

Lists:

Redis Lists are simple strings ordered by insertion order. It is possible to add elements to a Redis List by pushing new entries to the list’s head (on the left ) or tail (on the right).

LPUSH: Pushes the value to the left end of the list.

RPUSH: Pushes the value to the tail end of the list.

LRANGE: Retrieves a range of items.

LPOP/RPOP: Used to display and remove items from both ends.

LINDEX: Obtain a value from a specific position within the list.






Sets: A Redis set is a collection of unique strings that are not sorted. You can't remove entries from the start or end of the index as you do with lists since sets aren't sorted. The strings, on the other hand, are unique, and numerous instances of the same item inside a set are not possible.

Use the following commands to add, remove, retrieve, and inspect individual items of a set:

SADD: Add one or more items to a set

SISMEMBER: Find out if an item is part of a set

SMEMBERS: Retrieves all items from a set.

SREM: Removes an existing item from a set.














Hashes:

An unordered mapping of key-value pairs is stored in a Redis hash. A value is connected with a hash key. A Redis string containing another key-value pair is used as the value. Other complicated data structures, such as assets, lists, and other hashes, can’t be used as values.

 HSET: Map a value to a key within the hash.

HGET: Retrieves individual values associated with a key within the hash.

HGETALL: Displays the entire hash content.

HDEL: Removes an existing key-value pair from a hash.










Sorted Sets:

Sorted sets or ZSETS are one of the most advanced data types in Redis.

A sorted set key-value pair’s value is made up of a unique string element(key) called a member and an item (value) called a score. Sorted sets assign a floating-point value (score) to each element and use that value to sort the components in a given order.

 You can access items in sorted sets by member, sorted order, and by the score values.

 ZADD: Adds a member with a score to the sorted sets.

ZRANGE: Retrieves items based on their position in the sorted order.

ZRANGEBYSCORE: Fetches items from the sorted set based on the defined score range.

ZREM: Removes items from a sorted set.









Bitmaps:

Bitmaps allow you to manipulate strings on the bit level by using the appropriate commands:

 SETBIT: The bit is defined or cleared based on a 0 or 1 value.

GETBIT: Retrieves the bit value for the string value specified by akey.

BITTOP: Execute bitwise operations between strings.

BITPOS: Locate the first bit set to 1 or 0 in a string.

BITCOUNT: Count the number of bits set to 1 in a string.

 HYPERLOGLOGS:

 HyperLogLogs calculate the number of unique objects in a collection. Items in a HyperLogLogs are not individually tailed, as this would involve keeping track of preceding items to avoid counting the same element twice, as in other systems. This process necessitates the same amount of memory as was utilised to store the data.

 PFADD: Add one or several elements to a hyperLogLog.

PFCOUNT: Fetch an estimated count of unique items from a single HyperLogLog.

PFMERGE: Merge different HyperLogLogs into a single HyperLogLog.

 The accuracy of the findings varies according to the quantity of the collection. If you don’t require an accurate count of objects, though, this probabilistic structure allows you to employ a fraction of RAM you’d normally need.

 Streams:

A Redis stream is a data structure that works in the same way as an append-only log does. Streams are excellent for capturing events in chronological order.

 Geospatial indexes:

Geospatial indexes are provided by Redis and are useful for discovering places within a certain geographic radius. 

The GEOADD command can be used to add locations to a geospatial index. The GEORADIUS command is then used to find places with a specified radius.

Conclusion:

In this article, You know about Redis data Types and the basic command associated with each data structure. Redis provides flexibility for designing a viable and effective storage solution for our appliactions.

Jayakumar Pannela |Associate Software Engineer

Comments

Popular posts from this blog

Oracle Database Server Architecture: Overview

Oracle E-Business Suite (EBS) - Introduction

Why enterprises must not ignore Azure DevOps Server