Skip to content

Commit

Permalink
Merge pull request #37 from delano/feature/34-update-dep-uri-redis
Browse files Browse the repository at this point in the history
Modernize gemspec and dependencies
  • Loading branch information
delano authored Jun 17, 2024
2 parents 89131aa + d77fbb6 commit d4d8275
Show file tree
Hide file tree
Showing 25 changed files with 461 additions and 230 deletions.
71 changes: 71 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Ruby

on:
push:
branches:
- main

pull_request:

workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
name: Ruby ${{ matrix.ruby }}
strategy:
matrix:
include:
- ruby: '3.3'
bundler: latest
rubygems: latest

- ruby: '3.2'
bundler: latest
rubygems: latest

- ruby: '3.1'
bundler: latest
rubygems: latest

- ruby: '3.0'
bundler: latest
rubygems: latest

- ruby: '2.7'
bundler: '2.4.22'
rubygems: '3.2.3'

services:
redis:
image: redis:bookworm@sha256:e422889e156ebea83856b6ff973bfe0c86bce867d80def228044eeecf925592b
# Set health checks to wait until redis has started
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 3s
--health-retries 5
ports:
# https://docs.github.com/en/actions/using-containerized-services/creating-redis-service-containers#running-jobs-in-containers
# Maps port 6379 on service container to the host
- 6379:6379

steps:
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
rubygems: ${{ matrix.rubygems }}
bundler: ${{ matrix.bundler }}
# When the following is true, also run "bundle install",
# and cache the result automatically. Ran into an issue
# with the caching and multiple ruby versions. Needs
# further investigation.
bundler-cache: false

- name: Re-run bundle install
run: bundle install

- name: Run the tryouts
run: bundle exec try -v try/*_try.rb
18 changes: 17 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,18 @@
.DS_Store
pkg
.bundle
.byebug*
.history
.devcontainer
.vscode
*.env
*.log
*.md
*.txt
!LICENSE.txt
.ruby-version
appendonlydir
etc/config
log
tmp
vendor
*.gem
69 changes: 69 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
##
# Pre-Commit Configuration
#
# Initial setup:
#
# 0. Install the pre-commit framework (if it isn't already on your system):

# $ pip install pre-commit
#
# 1. Install the git hook:
#
# $ pre-commit install
#
#
# Other commands:
#
# Run it on all the files in this repo:
# $ pre-commit run --all-files
#
# Updating plugin repositories:
# $ pre-commit autoupdate
#
# Automatically enable pre-commit on repositories
# $ git config --global init.templateDir ~/.git-template
# $ pre-commit init-templatedir ~/.git-template
#
# See also:
# - https://pre-commit.com for more information
# - https://pre-commit.com/hooks.html for more hooks
#

default_install_hook_types:
- pre-commit
- prepare-commit-msg

fail_fast: true

repos:
- repo: meta
hooks:
- id: check-hooks-apply
- id: check-useless-excludes
- id: identity

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: detect-private-key
- id: mixed-line-ending
- id: check-added-large-files
args: ["--maxkb=1000"]
- id: no-commit-to-branch
args: ["--branch", "develop", "--branch", "rel/.*"]
- id: check-merge-conflict
- id: forbid-submodules

- repo: https://github.com/avilaton/add-msg-issue-prefix-hook
rev: v0.0.11
hooks:
- id: add-msg-issue-prefix
stages: [prepare-commit-msg]
name: Link commit to Github issue
args:
- "--default=[NOJIRA]"
- "--pattern=[a-zA-Z0-9]{0,10}-?[0-9]{1,5}"
- "--template=[#{}]"
13 changes: 13 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
AllCops:
TargetRubyVersion: 2.7.5

Style/StringLiterals:
Enabled: true
EnforcedStyle: double_quotes

Style/StringLiteralsInInterpolation:
Enabled: true
EnforcedStyle: double_quotes

Layout/LineLength:
Max: 120
9 changes: 9 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
REDIS-DUMP, CHANGES

#### 0.6.0 (2024-06-17) ###############################


#### 0.5.0 (2023-01-17) ###############################

* ADDED: Timeout support for redis connections
* CHANGED: uri-redis dependency to 1.0.0


#### 0.4.0 (2017-11-23) ###############################

* ADDED: support for redis >= 4.0
Expand Down
14 changes: 14 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

source "https://rubygems.org"

gem "redis", ">= 4.0", "< 5.0"
gem "uri-redis", ">= 1.3.0"
gem "yajl-ruby", ">= 1.4.3"
gem "oj", ">= 3.16.4"
gem "drydock", ">= 0.6.9"

gem "rake", "~> 13.0", require: false, group: :development
gem "rubocop", "~> 1.64.1", require: false, group: :development
gem "tryouts", "~> 2.2.0", require: false, group: :development
gem "pry-byebug", "~> 3.10.1", require: false, group: :development
72 changes: 72 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
GEM
remote: https://rubygems.org/
specs:
ast (2.4.2)
bigdecimal (3.1.8)
byebug (11.1.3)
coderay (1.1.3)
drydock (0.6.9)
json (2.7.2)
language_server-protocol (3.17.0.3)
method_source (1.1.0)
oj (3.16.4)
bigdecimal (>= 3.0)
parallel (1.25.1)
parser (3.3.3.0)
ast (~> 2.4.1)
racc
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
pry-byebug (3.10.1)
byebug (~> 11.0)
pry (>= 0.13, < 0.15)
racc (1.8.0)
rainbow (3.1.1)
rake (13.2.1)
redis (4.8.1)
regexp_parser (2.9.2)
rexml (3.3.0)
strscan
rubocop (1.64.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.31.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.31.3)
parser (>= 3.3.1.0)
ruby-progressbar (1.13.0)
storable (0.10.0)
strscan (3.1.0)
sysinfo (0.10.0)
drydock (< 1.0)
storable (~> 0.10)
tryouts (2.2.0)
sysinfo (~> 0.10)
unicode-display_width (2.5.0)
uri-redis (1.3.0)
yajl-ruby (1.4.3)

PLATFORMS
arm64-darwin-22
ruby

DEPENDENCIES
drydock (>= 0.6.9)
oj (>= 3.16.4)
pry-byebug (~> 3.10.1)
rake (~> 13.0)
redis (>= 4.0, < 5.0)
rubocop (~> 1.64.1)
tryouts (~> 2.2.0)
uri-redis (>= 1.3.0)
yajl-ruby (>= 1.4.3)

BUNDLED WITH
2.5.9
12 changes: 7 additions & 5 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Copyright (c) 2010-2017 Solutious Inc, Delano Mandelbaum
MIT License

Copyright (c) 2010-2024 Delano Mandelbaum

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -7,13 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
81 changes: 81 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Redis::Dump - v0.5 PRE

*Backup and restore your Redis data to and from JSON.*

## Installation

One of:
1. Gemfile: `gem 'redis-dump', '~> 0.4.0'`
2. Install manually: `gem install redis-dump`
3. Clone with git: `git clone [email protected]:delano/redis-dump.git`



## Usage

There are two executables: `redis-dump` and `redis-load`.

```bash
$ redis-dump
$ redis-dump -u 127.0.0.1:6379 > db_full.json
$ redis-dump -u 127.0.0.1:6379 -d 15 > db_db15.json

$ < db_full.json redis-load
$ < db_db15.json redis-load -d 15
# OR
$ cat db_full | redis-load
$ cat db_db15.json | redis-load -d 15

# You can specify the redis URI via an environment variable
$ export REDIS_URI=127.0.0.1:6379
$ redis-dump

# If your instance uses a password (such as on RedisToGo), you
# can specify the Redis URL as such:
# :<password>@<domain>:<port>
# Note the leading colon is important for specifying no username.
$ redis-dump -u :[email protected]:9055
```

### Output format

All redis datatypes are output to a simple JSON object. All objects have the following 5 fields:

* db (Integer)
* key (String)
* ttl (Integer): The amount of time in seconds that the key will live. If no expire is set, it's -1.
* type (String), one of: string, list, set, zset, hash, none.
* value (String): A JSON-encoded string. For keys of type list, set, zset, and hash, the data is given a specific structure (see below).

Here are examples of each datatype:

```json
{"db":0,"key":"hashkey","ttl":-1,"type":"hash","value":{"field_a":"value_a","field_b":"value_b","field_c":"value_c"},"size":42}
{"db":0,"key":"listkey","ttl":-1,"type":"list","value":["value_0","value_1","value_2","value_0","value_1","value_2"],"size":42}
{"db":0,"key":"setkey","ttl":-1,"type":"set","value":["value_2","value_0","value_1","value_3"],"size":28}
{"db":0,"key":"zsetkey","ttl":-1,"type":"zset","value":[["value_0","100"],["value_1","100"],["value_2","200"],["value_3","300"],["value_4","400"]],"size":50}
{"db":0,"key":"stringkey","ttl":79,"type":"string","value":"stringvalue","size":11}
```

## Important notes

### About TTLs

One of the purposes of redis-dump is the ability to restore the database to a known state. When you restore a redis database from a redis-dump file, *the expires are reset to their values at the time the dump was created*. This is different from restoring from Redis' native .rdb or .aof files (expires are stored relative to the actual time they were set).

### Output directly to an encrypted file

For most sensitive data, you should consider encrypting the data directly without writing first to a temp file. You can do this using the power of [gpg](http://www.gnupg.org/) and file descriptors. Here are a couple examples:

```bash
# Encrypt the data (interactive)
$ redis-dump -u 127.0.0.1:6379 -d 15 | gpg --force-mdc -v -c > path/2/backup-db1
```

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/delano/redis-dump.

## License

The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
Loading

0 comments on commit d4d8275

Please sign in to comment.