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
1483
votes
17 answers

Memcached vs. Redis?

We're using a Ruby web-app with Redis server for caching. Is there a point to test Memcached instead? What will give us better performance? Any pros or cons between Redis and Memcached? Points to consider: Read/write speed. Memory usage. Disk I/O…
Sagiv Ofek
  • 25,190
  • 8
  • 60
  • 55
876
votes
25 answers

How do I delete everything in Redis?

I want to delete all keys. I want everything wiped out and give me a blank database. Is there a way to do this in Redis client?
TIMEX
  • 259,804
  • 351
  • 777
  • 1,080
771
votes
40 answers

How do I run Redis on Windows?

How do I run Redis on Windows? The Redis download page just seems to offer *nix options. Can I run Redis natively on Windows?
DaveHeller
  • 7,899
  • 3
  • 19
  • 9
753
votes
32 answers

How to atomically delete keys matching a pattern using Redis

In my Redis DB I have a number of prefix: hashes. Sometimes I want to purge them all atomically. How do I do this without using some distributed locking mechanism?
Alexander Gladysh
  • 39,865
  • 32
  • 103
  • 160
670
votes
16 answers

Redis command to get all available keys?

Is there a Redis command for fetching all keys in the database? I have seen some python-redis libraries fetching them. But was wondering if it is possible from redis-client.
Lalith
  • 19,396
  • 17
  • 44
  • 54
646
votes
38 answers

MISCONF Redis is configured to save RDB snapshots

During writes to Redis ( SET foo bar ) I am getting the following error: MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Commands that may modify the data set are disabled. Please check Redis…
Salvador Dali
  • 214,103
  • 147
  • 703
  • 753
517
votes
30 answers

How can I stop redis-server?

I apparently have a redis-server instance running because when I try to start a new server by entering redis-server, I'm greeted with the following: Opening port: bind: Address already in use I can't figure out how to stop this server and start a…
Qcom
  • 18,263
  • 29
  • 87
  • 113
504
votes
10 answers

What is Express.js?

I am a learner in Node.js. What's Express.js? What's the purpose of it with Node.js? Why do we actually need Express.js? How is it useful for us to use with Node.js? What's Redis? Does it come with Express.js?
vinod
  • 8,350
  • 9
  • 32
  • 36
466
votes
10 answers

When to Redis? When to MongoDB?

What I want is not a comparison between Redis and MongoDB. I know they are different; the performance and the API is totally different. Redis is very fast, but the API is very 'atomic'. MongoDB will eat more resources, but the API is very very easy…
guilin 桂林
  • 17,050
  • 29
  • 92
  • 146
350
votes
6 answers

Redis strings vs Redis hashes to represent JSON: efficiency?

I want to store a JSON payload into redis. There's really 2 ways I can do this: One using a simple string keys and values. key:user, value:payload (the entire JSON blob which can be 100-200 KB) SET user:1 payload Using hashes HSET user:1 username…
Henley
  • 21,258
  • 32
  • 119
  • 207
344
votes
3 answers

What are the underlying data structures used for Redis?

I'm trying to answer two questions in a definitive list: What are the underlying data structures used for Redis? And what are the main advantages/disadvantages/use cases for each type? So, I've read the Redis lists are actually implemented with…
Homer6
  • 15,034
  • 11
  • 61
  • 81
319
votes
7 answers

WRONGTYPE Operation against a key holding the wrong kind of value php

Hi I am using Laravel with Redis .When I am trying to access a key by get method then get following error "WRONGTYPE Operation against a key holding the wrong kind of value" I am using following code to access the key value - i use this code for get…
Trushar Narodia
  • 3,511
  • 2
  • 11
  • 17
308
votes
9 answers

WSL Redis encountered System has not been booted with systemd as init system (PID 1). Can't operate

I'm trying to follow the Redis installation process that was discuss in this article of digital ocean, for in WSL(Windows Sub-System for Linux). The Ubuntu version installed is Ubuntu 18.04. Everything in redis installation is fine but when I tried…
Fil
  • 8,225
  • 14
  • 59
  • 85
287
votes
18 answers

Linux - Install redis-cli only

I have a Linux server with Redis installed and I want to connect to it via command line from my local Linux machine. Is it possible to install redis-cli only (without redis-server and other tools)? If I just copy redis-cli file to my local machine…
Oleg
  • 22,300
  • 9
  • 68
  • 84
285
votes
12 answers

Is Redis just a cache?

I have been reading some Redis docs and trying the tutorial at http://try.redis-db.com/. So far, I can't see any difference between Redis and caching technologies like Velocity or the Enterprise Library Caching Framework You're effectively just…
Matt Evans
  • 7,113
  • 7
  • 32
  • 64
1
2 3
99 100