Skip to content

Instantly share code, notes, and snippets.

@nedzadarek
Created July 24, 2014 12:36
Show Gist options
  • Save nedzadarek/ce7dce40c9ed329c27f4 to your computer and use it in GitHub Desktop.
Save nedzadarek/ce7dce40c9ed329c27f4 to your computer and use it in GitHub Desktop.
Sending to the Redis
class RStruct
def initialize
# `@name` => just to show that code works
# you don't have to put it into `initialize`
@name = 'example'
@my_object_id = self.object_id
end
attr_reader :name, :my_object_id
def save_to_Redis
# some code
end
end
example = RStruct.new
example.save_to_Redis
example_object_id = example.my_object_id
#####################
# some code later
#####################
def get_obj_from_Redis object_id
# Put some code that reads from the Redis to the Ruby
# here we fake it by taking `object_id` from the `example_object_id` variable
# and we just return object using `ObjectSpace._id2ref`
return ObjectSpace._id2ref object_id
end
puts get_obj_from_Redis(example_object_id).name
class RStruct
def initialize name
@name = name
end
attr_reader :name
def save_to_Redis
# code
end
end
example = RStruct.new 'example'
example.save_to_Redis
#################
# some code later
#################
def get_obj_from_Redis name
# Put some code that reads from the Redis to the Ruby
# Here we fake it by creating a new object
obj1 = RStruct.new name
return obj1
end
puts get_obj_from_Redis('example').name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment