News for hackers. Stuff that matters.
Re:Redis Re-Implemented with SQLite by akie on Sunday April 14, 2024 @02:43PM (#40033324)
I would love to have a Redis alternative where I don't have to think about whether or not the dataset fits into memory.
Re:Redis Re-Implemented with SQLite by GraemeMeyer on Sunday April 14, 2024 @02:55PM (#40033417)
I think Garnet might be what you're looking for: https://www.microsoft.com/en-us/research/project/garnet/
Re:Redis Re-Implemented with SQLite by sebazzz on Monday April 15, 2024 @04:02AM (#40037969)
Doesn't support lua at the moment. Some connectors to Redis like .NET IDistributedCache use lua.
Re:Redis Re-Implemented with SQLite by Rapzid on Tuesday April 16, 2024 @02:00PM (#40055161)
It turns out they didn't actually need LUA for IDistributedCache so it's being removed.
Re:Redis Re-Implemented with SQLite by alerighi on Sunday April 14, 2024 @04:13PM (#40034058)
At that point why using Redis entirely? You can use any DBMS you want, either relational or NoSQL. The advantage of Redis is that it is a memory cache, if you take out the memory from it, just use Postgres or whatever DBMS you are using (I say Postgres because it has all the features of Redis).
Re:Redis Re-Implemented with SQLite by dalyons on Sunday April 14, 2024 @05:06PM (#40034487)
Postgres has nowhere near all the features of redis. Go and have a look at the redis command’s documentation. They’re not even really similar at all, once you get past basic GET/SET stuff.
Re:Redis Re-Implemented with SQLite by pshc on Sunday April 14, 2024 @05:13PM (#40034532)
I feel like one could implement most Redis commands as functions or PL/SQL using native Postgres hstore and json. Could be an interesting translation layer.
Re:Redis Re-Implemented with SQLite by out_of_protocol on Monday April 15, 2024 @06:19AM (#40038614)
Well, you can't do O(1) part for most commands :) redis can do a lot of stuff at near constant (and superfast) speed. Databases do become slower when your dataset is big
Re:Redis Re-Implemented with SQLite by beepbooptheory on Monday April 15, 2024 @07:12AM (#40038991)
But if its that big, how are you fitting it in your RAM with Redis anyway?
Re:Redis Re-Implemented with SQLite by out_of_protocol on Monday April 15, 2024 @08:47AM (#40039883)
You can buy servers with 1TB RAM for reasonable price. Also, you don't need to go this big, even moderate-sized tables are slow. Indexes are usually log(n) at best (and eating more RAM anyway, you can get said log(n) if all index data is in memory, and at this point regular sql db eating more ram than redis), and insert time is slowing down since you need to update index as well (and maybe reorg stuff around)
Re:Redis Re-Implemented with SQLite by from-nibly on Sunday April 14, 2024 @05:12PM (#40034528)
Can you name an explicit thing that postgres does not do that redis does?
Re:Redis Re-Implemented with SQLite by jitl on Sunday April 14, 2024 @05:32PM (#40034673)
This is silly, Postgres doesn’t speak the Redis wire protocol. You will need a large army of connection proxies to get a Postgres database to handle the number of connections a single Redis shrugs off with no sweat.

Maybe you like this answer more: At the end of the day you can embed a bunch of Turing-complete programming languages in Postgres, and Postgres can store binary blobs, so Postgres can do literally anything. Can it do it performantly, and for low cost? Probably not. But if you put in enough time and money I’m sure you can re-implement Redis on Postgres using BLOB column alone.

Here’s a simpler answer: cuckoo filter is available out of the box in Redis, 2 seconds of Googling I didn’t find one for Postgres: https://redis.io/docs/latest/develop/data-types/probabilisti...

Re:Redis Re-Implemented with SQLite by codetrotter on Sunday April 14, 2024 @05:56PM (#40034827)
Not sure if this one could be used in order to do what you want but maybe?

https://www.postgresql.org/docs/current/bloom.html

Have a look

Re:Redis Re-Implemented with SQLite by pgaddict on Monday April 15, 2024 @05:42AM (#40038431)
No, that's a completely different thing - an index access method, building a bloom filter on multiple columns of a single row. Which means a query then can have an equality condition on any of the columns.

That being said, building a bloom/cuckoo filter as a data type would be quite trivial - a basic version might take an hour or two, the more advanced stuff (to support partial aggregates etc) might take a bit more. Ultimately, this is not that different from what postgresql-hll does.

Re:Redis Re-Implemented with SQLite by jetbalsa on Sunday April 14, 2024 @02:49PM (#40033368)
I've used SSDB[0] in the past for some really stupid large datasets (20TB)_and it worked really well in production

[0] https://github.com/ideawu/ssdb

Re:Redis Re-Implemented with SQLite by welder on Sunday April 14, 2024 @03:21PM (#40033624)
I switched from SSDB to Kvrocks recently, because SSDB is abandoned and the author missing for 3 years now. I used to recommend SSDB, but now there's better alternatives available:

https://github.com/apache/kvrocks

https://github.com/sabledb-io/sabledb

Re:Redis Re-Implemented with SQLite by akie on Sunday April 14, 2024 @03:35PM (#40033730)
These are great recommendations, thanks!
Re:Redis Re-Implemented with SQLite by PlutoIsAPlanet on Sunday April 14, 2024 @02:54PM (#40033410)
Its also worth checking out kvrocks, which is a redis interface on top of rockdb that's part of the Apache project, and very well maintained.
Re:Redis Re-Implemented with SQLite by mathfailure on Sunday April 14, 2024 @07:34PM (#40035493)
And which is not in-memory at all.
Re:Redis Re-Implemented with SQLite by PlutoIsAPlanet on Sunday April 14, 2024 @08:35PM (#40035841)
It can cache in-memory using RocksDBs caching mechanisms.
Re:Redis Re-Implemented with SQLite by Nican on Sunday April 14, 2024 @03:05PM (#40033505)
As usual, there is a spectrum of data safety vs. performance. Redis is at the "very fast, but unsafe" side of the scale.

ScyllaDB for me is in the middle of being high performance key-value store, but not really supporting transactions. FoundationDB is another one that I would consider.

Re:Redis Re-Implemented with SQLite by tyre on Sunday April 14, 2024 @06:25PM (#40035023)
Depends on the kind of safety you’re looking for. Redis is entirely safe from concurrency issues because it’s single-threaded. It supports an append-only file for persistence to disk.
Re:Redis Re-Implemented with SQLite by yuppiepuppie on Sunday April 14, 2024 @02:52PM (#40033391)
Curious, What’s the use case?
Re:Redis Re-Implemented with SQLite by jitl on Sunday April 14, 2024 @03:01PM (#40033473)
Redis drops data semi randomly when under memory pressure.

If you use Redis for queue tasks (this is popular in Rails and Django/Python web services), that means that during an incident where your queue jobs are getting added faster than they’re removed, you’re going to lose jobs if the incident goes on long enough.

Re:Redis Re-Implemented with SQLite by byroot on Sunday April 14, 2024 @03:08PM (#40033526)
That depends on how the `maxmemory-policy` is configured, and queue systems based on Redis will tell you not to allow eviction. https://github.com/sidekiq/sidekiq/wiki/Using-Redis#memory (it even logs a warnings if it detects your Redis is misconfigured IIRC).
Re:Redis Re-Implemented with SQLite by kiitos on Sunday April 14, 2024 @03:39PM (#40033762)
Well, of course! Redis is not (and has never been) a database, it's a data structure server, at best described as a cache. If jobs are added faster than they're removed, this is straight queueing theory 101 -- ideally you'd reject jobs at add-time, but otherwise you have to drop them.
Re:Redis Re-Implemented with SQLite by gnarbarian on Sunday April 14, 2024 @04:16PM (#40034080)
Right. I think Redis hitting the disk would be a terrible tradeoff compared to making a new backend call. it probably wouldn't save you much time and I imagine it would lead to very strange and unpredictable behavior on the front end or trying to debug latency or data issues downstream
Re:Redis Re-Implemented with SQLite by prisenco on Sunday April 14, 2024 @04:04PM (#40033986)
Since Redis is an in-memory cache, and already doesn't guarantee the data, would it make sense to set PRAGMA SYNCHRONOUS on nalgeon to OFF to boost performance to something closer to standard Redis?
Re:Redis Re-Implemented with SQLite by qwertox on Sunday April 14, 2024 @02:55PM (#40033419)
My same thought, because some don't require much memory.
Re:Redis Re-Implemented with SQLite by akie on Sunday April 14, 2024 @03:06PM (#40033509)
The use case is caching 20 million API responses that almost never change, each about 20kb of JSON, for a high traffic site.

Yes, I can pay for a 400Gb RAM instance of Redis, but it's expensive.

I can also cache it on disk, but then I need to think about cache expiration myself.

Or I can use something appropriate like a document database, but then I need additional code & additional configuration because we otherwise don't need that piece of infrastructure in our stack.

It would be a lot easier if I could just store it in Redis with the other (more reasonably sized) things that I need to cache.

Re:Redis Re-Implemented with SQLite by yuliyp on Sunday April 14, 2024 @04:23PM (#40034135)
You're trying to get redis to be what it isn't. Use a thing that has the properties you want: a document or relational database. If you insist on this then running a system that allows a ton of swap onto a reasonably fast disk might work, but is still gonna perform worse than a system that's designed for concurrently serving queries of wildly differing latencies.
Re:Redis Re-Implemented with SQLite by minitech on Sunday April 14, 2024 @08:03PM (#40035668)
Yes, that was the context: a Redis alternative to support the same operations but be what Redis isn’t.
Re:Redis Re-Implemented with SQLite by danpat on Sunday April 14, 2024 @04:11PM (#40034043)
Or shard it - divide your objects up based on some criteria (hash the name of the object, use the first N digits of the hash to assign to a shard), and distribute them across multiple redis instances. Yes, you then need to maintain some client code to pick the right redis instance to fetch from, but you can now pick the most $/memory efficient instance types to run redis, and you don't have to worry about introducing disk read latency and the edge cases that brings with it.

Edit: looks like redis has some built-in support for data sharding when used as a cluster (https://redis.io/docs/latest/commands/cluster-shards/) - I haven't used that, so not sure how easy it is to apply, and exactly what you'd have to change.

Re:Redis Re-Implemented with SQLite by yuliyp on Sunday April 14, 2024 @04:19PM (#40034100)
Sharding doesn't help here at all. They'd still need the same amount of RAM to house all the data in redis.
Re:Redis Re-Implemented with SQLite by reese_john on Sunday April 14, 2024 @04:15PM (#40034072)
You could try using Amazon S3 Express, a low-latency alternative for S3 buckets [0]. I imagine cache invalidation would be relatively simple to implement using lifecycle policies.

https://docs.aws.amazon.com/AmazonS3/latest/userguide/s3-exp...

Re:Redis Re-Implemented with SQLite by 0cf8612b2e1e on Sunday April 14, 2024 @04:10PM (#40034031)
Would DiskCache work for you? Runs via SQLite memory or persisted file database. Thread safe, has various expiration controls, etc.

https://grantjenks.com/docs/diskcache/tutorial.html

Re:Redis Re-Implemented with SQLite by Nican on Sunday April 14, 2024 @03:16PM (#40033589)
This looks like a good use case for ScyllaDB with Compression and TTL. It is pretty simple to setup a single-node instance.

If you rather have something in-process and writes to disk, to avoid extra infrastructure, I would also recommend RocksDB with Compression and TTL.

Re:Redis Re-Implemented with SQLite by seddonm1 on Sunday April 14, 2024 @04:36PM (#40034253)
In other abuses of SQLite, I wrote a tool [0] that exposes blobs in SQLite via an Amazon S3 API. It doesn't do expiry (but that would be easy enough to add if S3 does it).

We were using it to manage a millions of images for machine learning as many tools support S3 and the ability to add custom metadata to objects is useful (harder with files). It is one SQLite database per bucket but at the bucket level it is transactional.

0: https://github.com/seddonm1/s3ite

Re:Redis Re-Implemented with SQLite by phamilton on Sunday April 14, 2024 @04:40PM (#40034284)
A few things:

Redis Data Tiering - Redis Enterprise and AWS Elasticache for Redis support data tiering (using SSD for 80% of the dataset and moving things in and out). On AWS, a cache.r6gd.4xlarge with 100GB of memory can handle 500GB of data.

Local Files

> I can also cache it on disk, but then I need to think about cache expiration myself.

Is the challenge that you need it shared among many machines? On a single machine you can put 20 million files in a directory hierarchy and let the fs cache keep things hot in memory as needed. Or use SQLite which will only load the pages needed for each query and also rely on the fs cache.

S3 - An interesting solution is one of the SQLite S3 VFS's. Those will query S3 fairly efficiently for specific data in a large dataset.

Re:Redis Re-Implemented with SQLite by kiitos on Sunday April 14, 2024 @05:03PM (#40034461)
Redis is an in-memory cache by definition. If you don't want to cache in-memory, then don't use Redis.
Re:Redis Re-Implemented with SQLite by tayo42 on Sunday April 14, 2024 @09:41PM (#40036262)
Have you looked at varnish for caching api responses? Varnish let's you back it with disk and relies on page cache to keep more accessed items in memory.

If the reverse proxy thing doesn't work I think memcached has two level storage like that now iirc

Re:Redis Re-Implemented with SQLite by mannyv on Monday April 15, 2024 @01:26AM (#40037321)
If you're caching 20m api requests that almost never change use s3. I mean heck, it's cheaper, can be cdn'd, and can be pipelined by the browser.
Re:Redis Re-Implemented with SQLite by emmanueloga_ on Monday April 15, 2024 @06:50AM (#40038821)
Check memcached "extstore" [1].

--

1: https://github.com/memcached/memcached/wiki/Extstore

Re:Redis Re-Implemented with SQLite by noncoml on Sunday April 14, 2024 @03:13PM (#40033564)
Using a hammer like a screwdriver