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
81
votes
16 answers

redis-server in ubuntu14.04: Bind address already in use

I started redis server on ubuntu by typing this on terminal: $redis-server This results in following > http://paste.ubuntu.com/12688632/ aruns ~ $ redis-server 27851:C 05 Oct 15:16:17.955 # Warning: no config file specified, using the default…
aruns
  • 1,049
  • 1
  • 8
  • 19
81
votes
5 answers

Executing batches of commands using redis cli

I have a long text file of redis commands that I need to execute using the redis command line interface: e.g. DEL 9012012 DEL 1212 DEL 12214314 etc. I can't seem to figure out a way to enter the commands faster than one at a time. There are…
LTME
  • 1,086
  • 1
  • 10
  • 13
80
votes
1 answer

Redis Pubsub and Message Queueing

My overall question is: Using Redis for PubSub, what happens to messages when publishers push messages into a channel faster than subscribers are able to read them? For example, let's say I have: A simple publisher publishing messages at the rate…
Marco Benvoglio
  • 1,283
  • 2
  • 12
  • 17
79
votes
4 answers

What is the maximum value size you can store in redis?

Does anyone know what the maximum value size you can store in redis? I want to use redis as a message queue with celery to store some small documents that need to be processed by a worker on another server, and I want to make sure the documents…
Ken Cochrane
  • 75,357
  • 9
  • 52
  • 60
78
votes
7 answers

Best Redis library for Java

The official Redis homepage lists JDBC-Redis and JRedis. What are the advantages / disadvantages of each ? Are there any other options ?
muriloq
  • 2,692
  • 5
  • 29
  • 32
78
votes
6 answers

How to access Redis log file

Have Redis setup with ruby on ubuntu server, but can't figure out how to access its log file. Tutorial says it should be here: /var/log/redis_6379.log But can't even find the /var/ folder
Christoffer
  • 7,436
  • 4
  • 40
  • 42
78
votes
4 answers

How to implement server push in Flask framework?

I am trying to build a small site with the server push functionality on Flask micro-web framework, but I did not know if there is a framework to work with directly. I used Juggernaut, but it seems to be not working with redis-py in current version,…
little-eyes
  • 945
  • 2
  • 9
  • 14
77
votes
8 answers

What's the most efficient node.js inter-process communication library/method?

We have few node.js processes that should be able to pass messages, What's the most efficient way doing that? How about using node_redis pub/sub EDIT: the processes might run on different machines
DuduAlul
  • 6,313
  • 7
  • 39
  • 63
76
votes
6 answers

want to run redis-server in background nonstop

I have downloaded redis-2.6.16.tar.gz file and i installed sucessfully. After installed i run src/redis-server it worked fine. But i don't want manually run src/redis-server everytime, rather i want redis-server running as background process…
siv rj
  • 1,451
  • 1
  • 14
  • 31
75
votes
8 answers

What should I choose: MongoDB/Cassandra/Redis/CouchDB?

We're developing a really big project and I was wondering if anyone can give me some advice about what DB backend should we pick. Our system is compound by 1100 electronic devices that send a signal to a central server and then the server stores the…
Juanda
  • 1,648
  • 1
  • 20
  • 29
75
votes
13 answers

Sidekiq not processing queue

What possible reasons can Sidekiq prevent from processing jobs in the queue? The queue is full. The log file sidekiq.log indicates no activity at all. Thus the queue is full but the log is empty, and Sidekiq does not seem to process items. There…
0x4a6f4672
  • 27,297
  • 17
  • 103
  • 140
74
votes
2 answers

Celery: When should you choose Redis as a message broker over RabbitMQ?

My rough understanding is that Redis is better if you need the in-memory key-value store feature, however I am not sure how that has anything to do with distributing tasks? Does that mean we should use Redis as a message broker IF we are already…
Pig
  • 2,002
  • 5
  • 26
  • 42
74
votes
1 answer

ASP.NET MVC OutputCacheAttribute with external cache providers

After switching an ASP.NET MVC 5 application to Azure Redis (Microsoft.Web.RedisOutputCacheProvider Nuget package) I was surprised to see that OutputCacheAttribute when set to use either OutputCacheLocation.Any or…
UserControl
  • 14,766
  • 20
  • 100
  • 187
73
votes
4 answers

Retrieving/Listing all key/value pairs in a Redis db

I'm using an ORM called Ohm in Ruby that works on top of Redis and am curious to find out how the data is actually stored. I was wondering if there is way to list all the keys/values in a Redis db. Update: A note for others trying this out using…
Jagtesh Chadha
  • 2,632
  • 2
  • 23
  • 30
72
votes
9 answers

node.js store objects in redis

Here is the thing - I want to store native JS (node.js) objects (flash sockets references) in redis under a certain key. When I do that with simple client.set() it's stored as a string. When I try to get value I get [object Object] - just a…
Pono
  • 11,298
  • 9
  • 53
  • 70