Connect to Redis using NodeJs

Redis is a data store. Well, suited to handling simple data, that doesn’t need to be stored for long-term access such as instant messages and game-related data.

Redis stores data in Ram logging changes to it to disk the downside to this is that storage space is limited but the advantage is that radius can perform data manipulation quickly. If a ready server crashes and the contents of the ram are lost the dicks log can be used to restore the data.

Radius provides a vocabulary of primitive but useful commands. That works on several data structures. Most of the data structures supported by radius will be familiar to developers as they are analogous to those frequently used in programming like hash tables, lists, and E value pairs.

Hash table and key-value pair types are Illustrated in the figure radius. Also supports a less familiar data structure called to set, which we will talk about later.

We owned go into all of the Redis commands in this chapter, but we will run through several examples that will be applicable for most applications. If you are new to reddish and one to get an idea of its usefulness. Before trying these examples, a great place to start is the try Is tutorial.

The most mature and actively developed radius API. The module is Matt’s redness node. Reddish module Install this module using the following npm command.

npm install redis

Connecting to a radius server.

The following code establishes, a connection to a radius server. Using the default TCP IP port running on the same. Host, the radius client you have created, has inherited event emitter behavior that emits, an error event when the client has problems communicating with the radius server.

As the following example, shows you can Define your own error handling logic by adding a listener to the error event type

Manipulating data in radius.

After you have connected to Redis, your application can start manipulating data immediately using the client object. In the following example, the code shows the storage and retrieval of a key-value pair.

Storing and retrieving values using a hash table.

The figure shows the storage and retrieval of values in a slightly more complicated data structure. A hash table is also known as a hashmap. A hash table is essentially a table of identifiers called keys that are associated with corresponding values.

D. Hm set radius, command sets hash table elements, identified by a key to a value, the H Keys reduce command list. The keys of each element in a hash table.

Storing and retrieving data using the list.

Another data structure, ready? Supports is the list here radius list can? Theoretically hold over 4 billion elements memory permitting. The following code shows the storage and retrieval of value. In a list, the l.push radius command adds value to a list. The L range. Ready? Spirometry chips? A range of list items using start and end arguments.

The -1 and argument in the following code signify that the last item of the list. So this use of the L range will retrieve all list items.

Spread the love