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

Is Redis Persistence Enabled?

Is there any way to check, from an active session, whether a Redis server has persistence (e.g. RDB persistence) enabled? The INFO command does contain a section on persistence, but it is not clear to me whether the values indicate that persistence…
Gigi
  • 28,163
  • 29
  • 106
  • 188
8
votes
3 answers

Redis as a session store, Invalidate all sessions of a user

I'm using redis as a session store, Storing sessions like so [NameSpace]:[UniqueId] -> [email_id] Here is the problem, when a user resets their password, how do I invalidate all the sessions of that user ? Here are the solutions I came up with,…
Gautam
  • 7,868
  • 12
  • 64
  • 105
8
votes
5 answers

How to make config file in Golang elegantly?

I'm a newbie with Golang. I want to write a program to manage my Redis instances so that I can create a Redis connection with specific config file. But I don't know how to create the config file for Redis instances elegantly. I found "text/template"…
Papulatus
  • 677
  • 2
  • 8
  • 18
8
votes
2 answers

Stackexchange.Redis why does ConnectionMultiplexer.Connect establishes two client connections?

I am curious why ConnectionMultiplexer.Connect(options) attempts to connect 2 clients to the RedisDB instead of 1? Each time I connect I see that 2 additional clients connect to my RedisDB.
Matt
  • 7,004
  • 11
  • 71
  • 117
8
votes
3 answers

Huge Leaderboard ranking with filtering

We are building a massive multi-player educational game with some millions of entries in the leader-board (based on aggregated XPs gained). After a game finishes, we need to show the leaderboard and how this player/student is ranked. But there are a…
Kostas Kryptos
  • 4,081
  • 2
  • 23
  • 24
8
votes
2 answers

Can't connect to redis using django-redis

I've got a django project using django-redis 3.8.0 to connect to an aws instance of redis. However, I receive ConnectionError: Error 111 connecting to None:6379. Connection refused. when trying to connect. If I ssh into my ec2 and use redis-py from…
taman
  • 237
  • 2
  • 9
8
votes
1 answer

redis getaddrinfo ENOTFOUND - node.js , redis connection

Hi im trying to connect to redis from node.js which is successful, now i hosted my node.js server app on amazon ec2 instance and redis on amazon elastic cache instance the connection to redis is succesful but once in a while i'm getting the below…
8
votes
2 answers

How to perform a reverse command history search in redis-cli

How do I do a reverse search on command history in redis-cli? Typing the starting letters and pressing the up arrow doesn't work. Neither does bash style 'ctrl+r'. Please help. Is there a file where redis saves the command history.
akhil_
  • 233
  • 1
  • 4
  • 10
8
votes
1 answer

Redis INCR and multi processes?

I used to use PostgreSQL sequence SELECT nextval('number'); to make sure I get a new number even if there are several clients since nextval is guaranteed to return distinct and increasing values. I wanted to use the same mechanism with Redis. I…
Michael
  • 8,357
  • 20
  • 58
  • 86
8
votes
3 answers

Sidekiq jobs stuck in queue on Heroku

I have a Sidekiq worker functioning well locally, but when deployed to Heroku the jobs get stuck in the queue. I am using Redis-to-go nano and have it up and running, and I have scaled the worker to 1 on Heroku and can see that it is up. I am just…
Andy Weiss
  • 405
  • 5
  • 15
8
votes
2 answers

Partitioned key space for StackExchange Redis

When developing a component that use Redis, I've found it a good pattern to prefix all keys used by that component so that it does not interfere other components. Examples: A component managing users might use keys prefixed by user: and a component…
Mårten Wikström
  • 11,074
  • 5
  • 47
  • 87
8
votes
3 answers

Redis - Can data size be greater than memory size?

I'm rather new to Redis and before using it I'd like to learn some important (as for me) details on it. So.... Redis is using RAM and HDD for storing data. RAM is used as fast read/write storage, HDD is used to make this data persistant. When Redis…
Kirzilla
  • 16,368
  • 26
  • 84
  • 129
8
votes
2 answers

Install Redis on Windows Server

I am trying to install Redis on my windows Server 2012 R2. The problem is that all the installation guides that I have found are out-of-date. Can anyone show me the easiest and most recent way to install Redis on Windows? thanks.
user3242743
  • 1,751
  • 5
  • 22
  • 32
8
votes
4 answers

Redis and escaping binary data

i am having a tough time understanding how to use binary datatypes with redis. I want to use the command set '{binary data}' 'Alex' what if the binary data actually includes a quote symbol or /r/n? I know I can escape characters but is there…
user1978109
  • 727
  • 1
  • 8
  • 19
8
votes
1 answer

Random bad request 400 errors with Socket.io 1.0.6

I'm using Node.js on port 8082 and Apache on port 80. Everything works fine for a while and than the browser start to show error messages "400 Bad Request", CORS errors. The server is setting the CORS headers. As you can see I'm also using Redis…