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
129
votes
7 answers

Redis - Connect to Remote Server

I've just install Redis succesfully using the instructions on the Quick Start guide on http://redis.io/topics/quickstart on my Ubuntu 10.10 server. I'm running the service as dameon (so it can be run by init.d) The server is part of Rackspace…
gregavola
  • 2,519
  • 5
  • 30
  • 47
129
votes
4 answers

How to disable persistence with redis?

I was wondering how to disable presistence in redis. There is mention of the possibility of doing this here: http://redis.io/topics/persistence. I mean it in the exact same sense as described there. Any help would be very much appreciated!
Cenoc
  • 11,172
  • 21
  • 58
  • 92
126
votes
14 answers

How to store and retrieve a dictionary with redis

# I have the dictionary my_dict my_dict = { 'var1' : 5 'var2' : 9 } r = redis.StrictRedis() How would I store my_dict and retrieve it with redis. For example, the following code does not work. #Code that doesn't work r.set('this_dict',…
PiccolMan
  • 4,854
  • 12
  • 35
  • 53
126
votes
2 answers

Pros and cons to use Celery vs. RQ

Currently I'm working on python project that requires implement some background jobs (mostly for email sending and heavily database updates). I use Redis for task broker. So in this point I have two candidates: Celery and RQ. I had some experience…
Max Kamenkov
  • 2,478
  • 3
  • 22
  • 19
122
votes
7 answers

How Can I Browse/View The Values Stored in Redis

Are there any good browsers/explorer for viewing Redis out there ? Am new to Redis so my expectation is if there is something similar to MongoVUE,Toad or SQLExplorer. I tried Redis Admin UI from service stack but ran into 500 error when trying on…
airboss
  • 1,767
  • 3
  • 16
  • 21
121
votes
6 answers

Redis Vs RabbitMQ as a data broker/messaging system in between Logstash and elasticsearch

We are defining an architecture to collect log information by Logstash shippers which are installed in various machines and index the data in one elasticsearch server centrally and use Kibana as the graphical layer. We need a reliable messaging…
Salindaw
  • 1,556
  • 2
  • 11
  • 10
121
votes
6 answers

Get all keys in Redis database with python

There is a post about a Redis command to get all available keys, but I would like to do it with Python. Any way to do this?
tscizzle
  • 11,191
  • 15
  • 54
  • 88
118
votes
9 answers

Can you connect to Amazon ElastiСache Redis outside of Amazon?

I'm able to connect to an ElastiCache Redis instance in a VPC from EC2 instances. But I would like to know if there is a way to connect to an ElastiCache Redis node outside of Amazon EC2 instances, such as from my local dev setup or VPS instances…
117
votes
2 answers

Difference between Document-based and Key/Value-based databases?

I know there are three different, popular types of non-sql databases. Key/Value: Redis, Tokyo Cabinet, Memcached ColumnFamily: Cassandra, HBase Document: MongoDB, CouchDB I have read long blogs about it without understanding so much. I know…
never_had_a_name
  • 90,630
  • 105
  • 267
  • 383
116
votes
11 answers

node.js database

I'm looking for a database to pair with a node.js app. I'm assuming a json/nosql db would be preferable to a relational DB [I can do without any json/sql impedance mismatch]. I'm considering: couchdb mongodb redis Anyone have any views / war…
Justin
  • 4,649
  • 6
  • 33
  • 71
114
votes
3 answers

How safe is it to store sessions with Redis?

I'm currently using MySql to store my sessions. It works great, but it is a bit slow. I've been asked to use Redis, but I'm wondering if it is a good idea because I've heard that Redis delays write operations. I'm a bit afraid because sessions need…
Trent
  • 5,785
  • 6
  • 32
  • 43
110
votes
2 answers

How to remove debugging from an Express app?

I would like to remove the debugging mode. I am using express, redis, socket.io and connect-redis, but I do not know where the debugging mode comes from. Someone has an idea?
Vsplit
  • 1,988
  • 3
  • 15
  • 18
110
votes
5 answers

How can I use redis with Django?

I've heard of redis-cache but how exactly does it work? Is it used as a layer between django and my rdbms, by caching the rdbms queries somehow? Or is it supposed to be used directly as the database? Which I doubt, since that github page doesn't…
meder omuraliev
  • 183,342
  • 71
  • 393
  • 434
105
votes
13 answers

How to install php-redis extension using the official PHP Docker image approach?

I want to build my PHP-FPM image with php-redis extension based on the official PHP Docker image, for example, using this Dockerfile: php:5.6-fpm. The docs say that I can install extensions this way, installing dependencies for extensions…
starikovs
  • 3,240
  • 4
  • 28
  • 33
104
votes
1 answer

Naming Convention and Valid Characters for a Redis Key

I was wondering what characters are considered valid in a Redis key. I have googled for some time and can not find any useful info. Like in Python, valid variable name should belong to the class [a-zA-Z0-9_]. What are the requirements and…
andy
  • 3,951
  • 9
  • 29
  • 40