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
42
votes
5 answers

Redis server port already in use

I'm using Redis version 2.2.13 jack@ubuntu:~/redis$ src/redis-server [23900] 14 Sep 14:28:52 # Warning: no config file specified, using the default config. In order to specify a config file use 'redis-server /path/to/redis.conf' [23900] 14 Sep…
Jack
  • 15,614
  • 19
  • 67
  • 92
42
votes
10 answers

LogicException: Please make sure the PHP Redis extension is installed and enabled

Laravel Version: 7.5.0 PHP Version: 7.2 Database Driver & Version: Redis Everything was working fine but suddenly this error appear i changed the phpredis to predis but error is same. Steps To Reproduce: I am calling the event function event(new…
UMAIR ALI
  • 1,055
  • 5
  • 14
  • 25
42
votes
7 answers

How to destroy jobs enqueued by resque workers?

I'm using Resque on a rails-3 project to handle jobs that are scheduled to run every 5 minutes. I recently did something that snowballed the creation of these jobs and the stack has hit over 1000 jobs. I fixed the issue that caused that many jobs to…
Kibet Yegon
  • 2,763
  • 2
  • 25
  • 32
42
votes
2 answers

Redis, CouchDB or Cassandra?

What are the strengths and weaknesses of the various NoSQL databases available? In particular, it seems like Redis is weak when it comes to distributing write load over multiple servers. Is that the case? Is it a big problem? How big does a service…
nornagon
  • 15,393
  • 18
  • 71
  • 85
42
votes
3 answers

Should I store JWT tokens in redis?

I'm building an application with ExpressJS, Mongodb(Mogoose). Application contains routes where user has to be authenticated before accessing it. Currently I have written a express middleware to do the same. Here with the help of JWT token I'm…
manish keer
  • 1,847
  • 3
  • 17
  • 25
42
votes
5 answers

Failed to start redis.service: Unit redis-server.service is masked

I Installed Redis Server on ubuntu 16.04. but when I try to start the redis service using $ sudo systemctl start redis I receive message: Failed to start redis.service: Unit redis-server.service is masked. I don't have any idea about this error.
Raza Rafaideen
  • 2,119
  • 1
  • 19
  • 30
42
votes
6 answers

How to set/get pandas.DataFrame to/from Redis?

After setting a DataFrame to redis, then getting it back, redis returns a string and I can't figure out a way to convert this str to a DataFrame. How can I do these two appropriately?
Alex Luya
  • 9,412
  • 15
  • 59
  • 91
42
votes
3 answers

How to search in redis for hash keys?

I'm using hash keys to store user details like: hmset user:1 user_name lee age 21 hmset user:2 user_name david age 25 hmset user:3 user_name chris age 25 I need to search for users having age = 25, name = lee. How to do a search for a…
Heera
  • 495
  • 1
  • 4
  • 6
42
votes
1 answer

Transactions and watch statement in Redis

Could you please explain me following example from "The Little Redis Book": With the code above, we wouldn't be able to implement our own incr command since they are all executed together once exec is called. From code, we can't…
Marboni
  • 2,399
  • 3
  • 25
  • 42
41
votes
8 answers

docker-compose redis password via environment variable

I'm trying to pass my redis password using docker-compose via environment variable but it gives me errors. Here is part of mine docker-compose.yml with redis image: redis: image: redis container_name: redis # command: redis-server…
karambaq
  • 631
  • 3
  • 9
  • 24
41
votes
4 answers

How to create a redis cloud connection url with an auth password

I'm switching over from a heroku addon to a direct redis cloud account and am a bit puzzled on how to generate the redis url with the auth info. The old heroku add-on url was in the format of redis://rediscloud:mypassword@redis... However in the…
MonkeyBonkey
  • 46,433
  • 78
  • 254
  • 460
41
votes
5 answers

redis vs hazelcast

Redis Vs Hazelcast If my app: Have a lot of http requests (6,000 per minute, I collect clicks info) that needs to be saved Have a lot of http requests that query the data previously saved. My Questions are - Which one between Redis and Hazelcast…
Federico
  • 5,438
  • 5
  • 39
  • 47
41
votes
9 answers

MongoDB vs. Redis vs. Cassandra for a fast-write, temporary row storage solution

I'm building a system that tracks and verifies ad impressions and clicks. This means that there are a lot of insert commands (about 90/second average, peaking at 250) and some read operations, but the focus is on performance and making it…
Mark Bao
  • 896
  • 1
  • 10
  • 19
41
votes
9 answers

Where does Redis store the data

I am using redis for pub/sub as well as for server side cache. I mean my app server has redis server running as one process (functioning as a cache as well) . I have several thin clients (running redis client) connected to this app server in…
user3364247
  • 1,477
  • 3
  • 14
  • 24
41
votes
2 answers

StackExchange.Redis - LockTake / LockRelease Usage

I am using Redis with StackExchange.Redis. I have multiple threads that will at some point access and edit the value of the same key, so I need to synchronize the manipulation of the data. Looking at the available functions, I see that there are…
lolcodez
  • 659
  • 4
  • 9
  • 16