Questions tagged [redis]

Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker. It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs, geospatial indexes with radius queries and streams. It also provides pub-sub capabilities. Use this tag for questions related to Redis and in-memory system.

Redis

Redis is a BSD-licensed, advanced key-value store which works in-memory but provides disk persistence. It is often referred to as a data structure server since keys can contain as values different data structures:

  • Strings, which are binary safe and up to 512 MB in size.

  • Lists, offering O(1) push/pop/trim/length operations regardless of the number of elements contained inside the list. Lists also provide blocking operations (pop-style commands that block if there are no elements in the list), so Redis lists are often used in order to implement background jobs and other kinds of queues. There are very popular libraries like Resque and Sidekiq using Redis as a backend.

  • Hashes are field-value maps like in most programming languages. They are useful in order to represent objects and are very memory efficient for a small number of fields, yet very scalable supporting up to 2.14 billion fields per hash.

  • Sets are unordered collections of elements and are useful in order to add, remove, and test elements for existence in constant-time. Small sets of integers are extremely space efficient, and but sets scale up to 2.14 billion elements per set. It is possible to ask for random elements inside sets which is very useful. See SPOP and SRANDMEMBER for more information.

  • Sorted sets are very useful data structures where collections or elements are ordered by a floating point number called score. The data structure offers a set of very powerful operations running in logarithmic time: it is possible to add and remove elements, increment the score of elements, get ranges by rank and by score, given an element get its position (rank) or score, and so forth. A notable application is leader boards involving million of users: there are companies using Redis sorted sets in order to implement leader boards of popular games such as Facebook games.

  • Geo sets are sorted sets in which elements' scores are used for storing locations - longitude and latitude - as geohash-encoded values. Once stored in this fashion, the elements can be queried by their distance from an arbitrary position with the GEORADIUS command. Geospatial indexes are used by any location-based application and service, including: social networks, navigation & commuting assistance and fleet management.

  • Counters are not exactly a type per se, but actually operations you can use with strings that represent integers. For example, the command INCR mykey will automatically create a key with the string value "1" if the key does not exist. The next call will modify the value of the string into "2", and so forth. You can increment and decrement by floats or by any amount. Values are in the range of a signed 64-bit number even when using Redis on 32-bit architectures.

  • Bit operations, like counters, operate in strings in a different way. The user is basically able to treat the string as an array of bits, doing very memory-efficient operations. For example, if you have ten million users and want to store a Boolean value for every user, you'll need just a bit more than 1 MB of memory! Because of the rich set of bitwise commands you can: count the number of set bits with BITCOUNT; perform bitwise AND, OR, XOR, and NOT between bitmaps using BITOP; find the first bit clear or set in a given range with BITPOS; and so forth.

  • Bit fields are strings that, similarly to bit operations, are treated as an array of bits. These allow referencing integers of varying types (unsigned or signed 1-bit to 64-bits and 63-bits, respectively) by offset or position. Each such bit field can be read, written or incremented and supports several overflow modes via the use of the BITFIELD command.

  • HyperLogLog is a probabilistic data structure that efficiently (in terms of computational and memory complexity) addresses the count-distinct problem. The Redis implementation of HLL requires only 12KB for each counter and exhibits a standard error of 0.81%. HLLs can be added with items, merged and counted using the PFADD, PFMERGE and PFCOUNT commands, respectively (the PF prefix of the commands is in honor of Phillipe Flajolet, HyperLogLog's inventor).

  • Streams, that are structures that provide an abstraction of log-like append-only data. Messages in the stream are added by producers with the XADD command, and the processing of these is done by consumers with the XREAD. Streams also support the concept of Consumer Groups via the XREADGROUP for simple and efficient scaling.

  • Modules, that are basically just dynamically-loaded server-side libraries, can developed and used by anyone and everyone for extending the core Redis platform with anything from custom data types (e.g. a Bloom Filter) to full-fledged servers (e.g. a search engine). Modules are supported as of v4.

To get started quickly, try Redis directly inside your browser, read this quick intro to Redis data types, or watch a great presentation by Peter Cooper.

Features as a data store

While Redis is an in-memory system, it offers a lot of features of a data store.

  • Tunable on-disk persistence with a point-in-time snapshotting persistence, or an Append Only File with tunable fsync policy.
  • Asynchronous replication.
  • Redis is also a very fast Pub/Sub server.
  • An API to configure Redis at runtime and automatically rewrite the configuration file.
  • Automatic failover and monitoring via Redis Sentinel.
  • Shared-nothing clustering is available from v3.

It has an impressive ecosystem of client libraries for all the mainstream and elite programming languages.

Community

The Redis community is big and willing to help.

Persistency

There are two options for persistency in Redis:

  • RDB (Redis Database File): This option takes snapshot from database periodically.
  • AOF (Append Only File): Logs every write operation and reconstructs dataset at startup.

RDB is faster than AOF but loses created data after the latest snapshot.

Support

Support for Redis is provided by the following companies:

Certification

Redis has a Professional Certification program at no cost! There are three prerequisite courses that must be successfully completed before enrolling in the Developer Certification Program:

  1. Introduction to Redis Data Structures
  2. Redis Streams
  3. Any other elective Redis University class of your choice.

The Redis Certified Developer exam is a timed, 90-minute multiple-choice test. You can schedule your exam at any time and take it from any location, including your own home. You can learn more about the Redis Certified Developer Program from the official certification page.

Related tags

24955 questions
8
votes
2 answers

Redis Capped Sorted Set, List, or Queue?

Has anyone implemented a capped data-structure of any kind in Redis? I'm working on building something like a news feed. The feed will wind up being manipulated and read from very frequently, and holding it in a sorted set in Redis would be cheap…
Eli
  • 36,793
  • 40
  • 144
  • 207
8
votes
1 answer

Atomic set only if not already set

Is there any way to do an atomic set only if not already set in Redis? Specifically, I'm creating a user like "myapp:user:user_email" and want Redis to give me back an error if "user_email" is already taken, instead of silently replacing the old…
Aaron Yodaiken
  • 19,163
  • 32
  • 103
  • 184
8
votes
3 answers

How can I pop objects from Redis as they are added realtime?

I want to get a Node.js process running as it's checking a Redis server for anything new to pop. Another process will be doing the pushing sporadically, and the Node process will be trying to pop whatever that comes in. The Node process will stay…
deeJ
  • 361
  • 4
  • 13
8
votes
4 answers

Persistent in-memory Python object for nginx/uwsgi server

I doubt this is even possible, but here is the problem and proposed solution (the feasibility of the proposed solution is the object of this question): I have some "global data" that needs to be available for all requests. I'm persisting this…
Dev Kanchen
  • 2,332
  • 3
  • 28
  • 40
8
votes
1 answer

Redis commands queue size

How to log/measure the size of Redis command's queue. The Redis is single-threaded, so it runs commands sequentially, as I guess there is command queue there, where the incoming commands are stored, and executed one by one. The SLOWLOG command only…
MKo
  • 4,768
  • 8
  • 32
  • 35
8
votes
1 answer

SignalR - Switch between different Redis backplanes

Let's assume we have 2 Redis Server Backplanes, one as Master and the other as Slave. Each web application is using SignalR in order to push content to the connected clients as it happens and in order to connect them to the backplane I am using in…
ppolyzos
  • 6,791
  • 6
  • 31
  • 40
8
votes
5 answers

How to copy values from one list into another in Redis?

I have a Redis list with some values LRANGE LIST 0 -1 > 1 > 2 > 3 And I want to RPUSH these values into another list. How can this be done? I've tried to do it with MULTI and EXEC, but with no results.
amb
  • 4,798
  • 6
  • 41
  • 68
8
votes
4 answers

Redis: Get all score available for a sorted set

I need to get all score available for a redis sorted set. redis> ZADD myzset 10 "one" (integer) 1 redis> ZADD myzset 20 "two" (integer) 1 redis> ZADD myzset 30 "three" (integer) 1 Now I want to retrieve all score for myzset, ie. 10,20,30.
biztiger
  • 1,447
  • 4
  • 23
  • 40
8
votes
1 answer

What is the difference between a Cookie and Redis Session store?

I want to share sessions among 2 applications on different nodes; however, I am confused what the difference is between Cookie and Redis session stores; e.g. a cookie session might look like…
poseid
  • 6,986
  • 10
  • 48
  • 78
8
votes
1 answer

Why use Redis instead of storage in normal variables?

What is the advantage of using Redis for session storage over simply storing all data in variables inside your app?
Tiddo
  • 6,331
  • 6
  • 52
  • 85
8
votes
1 answer

How to set up handlers in RedMQ from events raised in my domain

Just getting my head around message queues and Redis MQ, excellent framework. I understand that you have to use .RegisterHandler(...) to determine which handler will process the type of message/event that is in the message queue. So if I have…
JD.
  • 15,171
  • 21
  • 86
  • 159
8
votes
3 answers

nodejs redis Q promises, how to make it work?

I am trying to get few values from redis, combine them and eventually send. But I just can't make those promises work. This is the simple get functions from redis client.get('user:1:id',function(err,data){ // here I have data which contains user…
Giedrius
  • 1,590
  • 3
  • 16
  • 27
8
votes
3 answers

Dealing with exception handling and re-queueing in RQ on Heroku

I have a website running on Heroku in Python, and I have a worker up as a background process to handle tasks that I don't want to block webpage delivery and therefore are inappropriate for the web dynos. For this, I've set up a queue using rq and…
jdotjdot
  • 16,134
  • 13
  • 66
  • 118
8
votes
3 answers

redigo, SMEMBERS, how to get strings

I am redigo to connect from Go to a redis database. How can I convert a type of []interface {}{[]byte{} []byte{}} to a set of strings? In this case I'd like to get the two strings Hello and World. package main import ( "fmt" …
topskip
  • 16,207
  • 15
  • 67
  • 99
8
votes
1 answer

Resque, Resque Server, on RedisToGo with Heroku

I've been trying to get Resque (with Resque server) & RedisToGo working on heroku (cedar) for awhile now, but I keep running into this error: Redis::CannotConnectError (Error connecting to Redis on 127.0.0.1:6379 (ECONNREFUSED)): Its working…
Elliot
  • 13,580
  • 29
  • 82
  • 118
1 2 3
99
100